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