devfile 0.0.5.pre.alpha1-arm64-darwin-22

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: d07f93d3ab5f574344903072d3c57932473697124f1eaac72498295960b2ec00
4
+ data.tar.gz: 20152dfa912e4cf01aef7f77bd167c1efc729a5f371fe56b8a5f7e782cec3760
5
+ SHA512:
6
+ metadata.gz: '00980233234e5543c3b4d0ca3ff4ec4b7bbe162ad0d6db0fc1691e747c3cea623031d133b3dd900cbf84446e16187778956a472a40cb8f3942135c47df1fb1f0'
7
+ data.tar.gz: ab79aac021e6942bf7c4b65f612860375fe3243cfe6555f2263edd5dec1d1a8c81e172b77b088f2bbc18da0923e23181d90114d20c35799f5a96b78f850671c6
data/bin/devfile ADDED
Binary file
data/ext/devfile.go ADDED
@@ -0,0 +1,214 @@
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
+ networkingv1 "k8s.io/api/networking/v1"
13
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
+ "k8s.io/apimachinery/pkg/runtime"
15
+ "k8s.io/cli-runtime/pkg/printers"
16
+ "sigs.k8s.io/yaml"
17
+ )
18
+
19
+ type Devfile struct {
20
+ devfileObj parser.DevfileObj
21
+ }
22
+
23
+ func (d Devfile) getDeployment(name, namespace string, labels, annotations map[string]string, replicas int) (runtime.Object, error) {
24
+ containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
25
+ if err != nil {
26
+ return nil, err
27
+ }
28
+ initContainers, err := generator.GetInitContainers(d.devfileObj)
29
+ if err != nil {
30
+ return nil, err
31
+ }
32
+ volumes, err := d.getVolumesAndVolumeMounts(containers, initContainers, name)
33
+ if err != nil {
34
+ return nil, err
35
+ }
36
+
37
+ deployParams := generator.DeploymentParams{
38
+ TypeMeta: generator.GetTypeMeta("Deployment", "apps/v1"),
39
+ ObjectMeta: generator.GetObjectMeta(name, namespace, labels, annotations),
40
+ InitContainers: initContainers,
41
+ Containers: containers,
42
+ Volumes: volumes,
43
+ PodSelectorLabels: labels,
44
+ Replicas: pointerTo(int32(replicas)),
45
+ }
46
+
47
+ deployment, err := generator.GetDeployment(d.devfileObj, deployParams)
48
+ if err != nil {
49
+ return nil, err
50
+ }
51
+
52
+ return deployment, err
53
+ }
54
+
55
+ func (d Devfile) getService(name, namespace string, labels, annotations map[string]string) (runtime.Object, error) {
56
+ service, err := generator.GetService(d.devfileObj, generator.ServiceParams{
57
+ TypeMeta: generator.GetTypeMeta("Service", "v1"),
58
+ ObjectMeta: generator.GetObjectMeta(name, namespace, labels, annotations),
59
+ SelectorLabels: labels,
60
+ }, common.DevfileOptions{})
61
+ if err != nil {
62
+ return nil, err
63
+ }
64
+
65
+ return service, err
66
+ }
67
+
68
+ func (d Devfile) getIngress(name, namespace string, labels, annotations map[string]string, domainTemplate, ingressClass string) (runtime.Object, error) {
69
+ components, err := d.devfileObj.Data.GetDevfileContainerComponents(common.DevfileOptions{})
70
+ if err != nil {
71
+ return nil, err
72
+ }
73
+
74
+ var hosts []string
75
+ var rules []networkingv1.IngressRule
76
+
77
+ // Create a new template and parse the letter into it.
78
+ t := template.Must(template.New("domainTemplate").Parse(domainTemplate))
79
+
80
+ for _, component := range components {
81
+ for _, endpoint := range component.Container.Endpoints {
82
+ var domain bytes.Buffer
83
+ err := t.Execute(&domain, map[string]string{"port": strconv.Itoa(endpoint.TargetPort)})
84
+ if err != nil {
85
+ return nil, err
86
+ }
87
+ hosts = append(hosts, domain.String())
88
+ rules = append(rules, networkingv1.IngressRule{
89
+ Host: domain.String(),
90
+ IngressRuleValue: networkingv1.IngressRuleValue{
91
+ HTTP: &networkingv1.HTTPIngressRuleValue{
92
+ Paths: []networkingv1.HTTPIngressPath{
93
+ {
94
+ Path: "/",
95
+ PathType: pointerTo(networkingv1.PathTypePrefix),
96
+ Backend: networkingv1.IngressBackend{
97
+ Service: &networkingv1.IngressServiceBackend{
98
+ Name: name,
99
+ Port: networkingv1.ServiceBackendPort{
100
+ Number: int32(endpoint.TargetPort),
101
+ },
102
+ },
103
+ },
104
+ },
105
+ },
106
+ },
107
+ },
108
+ })
109
+ }
110
+ }
111
+
112
+ if len(rules) == 0 {
113
+ return nil, nil
114
+ }
115
+
116
+ // since annotations is a map, it is passed by reference in go
117
+ // hence to modify it, create a new copy
118
+ ingressAnnotations := map[string]string{
119
+ "kubernetes.io/ingress.class": ingressClass,
120
+ }
121
+ for k, v := range annotations {
122
+ ingressAnnotations[k] = v
123
+ }
124
+ ingress := &networkingv1.Ingress{
125
+ TypeMeta: generator.GetTypeMeta("Ingress", "networking.k8s.io/v1"),
126
+ ObjectMeta: metav1.ObjectMeta{
127
+ Name: name,
128
+ Namespace: namespace,
129
+ Labels: labels,
130
+ Annotations: ingressAnnotations,
131
+ },
132
+ Spec: networkingv1.IngressSpec{
133
+ //TLS: []networkingv1.IngressTLS{
134
+ // {
135
+ // Hosts: hosts,
136
+ // SecretName: "tls",
137
+ // },
138
+ //},
139
+ Rules: rules,
140
+ },
141
+ }
142
+
143
+ return ingress, nil
144
+ }
145
+
146
+ func (d Devfile) getAll(name, namespace string, labels, annotations map[string]string, replicas int, domainTemplate, ingressClass string) ([]runtime.Object, error) {
147
+ deployment, err := d.getDeployment(name, namespace, labels, annotations, replicas)
148
+ if err != nil {
149
+ return nil, err
150
+ }
151
+ service, err := d.getService(name, namespace, labels, annotations)
152
+ if err != nil {
153
+ return nil, err
154
+ }
155
+ ingress, err := d.getIngress(name, namespace, labels, annotations, domainTemplate, ingressClass)
156
+ if err != nil {
157
+ return nil, err
158
+ }
159
+
160
+ return []runtime.Object{deployment, service, ingress}, nil
161
+ }
162
+
163
+ func (d Devfile) hasContainerComponents() (bool, error) {
164
+ containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
165
+ if err != nil {
166
+ return false, err
167
+ }
168
+ if len(containers) > 0 {
169
+ return true, nil
170
+ }
171
+ return false, nil
172
+ }
173
+
174
+ func (d Devfile) getFlattenedDevfileContent() string {
175
+ return string(d.devfileObj.Ctx.GetDevfileContent())
176
+ }
177
+
178
+ func parseDevfile(content string) (Devfile, error) {
179
+ parserArgs := parser.ParserArgs{
180
+ Data: []byte(content),
181
+ }
182
+ devfileObj, err := parser.ParseDevfile(parserArgs)
183
+ return Devfile{
184
+ devfileObj: devfileObj,
185
+ }, err
186
+ }
187
+
188
+ func marshalResources(objs []runtime.Object) (string, error) {
189
+ printer := printers.YAMLPrinter{}
190
+ dest := bytes.NewBuffer([]byte{})
191
+ for _, obj := range objs {
192
+ if obj == nil {
193
+ continue
194
+ }
195
+ err := printer.PrintObj(obj, dest)
196
+ if err != nil {
197
+ return "", err
198
+ }
199
+ }
200
+ return dest.String(), nil
201
+ }
202
+
203
+ func marshalDevfile(devfile string) (string, error) {
204
+ data, err := yaml.JSONToYAML([]byte(devfile))
205
+ if err != nil {
206
+ return "", err
207
+ }
208
+ return string(data), nil
209
+ }
210
+
211
+ // since it is not possible to get pointer of a constant directly
212
+ func pointerTo[T any](v T) *T {
213
+ return &v
214
+ }
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
+ )