devfile 0.0.8.pre.alpha1-arm64-darwin-21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4598efd73f0885c6a5875a1d7377354f97bfe4c1266e5a2c75f25aa1216e5b1b
4
+ data.tar.gz: 2410e324d0529cfa0e9ba184400b3e3251cd3743003d22814aa9d3da9d9ce006
5
+ SHA512:
6
+ metadata.gz: 9857c696dc68b62611c2997d669366784e13f4c542e4fbda9307df94c0aefa35f648dfd5b6ab1eb045680d13f7b7f675e868038aa7c5c9181f35832878b58de5
7
+ data.tar.gz: ad907960396e68cbcda9ac8652f24f5f6253dfd9e1b6f0bd8872540b0210129321b6170ea0fe5cfe9d3bce93a2392b3177d18f2fa75e16ff5a9b999332d64cc6
data/bin/devfile ADDED
Binary file
data/ext/devfile.go ADDED
@@ -0,0 +1,227 @@
1
+ package main
2
+
3
+ import "C"
4
+ import (
5
+ "bytes"
6
+ "strconv"
7
+ "text/template"
8
+
9
+ "github.com/devfile/library/v2/pkg/devfile/generator"
10
+ "github.com/devfile/library/v2/pkg/devfile/parser"
11
+ "github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
12
+ appsv1 "k8s.io/api/apps/v1"
13
+ corev1 "k8s.io/api/core/v1"
14
+ networkingv1 "k8s.io/api/networking/v1"
15
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
+ "k8s.io/apimachinery/pkg/runtime"
17
+ "k8s.io/cli-runtime/pkg/printers"
18
+ "sigs.k8s.io/yaml"
19
+ )
20
+
21
+ type Devfile struct {
22
+ devfileObj parser.DevfileObj
23
+ }
24
+
25
+ func (d Devfile) getDeployment(name, namespace string, labels, annotations map[string]string, replicas int) (*appsv1.Deployment, error) {
26
+ containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
27
+ if err != nil {
28
+ return nil, err
29
+ }
30
+ initContainers, err := generator.GetInitContainers(d.devfileObj)
31
+ if err != nil {
32
+ return nil, err
33
+ }
34
+ volumes, err := d.getVolumesAndVolumeMounts(containers, initContainers, name)
35
+ if err != nil {
36
+ return nil, err
37
+ }
38
+
39
+ deployParams := generator.DeploymentParams{
40
+ TypeMeta: generator.GetTypeMeta("Deployment", "apps/v1"),
41
+ ObjectMeta: generator.GetObjectMeta(name, namespace, labels, annotations),
42
+ InitContainers: initContainers,
43
+ Containers: containers,
44
+ Volumes: volumes,
45
+ PodSelectorLabels: labels,
46
+ Replicas: pointerTo(int32(replicas)),
47
+ }
48
+
49
+ deployment, err := generator.GetDeployment(d.devfileObj, deployParams)
50
+ if err != nil {
51
+ return nil, err
52
+ }
53
+
54
+ return deployment, err
55
+ }
56
+
57
+ func (d Devfile) getService(name, namespace string, labels, annotations map[string]string) (*corev1.Service, error) {
58
+ service, err := generator.GetService(d.devfileObj, generator.ServiceParams{
59
+ TypeMeta: generator.GetTypeMeta("Service", "v1"),
60
+ ObjectMeta: generator.GetObjectMeta(name, namespace, labels, annotations),
61
+ SelectorLabels: labels,
62
+ }, common.DevfileOptions{})
63
+ if err != nil {
64
+ return nil, err
65
+ }
66
+
67
+ return service, err
68
+ }
69
+
70
+ func (d Devfile) getIngress(name, namespace string, labels, annotations map[string]string, domainTemplate, ingressClass string) (*networkingv1.Ingress, error) {
71
+
72
+ if ingressClass == "none" {
73
+ return nil, nil
74
+ }
75
+
76
+ components, err := d.devfileObj.Data.GetDevfileContainerComponents(common.DevfileOptions{})
77
+ if err != nil {
78
+ return nil, err
79
+ }
80
+
81
+ var hosts []string
82
+ var rules []networkingv1.IngressRule
83
+
84
+ // Create a new template and parse the letter into it.
85
+ t, err := template.New("domainTemplate").Parse(domainTemplate)
86
+ if err != nil {
87
+ return nil, err
88
+ }
89
+
90
+ for _, component := range components {
91
+ for _, endpoint := range component.Container.Endpoints {
92
+ var domain bytes.Buffer
93
+ err := t.Execute(&domain, map[string]string{"port": strconv.Itoa(endpoint.TargetPort)})
94
+ if err != nil {
95
+ return nil, err
96
+ }
97
+ hosts = append(hosts, domain.String())
98
+ rules = append(rules, networkingv1.IngressRule{
99
+ Host: domain.String(),
100
+ IngressRuleValue: networkingv1.IngressRuleValue{
101
+ HTTP: &networkingv1.HTTPIngressRuleValue{
102
+ Paths: []networkingv1.HTTPIngressPath{
103
+ {
104
+ Path: "/",
105
+ PathType: pointerTo(networkingv1.PathTypePrefix),
106
+ Backend: networkingv1.IngressBackend{
107
+ Service: &networkingv1.IngressServiceBackend{
108
+ Name: name,
109
+ Port: networkingv1.ServiceBackendPort{
110
+ Number: int32(endpoint.TargetPort),
111
+ },
112
+ },
113
+ },
114
+ },
115
+ },
116
+ },
117
+ },
118
+ })
119
+ }
120
+ }
121
+
122
+ if len(rules) == 0 {
123
+ return nil, nil
124
+ }
125
+
126
+ ingress := &networkingv1.Ingress{
127
+ TypeMeta: generator.GetTypeMeta("Ingress", "networking.k8s.io/v1"),
128
+ ObjectMeta: metav1.ObjectMeta{
129
+ Name: name,
130
+ Namespace: namespace,
131
+ Labels: labels,
132
+ Annotations: annotations,
133
+ },
134
+ Spec: networkingv1.IngressSpec{
135
+ IngressClassName: &ingressClass,
136
+ //TLS: []networkingv1.IngressTLS{
137
+ // {
138
+ // Hosts: hosts,
139
+ // SecretName: "tls",
140
+ // },
141
+ //},
142
+ Rules: rules,
143
+ },
144
+ }
145
+
146
+ return ingress, nil
147
+ }
148
+
149
+ func (d Devfile) getAll(name, namespace string, labels, annotations map[string]string, replicas int, domainTemplate, ingressClass string) ([]runtime.Object, error) {
150
+
151
+ var result []runtime.Object
152
+
153
+ deployment, err := d.getDeployment(name, namespace, labels, annotations, replicas)
154
+ if err != nil {
155
+ return nil, err
156
+ }
157
+ result = append(result, deployment)
158
+
159
+ service, err := d.getService(name, namespace, labels, annotations)
160
+ if err != nil {
161
+ return nil, err
162
+ }
163
+ result = append(result, service)
164
+
165
+ ingress, err := d.getIngress(name, namespace, labels, annotations, domainTemplate, ingressClass)
166
+ if err != nil {
167
+ return nil, err
168
+ }
169
+ if ingress != nil {
170
+ result = append(result, ingress)
171
+ }
172
+
173
+ return result, nil
174
+ }
175
+
176
+ func (d Devfile) hasContainerComponents() (bool, error) {
177
+ containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
178
+ if err != nil {
179
+ return false, err
180
+ }
181
+ if len(containers) > 0 {
182
+ return true, nil
183
+ }
184
+ return false, nil
185
+ }
186
+
187
+ func (d Devfile) getFlattenedDevfileContent() string {
188
+ return string(d.devfileObj.Ctx.GetDevfileContent())
189
+ }
190
+
191
+ func parseDevfile(content string) (Devfile, error) {
192
+ parserArgs := parser.ParserArgs{
193
+ Data: []byte(content),
194
+ }
195
+ devfileObj, err := parser.ParseDevfile(parserArgs)
196
+ return Devfile{
197
+ devfileObj: devfileObj,
198
+ }, err
199
+ }
200
+
201
+ func marshalResources(objs []runtime.Object) (string, error) {
202
+ printer := printers.YAMLPrinter{}
203
+ dest := bytes.NewBuffer([]byte{})
204
+ for _, obj := range objs {
205
+ if obj == nil {
206
+ continue
207
+ }
208
+ err := printer.PrintObj(obj, dest)
209
+ if err != nil {
210
+ return "", err
211
+ }
212
+ }
213
+ return dest.String(), nil
214
+ }
215
+
216
+ func marshalDevfile(devfile string) (string, error) {
217
+ data, err := yaml.JSONToYAML([]byte(devfile))
218
+ if err != nil {
219
+ return "", err
220
+ }
221
+ return string(data), nil
222
+ }
223
+
224
+ // since it is not possible to get pointer of a constant directly
225
+ func pointerTo[T any](v T) *T {
226
+ return &v
227
+ }
data/ext/go.mod ADDED
@@ -0,0 +1,119 @@
1
+ module gitlab.com/gitlab-org/incubation-engineering/server-runtime/devfilerubyffi
2
+
3
+ go 1.18
4
+
5
+ require (
6
+ github.com/devfile/library/v2 v2.2.0
7
+ k8s.io/api v0.26.1
8
+ k8s.io/apimachinery v0.26.1
9
+ k8s.io/cli-runtime v0.26.1
10
+ )
11
+
12
+ require (
13
+ github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
14
+ github.com/Microsoft/go-winio v0.5.1 // indirect
15
+ github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
16
+ github.com/acomagu/bufpipe v1.0.3 // indirect
17
+ github.com/beorn7/perks v1.0.1 // indirect
18
+ github.com/cespare/xxhash/v2 v2.1.2 // indirect
19
+ github.com/containerd/containerd v1.5.9 // indirect
20
+ github.com/davecgh/go-spew v1.1.1 // indirect
21
+ github.com/devfile/api/v2 v2.2.0 // indirect
22
+ github.com/devfile/registry-support/index/generator v0.0.0-20221018203505-df96d34d4273 // indirect
23
+ github.com/devfile/registry-support/registry-library v0.0.0-20221018213054-47b3ffaeadba // indirect
24
+ github.com/docker/cli v20.10.11+incompatible // indirect
25
+ github.com/docker/distribution v2.7.1+incompatible // indirect
26
+ github.com/docker/docker v20.10.11+incompatible // indirect
27
+ github.com/docker/docker-credential-helpers v0.6.4 // indirect
28
+ github.com/docker/go-connections v0.4.0 // indirect
29
+ github.com/docker/go-metrics v0.0.1 // indirect
30
+ github.com/docker/go-units v0.4.0 // indirect
31
+ github.com/emicklei/go-restful/v3 v3.9.0 // indirect
32
+ github.com/emirpasic/gods v1.12.0 // indirect
33
+ github.com/evanphx/json-patch/v5 v5.6.0 // indirect
34
+ github.com/fatih/color v1.7.0 // indirect
35
+ github.com/fsnotify/fsnotify v1.5.4 // indirect
36
+ github.com/go-git/gcfg v1.5.0 // indirect
37
+ github.com/go-git/go-billy/v5 v5.3.1 // indirect
38
+ github.com/go-git/go-git/v5 v5.4.2 // indirect
39
+ github.com/go-logr/logr v1.2.3 // indirect
40
+ github.com/go-openapi/jsonpointer v0.19.5 // indirect
41
+ github.com/go-openapi/jsonreference v0.20.0 // indirect
42
+ github.com/go-openapi/swag v0.19.14 // indirect
43
+ github.com/gobwas/glob v0.2.3 // indirect
44
+ github.com/gogo/protobuf v1.3.2 // indirect
45
+ github.com/golang/mock v1.6.0 // indirect
46
+ github.com/golang/protobuf v1.5.2 // indirect
47
+ github.com/google/btree v1.0.1 // indirect
48
+ github.com/google/gnostic v0.5.7-v3refs // indirect
49
+ github.com/google/go-cmp v0.5.9 // indirect
50
+ github.com/google/gofuzz v1.2.0 // indirect
51
+ github.com/gorilla/mux v1.8.0 // indirect
52
+ github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
53
+ github.com/hashicorp/errwrap v1.0.0 // indirect
54
+ github.com/hashicorp/go-multierror v1.1.1 // indirect
55
+ github.com/hashicorp/go-version v1.4.0 // indirect
56
+ github.com/imdario/mergo v0.3.12 // indirect
57
+ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
58
+ github.com/josharian/intern v1.0.0 // indirect
59
+ github.com/json-iterator/go v1.1.12 // indirect
60
+ github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
61
+ github.com/klauspost/compress v1.13.6 // indirect
62
+ github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
63
+ github.com/mailru/easyjson v0.7.6 // indirect
64
+ github.com/mattn/go-colorable v0.1.2 // indirect
65
+ github.com/mattn/go-isatty v0.0.12 // indirect
66
+ github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
67
+ github.com/mitchellh/go-homedir v1.1.0 // indirect
68
+ github.com/mitchellh/reflectwalk v1.0.1 // indirect
69
+ github.com/moby/locker v1.0.1 // indirect
70
+ github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 // indirect
71
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
72
+ github.com/modern-go/reflect2 v1.0.2 // indirect
73
+ github.com/morikuni/aec v1.0.0 // indirect
74
+ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
75
+ github.com/opencontainers/go-digest v1.0.0 // indirect
76
+ github.com/opencontainers/image-spec v1.0.2 // indirect
77
+ github.com/openshift/api v0.0.0-20200930075302-db52bc4ef99f // indirect
78
+ github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
79
+ github.com/pkg/errors v0.9.1 // indirect
80
+ github.com/prometheus/client_golang v1.12.2 // indirect
81
+ github.com/prometheus/client_model v0.2.0 // indirect
82
+ github.com/prometheus/common v0.32.1 // indirect
83
+ github.com/prometheus/procfs v0.7.3 // indirect
84
+ github.com/sergi/go-diff v1.1.0 // indirect
85
+ github.com/sirupsen/logrus v1.8.1 // indirect
86
+ github.com/spf13/afero v1.6.0 // indirect
87
+ github.com/spf13/pflag v1.0.5 // indirect
88
+ github.com/xanzy/ssh-agent v0.3.0 // indirect
89
+ github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
90
+ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
91
+ github.com/xeipuuv/gojsonschema v1.2.0 // indirect
92
+ golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
93
+ golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
94
+ golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
95
+ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
96
+ golang.org/x/sys v0.3.0 // indirect
97
+ golang.org/x/term v0.3.0 // indirect
98
+ golang.org/x/text v0.5.0 // indirect
99
+ golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
100
+ google.golang.org/appengine v1.6.7 // indirect
101
+ google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
102
+ google.golang.org/grpc v1.47.0 // indirect
103
+ google.golang.org/protobuf v1.28.1 // indirect
104
+ gopkg.in/inf.v0 v0.9.1 // indirect
105
+ gopkg.in/warnings.v0 v0.1.2 // indirect
106
+ gopkg.in/yaml.v2 v2.4.0 // indirect
107
+ gopkg.in/yaml.v3 v3.0.1 // indirect
108
+ k8s.io/apiextensions-apiserver v0.25.0 // indirect
109
+ k8s.io/client-go v0.26.1 // indirect
110
+ k8s.io/klog v1.0.0 // indirect
111
+ k8s.io/klog/v2 v2.80.1 // indirect
112
+ k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
113
+ k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
114
+ oras.land/oras-go v1.1.0 // indirect
115
+ sigs.k8s.io/controller-runtime v0.13.1 // indirect
116
+ sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
117
+ sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
118
+ sigs.k8s.io/yaml v1.3.0 // indirect
119
+ )