devfile 0.0.2.pre.alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6b5ccb630f8c382fdec4a27c4d68f09f10630fd51f517e2cde323cfc02bfef22
4
+ data.tar.gz: e4933a597caaeb4ea040b8045a623e4e359912dbb8da5fc229ae7c51d5af7e17
5
+ SHA512:
6
+ metadata.gz: d414b0f161daccc339bc8f95fa145c935aaa0b3b2ac950ce4f3046e517a58a8c9903fd5c7c3485b9aa8ce4a08055fd710892412609ece2e9300940d5b03b7f38
7
+ data.tar.gz: 458502ef4f3178ab10d54c982c438baa17b2848b3ab881e5508e74658cc1a9348dfc88e1220db5c3741d9e503745ee9a661909834fc06b0949e5718e07b1d5a0
data/ext/devfile.go ADDED
@@ -0,0 +1,186 @@
1
+ package main
2
+
3
+ import "C"
4
+ import (
5
+ "bytes"
6
+ "fmt"
7
+
8
+ "github.com/devfile/library/pkg/devfile/generator"
9
+ "github.com/devfile/library/pkg/devfile/parser"
10
+ "github.com/devfile/library/pkg/devfile/parser/data/v2/common"
11
+ networkingv1 "k8s.io/api/networking/v1"
12
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
+ "k8s.io/apimachinery/pkg/runtime"
14
+ "k8s.io/cli-runtime/pkg/printers"
15
+ )
16
+
17
+ const (
18
+ defaultIngressClass = "ingress-nginx"
19
+ )
20
+
21
+ type Devfile struct {
22
+ devfileObj parser.DevfileObj
23
+ }
24
+
25
+ func (d Devfile) getDeployment(name, namespace string) (runtime.Object, error) {
26
+ containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
27
+ if err != nil {
28
+ return nil, err
29
+ }
30
+
31
+ deployParams := generator.DeploymentParams{
32
+ TypeMeta: generator.GetTypeMeta("Deployment", "apps/v1"),
33
+ ObjectMeta: generator.GetObjectMeta(name, namespace, map[string]string{}, make(map[string]string)),
34
+ Containers: containers,
35
+ PodSelectorLabels: map[string]string{
36
+ "name": name,
37
+ },
38
+ }
39
+
40
+ deployment, err := generator.GetDeployment(d.devfileObj, deployParams)
41
+ if err != nil {
42
+ return nil, err
43
+ }
44
+
45
+ return deployment, err
46
+ }
47
+
48
+ func (d Devfile) getService(name, namespace string) (runtime.Object, error) {
49
+ service, err := generator.GetService(d.devfileObj, generator.ServiceParams{
50
+ TypeMeta: generator.GetTypeMeta("Service", "v1"),
51
+ ObjectMeta: generator.GetObjectMeta(name, namespace, map[string]string{}, map[string]string{}),
52
+ SelectorLabels: map[string]string{
53
+ "name": name,
54
+ },
55
+ }, common.DevfileOptions{})
56
+ if err != nil {
57
+ return nil, err
58
+ }
59
+
60
+ return service, err
61
+ }
62
+
63
+ func (d Devfile) getIngress(name, namespace, domain string) (runtime.Object, error) {
64
+ components, err := d.devfileObj.Data.GetDevfileContainerComponents(common.DevfileOptions{})
65
+ if err != nil {
66
+ return nil, err
67
+ }
68
+
69
+ var hosts []string
70
+ var rules []networkingv1.IngressRule
71
+
72
+ for _, component := range components {
73
+ for _, endpoint := range component.Container.Endpoints {
74
+ domain := fmt.Sprintf("%d-%v", endpoint.TargetPort, domain)
75
+ hosts = append(hosts, domain)
76
+ rules = append(rules, networkingv1.IngressRule{
77
+ Host: domain,
78
+ IngressRuleValue: networkingv1.IngressRuleValue{
79
+ HTTP: &networkingv1.HTTPIngressRuleValue{
80
+ Paths: []networkingv1.HTTPIngressPath{
81
+ {
82
+ Path: "/",
83
+ PathType: pointerTo(networkingv1.PathTypePrefix),
84
+ Backend: networkingv1.IngressBackend{
85
+ Service: &networkingv1.IngressServiceBackend{
86
+ Name: name,
87
+ Port: networkingv1.ServiceBackendPort{
88
+ Number: int32(endpoint.TargetPort),
89
+ },
90
+ },
91
+ },
92
+ },
93
+ },
94
+ },
95
+ },
96
+ })
97
+ }
98
+ }
99
+
100
+ if len(rules) == 0 {
101
+ return nil, nil
102
+ }
103
+
104
+ ingress := &networkingv1.Ingress{
105
+ TypeMeta: generator.GetTypeMeta("Ingress", "networking.k8s.io/v1"),
106
+ ObjectMeta: metav1.ObjectMeta{
107
+ Name: name,
108
+ Namespace: namespace,
109
+ Annotations: map[string]string{
110
+ "kubernetes.io/ingress.class": defaultIngressClass,
111
+ },
112
+ },
113
+ Spec: networkingv1.IngressSpec{
114
+ //TLS: []networkingv1.IngressTLS{
115
+ // {
116
+ // Hosts: hosts,
117
+ // SecretName: "tls",
118
+ // },
119
+ //},
120
+ Rules: rules,
121
+ },
122
+ }
123
+
124
+ return ingress, nil
125
+ }
126
+
127
+ func (d Devfile) getAll(name, namespace, domain string) ([]runtime.Object, error) {
128
+ deployment, err := d.getDeployment(name, namespace)
129
+ if err != nil {
130
+ return nil, err
131
+ }
132
+ service, err := d.getService(name, namespace)
133
+ if err != nil {
134
+ return nil, err
135
+ }
136
+ ingress, err := d.getIngress(name, namespace, domain)
137
+ if err != nil {
138
+ return nil, err
139
+ }
140
+
141
+ return []runtime.Object{deployment, service, ingress}, nil
142
+ }
143
+
144
+ func (d Devfile) hasContainerComponents() (bool, error) {
145
+ containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
146
+ if err != nil {
147
+ return false, err
148
+ }
149
+ if len(containers) > 0 {
150
+ return true, nil
151
+ }
152
+ return false, nil
153
+ }
154
+
155
+ func (d Devfile) getFlattenedDevfileContent() string {
156
+ return string(d.devfileObj.Ctx.GetDevfileContent())
157
+ }
158
+
159
+ func parseDevfile(content string) (parser.DevfileObj, error) {
160
+ parserArgs := parser.ParserArgs{
161
+ Data: []byte(content),
162
+ }
163
+
164
+ devfile, err := parser.ParseDevfile(parserArgs)
165
+ return devfile, err
166
+ }
167
+
168
+ func marshal(objs []runtime.Object) (string, error) {
169
+ printer := printers.YAMLPrinter{}
170
+ dest := bytes.NewBuffer([]byte{})
171
+ for _, obj := range objs {
172
+ if obj == nil {
173
+ continue
174
+ }
175
+ err := printer.PrintObj(obj, dest)
176
+ if err != nil {
177
+ return "", err
178
+ }
179
+ }
180
+ return dest.String(), nil
181
+ }
182
+
183
+ // since it is not possible to get pointer of a constant directly
184
+ func pointerTo[T any](v T) *T {
185
+ return &v
186
+ }
data/ext/extconf.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ makefile_contents = "all:\n\techo \"Starting...\"\n\ninstall:\n\tgo build -buildmode=c-shared -o ../lib/devfile.so\n\n"
4
+
5
+ File.write('Makefile', makefile_contents)
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 v1.3.0
7
+ k8s.io/cli-runtime v0.26.1
8
+ )
9
+
10
+ require (
11
+ github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
12
+ github.com/Microsoft/go-winio v0.5.1 // indirect
13
+ github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
14
+ github.com/acomagu/bufpipe v1.0.3 // indirect
15
+ github.com/beorn7/perks v1.0.1 // indirect
16
+ github.com/cespare/xxhash/v2 v2.1.2 // indirect
17
+ github.com/containerd/containerd v1.5.9 // indirect
18
+ github.com/davecgh/go-spew v1.1.1 // indirect
19
+ github.com/devfile/api/v2 v2.2.0 // indirect
20
+ github.com/devfile/registry-support/index/generator v0.0.0-20220527155645-8328a8a883be // indirect
21
+ github.com/devfile/registry-support/registry-library v0.0.0-20220627163229-4aa39fcb0c0a // indirect
22
+ github.com/docker/cli v20.10.11+incompatible // indirect
23
+ github.com/docker/distribution v2.7.1+incompatible // indirect
24
+ github.com/docker/docker v20.10.11+incompatible // indirect
25
+ github.com/docker/docker-credential-helpers v0.6.4 // indirect
26
+ github.com/docker/go-connections v0.4.0 // indirect
27
+ github.com/docker/go-metrics v0.0.1 // indirect
28
+ github.com/docker/go-units v0.4.0 // indirect
29
+ github.com/emicklei/go-restful/v3 v3.9.0 // indirect
30
+ github.com/emirpasic/gods v1.12.0 // indirect
31
+ github.com/evanphx/json-patch/v5 v5.6.0 // indirect
32
+ github.com/fatih/color v1.7.0 // indirect
33
+ github.com/fsnotify/fsnotify v1.5.4 // indirect
34
+ github.com/go-git/gcfg v1.5.0 // indirect
35
+ github.com/go-git/go-billy/v5 v5.3.1 // indirect
36
+ github.com/go-git/go-git/v5 v5.4.2 // indirect
37
+ github.com/go-logr/logr v1.2.3 // indirect
38
+ github.com/go-openapi/jsonpointer v0.19.5 // indirect
39
+ github.com/go-openapi/jsonreference v0.20.0 // indirect
40
+ github.com/go-openapi/swag v0.19.14 // indirect
41
+ github.com/gobwas/glob v0.2.3 // indirect
42
+ github.com/gogo/protobuf v1.3.2 // indirect
43
+ github.com/golang/mock v1.6.0 // indirect
44
+ github.com/golang/protobuf v1.5.2 // indirect
45
+ github.com/google/btree v1.0.1 // indirect
46
+ github.com/google/gnostic v0.5.7-v3refs // indirect
47
+ github.com/google/go-cmp v0.5.9 // indirect
48
+ github.com/google/gofuzz v1.2.0 // indirect
49
+ github.com/gorilla/mux v1.8.0 // indirect
50
+ github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
51
+ github.com/hashicorp/errwrap v1.0.0 // indirect
52
+ github.com/hashicorp/go-multierror v1.1.1 // indirect
53
+ github.com/hashicorp/go-version v1.4.0 // indirect
54
+ github.com/imdario/mergo v0.3.12 // indirect
55
+ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
56
+ github.com/josharian/intern v1.0.0 // indirect
57
+ github.com/json-iterator/go v1.1.12 // indirect
58
+ github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
59
+ github.com/klauspost/compress v1.13.6 // indirect
60
+ github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
61
+ github.com/mailru/easyjson v0.7.6 // indirect
62
+ github.com/mattn/go-colorable v0.1.2 // indirect
63
+ github.com/mattn/go-isatty v0.0.12 // indirect
64
+ github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
65
+ github.com/mitchellh/go-homedir v1.1.0 // indirect
66
+ github.com/mitchellh/reflectwalk v1.0.1 // indirect
67
+ github.com/moby/locker v1.0.1 // indirect
68
+ github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 // indirect
69
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
70
+ github.com/modern-go/reflect2 v1.0.2 // indirect
71
+ github.com/morikuni/aec v1.0.0 // indirect
72
+ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
73
+ github.com/opencontainers/go-digest v1.0.0 // indirect
74
+ github.com/opencontainers/image-spec v1.0.2 // indirect
75
+ github.com/openshift/api v0.0.0-20200930075302-db52bc4ef99f // indirect
76
+ github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
77
+ github.com/pkg/errors v0.9.1 // indirect
78
+ github.com/prometheus/client_golang v1.12.2 // indirect
79
+ github.com/prometheus/client_model v0.2.0 // indirect
80
+ github.com/prometheus/common v0.32.1 // indirect
81
+ github.com/prometheus/procfs v0.7.3 // indirect
82
+ github.com/sergi/go-diff v1.1.0 // indirect
83
+ github.com/sirupsen/logrus v1.8.1 // indirect
84
+ github.com/spf13/afero v1.6.0 // indirect
85
+ github.com/spf13/pflag v1.0.5 // indirect
86
+ github.com/xanzy/ssh-agent v0.3.0 // indirect
87
+ github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
88
+ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
89
+ github.com/xeipuuv/gojsonschema v1.2.0 // indirect
90
+ golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
91
+ golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
92
+ golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
93
+ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
94
+ golang.org/x/sys v0.3.0 // indirect
95
+ golang.org/x/term v0.3.0 // indirect
96
+ golang.org/x/text v0.5.0 // indirect
97
+ golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
98
+ google.golang.org/appengine v1.6.7 // indirect
99
+ google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
100
+ google.golang.org/grpc v1.47.0 // indirect
101
+ google.golang.org/protobuf v1.28.1 // indirect
102
+ gopkg.in/inf.v0 v0.9.1 // indirect
103
+ gopkg.in/warnings.v0 v0.1.2 // indirect
104
+ gopkg.in/yaml.v2 v2.4.0 // indirect
105
+ gopkg.in/yaml.v3 v3.0.1 // indirect
106
+ k8s.io/api v0.26.1 // indirect
107
+ k8s.io/apiextensions-apiserver v0.25.0 // indirect
108
+ k8s.io/apimachinery v0.26.1 // 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
+ )