devfile 0.0.5.pre.alpha1-arm64-darwin → 0.0.11.pre.alpha1-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/devfile +0 -0
  3. data/ext/devfile.go +27 -14
  4. data/ext/main.go +57 -56
  5. metadata +7 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7213c30bd262a47cc7230b2766d8af2af0d2d9e14f13d5deede4c80fc565abd7
4
- data.tar.gz: 14fb2059088725869adfb122c9da334d2890220be97dd46ec39eca2f9d502941
3
+ metadata.gz: 022c2013340f8ac58d39c78763e2820e5ecdbde4b4bfad366756a4c018ad610c
4
+ data.tar.gz: f3f50f92496f1361859f2140f264fc17817aa4f2d80c7608f12270a84a869c40
5
5
  SHA512:
6
- metadata.gz: 3b0f12ae00f9f5752cb2da4c4805ce2323a7b0c79ce021a311a576ffea9d3436fbbeba04eab05037a7cf1b5cb9818461436e9ae5b3c2b55199b2a770d25c118f
7
- data.tar.gz: d483b86fd468e4d42104e7596b2e1a228de720a2b00889b34d43869f7817b667832f2e5d467f3bfa04444537c5ce922fb610dc44f17c6ffb8d0d914e3e222348
6
+ metadata.gz: 78758a78eb281a2ed9e65230425a33fb43b1b0da61419351e73efe154a47aee552dee439d9b0ad45f6fb307bdb5f35dbf435925c3ac6add0f35534b25ba1c1a9
7
+ data.tar.gz: 06e0da12b3a91d20e53cfcc1d500cdc03c73e8121047b35af1ce5ca3d7e8ca62b72785c5f37ead01eadd181ad8d7078297744525c77b0dafae2abfea654884f3
data/bin/devfile CHANGED
Binary file
data/ext/devfile.go CHANGED
@@ -9,6 +9,8 @@ import (
9
9
  "github.com/devfile/library/v2/pkg/devfile/generator"
10
10
  "github.com/devfile/library/v2/pkg/devfile/parser"
11
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"
12
14
  networkingv1 "k8s.io/api/networking/v1"
13
15
  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
16
  "k8s.io/apimachinery/pkg/runtime"
@@ -20,7 +22,7 @@ type Devfile struct {
20
22
  devfileObj parser.DevfileObj
21
23
  }
22
24
 
23
- func (d Devfile) getDeployment(name, namespace string, labels, annotations map[string]string, replicas int) (runtime.Object, error) {
25
+ func (d Devfile) getDeployment(name, namespace string, labels, annotations map[string]string, replicas int) (*appsv1.Deployment, error) {
24
26
  containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
25
27
  if err != nil {
26
28
  return nil, err
@@ -52,7 +54,7 @@ func (d Devfile) getDeployment(name, namespace string, labels, annotations map[s
52
54
  return deployment, err
53
55
  }
54
56
 
55
- func (d Devfile) getService(name, namespace string, labels, annotations map[string]string) (runtime.Object, error) {
57
+ func (d Devfile) getService(name, namespace string, labels, annotations map[string]string) (*corev1.Service, error) {
56
58
  service, err := generator.GetService(d.devfileObj, generator.ServiceParams{
57
59
  TypeMeta: generator.GetTypeMeta("Service", "v1"),
58
60
  ObjectMeta: generator.GetObjectMeta(name, namespace, labels, annotations),
@@ -65,7 +67,12 @@ func (d Devfile) getService(name, namespace string, labels, annotations map[stri
65
67
  return service, err
66
68
  }
67
69
 
68
- func (d Devfile) getIngress(name, namespace string, labels, annotations map[string]string, domainTemplate, ingressClass string) (runtime.Object, error) {
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
+
69
76
  components, err := d.devfileObj.Data.GetDevfileContainerComponents(common.DevfileOptions{})
70
77
  if err != nil {
71
78
  return nil, err
@@ -75,7 +82,10 @@ func (d Devfile) getIngress(name, namespace string, labels, annotations map[stri
75
82
  var rules []networkingv1.IngressRule
76
83
 
77
84
  // Create a new template and parse the letter into it.
78
- t := template.Must(template.New("domainTemplate").Parse(domainTemplate))
85
+ t, err := template.New("domainTemplate").Parse(domainTemplate)
86
+ if err != nil {
87
+ return nil, err
88
+ }
79
89
 
80
90
  for _, component := range components {
81
91
  for _, endpoint := range component.Container.Endpoints {
@@ -113,23 +123,16 @@ func (d Devfile) getIngress(name, namespace string, labels, annotations map[stri
113
123
  return nil, nil
114
124
  }
115
125
 
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
126
  ingress := &networkingv1.Ingress{
125
127
  TypeMeta: generator.GetTypeMeta("Ingress", "networking.k8s.io/v1"),
126
128
  ObjectMeta: metav1.ObjectMeta{
127
129
  Name: name,
128
130
  Namespace: namespace,
129
131
  Labels: labels,
130
- Annotations: ingressAnnotations,
132
+ Annotations: annotations,
131
133
  },
132
134
  Spec: networkingv1.IngressSpec{
135
+ IngressClassName: &ingressClass,
133
136
  //TLS: []networkingv1.IngressTLS{
134
137
  // {
135
138
  // Hosts: hosts,
@@ -144,20 +147,30 @@ func (d Devfile) getIngress(name, namespace string, labels, annotations map[stri
144
147
  }
145
148
 
146
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
+
147
153
  deployment, err := d.getDeployment(name, namespace, labels, annotations, replicas)
148
154
  if err != nil {
149
155
  return nil, err
150
156
  }
157
+ result = append(result, deployment)
158
+
151
159
  service, err := d.getService(name, namespace, labels, annotations)
152
160
  if err != nil {
153
161
  return nil, err
154
162
  }
163
+ result = append(result, service)
164
+
155
165
  ingress, err := d.getIngress(name, namespace, labels, annotations, domainTemplate, ingressClass)
156
166
  if err != nil {
157
167
  return nil, err
158
168
  }
169
+ if ingress != nil {
170
+ result = append(result, ingress)
171
+ }
159
172
 
160
- return []runtime.Object{deployment, service, ingress}, nil
173
+ return result, nil
161
174
  }
162
175
 
163
176
  func (d Devfile) hasContainerComponents() (bool, error) {
data/ext/main.go CHANGED
@@ -9,11 +9,6 @@ import (
9
9
  "k8s.io/apimachinery/pkg/runtime"
10
10
  )
11
11
 
12
- type Result struct {
13
- content string
14
- err error
15
- }
16
-
17
12
  func main() {
18
13
  args := os.Args
19
14
 
@@ -25,27 +20,28 @@ func main() {
25
20
  fnName := os.Args[1]
26
21
  devfile := os.Args[2]
27
22
 
28
- var result Result
23
+ var content string
24
+ var err error
29
25
 
30
26
  switch fnName {
31
27
  case "deployment":
32
- result = getDeployment(devfile, args[3], args[4], args[5], args[6], args[7])
28
+ content, err = getDeployment(devfile, args[3], args[4], args[5], args[6], args[7])
33
29
  case "service":
34
- result = getService(devfile, args[3], args[4], args[5], args[6])
30
+ content, err = getService(devfile, args[3], args[4], args[5], args[6])
35
31
  case "ingress":
36
- result = getIngress(devfile, args[3], args[4], args[5], args[6], args[7], args[8])
32
+ content, err = getIngress(devfile, args[3], args[4], args[5], args[6], args[7], args[8])
37
33
  case "all":
38
- result = getAll(devfile, args[3], args[4], args[5], args[6], args[7], args[8], args[9])
34
+ content, err = getAll(devfile, args[3], args[4], args[5], args[6], args[7], args[8], args[9])
39
35
  case "flatten":
40
- result = flatten(devfile)
36
+ content, err = flatten(devfile)
41
37
  }
42
38
 
43
- if result.err != nil {
44
- fmt.Fprint(os.Stderr, result.err)
39
+ if err != nil {
40
+ fmt.Fprint(os.Stderr, err)
45
41
  os.Exit(1)
46
42
  }
47
43
 
48
- fmt.Print(result.content)
44
+ fmt.Print(content)
49
45
  }
50
46
 
51
47
  func unmarshalKeyValuePair(data string) (map[string]string, error) {
@@ -57,147 +53,152 @@ func unmarshalKeyValuePair(data string) (map[string]string, error) {
57
53
  return values, err
58
54
  }
59
55
 
60
- func getDeployment(devfile, name, namespace, labelsStr, annotationsStr, replicas string) Result {
56
+ func getDeployment(devfile, name, namespace, labelsStr, annotationsStr, replicas string) (string, error) {
61
57
  d, err := parseDevfile(devfile)
62
58
  if err != nil {
63
- return Result{"", err}
59
+ return "", err
64
60
  }
65
61
  exists, err := d.hasContainerComponents()
66
62
  if err != nil {
67
- return Result{"", err}
63
+ return "", err
68
64
  }
69
65
  if exists == false {
70
- return Result{"", err}
66
+ return "", err
71
67
  }
72
68
  labels, err := unmarshalKeyValuePair(labelsStr)
73
69
  if err != nil {
74
- return Result{"", err}
70
+ return "", err
75
71
  }
76
72
  annotations, err := unmarshalKeyValuePair(annotationsStr)
77
73
  if err != nil {
78
- return Result{"", err}
74
+ return "", err
79
75
  }
80
76
  replicasInt, err := strconv.Atoi(replicas)
81
77
  if err != nil {
82
- return Result{"", err}
78
+ return "", err
83
79
  }
84
80
  deployment, err := d.getDeployment(name, namespace, labels, annotations, replicasInt)
85
81
  if err != nil {
86
- return Result{"", err}
82
+ return "", err
87
83
  }
88
84
  content, err := marshalResources([]runtime.Object{deployment})
89
85
  if err != nil {
90
- return Result{"", err}
86
+ return "", err
91
87
  }
92
- return Result{content, nil}
88
+ return content, nil
93
89
  }
94
90
 
95
- func getService(devfile, name, namespace, labelsStr, annotationsStr string) Result {
91
+ func getService(devfile, name, namespace, labelsStr, annotationsStr string) (string, error) {
96
92
  d, err := parseDevfile(devfile)
97
93
  if err != nil {
98
- return Result{"", err}
94
+ return "", err
99
95
  }
100
96
  exists, err := d.hasContainerComponents()
101
97
  if err != nil {
102
- return Result{"", err}
98
+ return "", err
103
99
  }
104
100
  if exists == false {
105
- return Result{"", err}
101
+ return "", err
106
102
  }
107
103
  labels, err := unmarshalKeyValuePair(labelsStr)
108
104
  if err != nil {
109
- return Result{"", err}
105
+ return "", err
110
106
  }
111
107
  annotations, err := unmarshalKeyValuePair(annotationsStr)
112
108
  if err != nil {
113
- return Result{"", err}
109
+ return "", err
114
110
  }
115
111
  service, err := d.getService(name, namespace, labels, annotations)
116
112
  if err != nil {
117
- return Result{"", err}
113
+ return "", err
118
114
  }
119
115
  content, err := marshalResources([]runtime.Object{service})
120
116
  if err != nil {
121
- return Result{"", err}
117
+ return "", err
122
118
  }
123
- return Result{content, nil}
119
+ return content, nil
124
120
  }
125
121
 
126
- func getIngress(devfile, name, namespace, labelsStr, annotationsStr, domainTemplate, ingressClass string) Result {
122
+ func getIngress(devfile, name, namespace, labelsStr, annotationsStr, domainTemplate, ingressClass string) (string, error) {
127
123
  d, err := parseDevfile(devfile)
128
124
  if err != nil {
129
- return Result{"", err}
125
+ return "", err
130
126
  }
131
127
  exists, err := d.hasContainerComponents()
132
128
  if err != nil {
133
- return Result{"", err}
129
+ return "", err
134
130
  }
135
131
  if exists == false {
136
- return Result{"", err}
132
+ return "", err
137
133
  }
138
134
  labels, err := unmarshalKeyValuePair(labelsStr)
139
135
  if err != nil {
140
- return Result{"", err}
136
+ return "", err
141
137
  }
142
138
  annotations, err := unmarshalKeyValuePair(annotationsStr)
143
139
  if err != nil {
144
- return Result{"", err}
140
+ return "", err
145
141
  }
146
142
  ingress, err := d.getIngress(name, namespace, labels, annotations, domainTemplate, ingressClass)
147
143
  if err != nil {
148
- return Result{"", err}
144
+ return "", err
149
145
  }
146
+
147
+ if ingress == nil {
148
+ return "", nil
149
+ }
150
+
150
151
  content, err := marshalResources([]runtime.Object{ingress})
151
152
  if err != nil {
152
- return Result{"", err}
153
+ return "", err
153
154
  }
154
- return Result{content, nil}
155
+ return content, nil
155
156
  }
156
157
 
157
- func getAll(devfile string, name, namespace, labelsStr, annotationsStr, replicas, domainTemplate, ingressClass string) Result {
158
+ func getAll(devfile string, name, namespace, labelsStr, annotationsStr, replicas, domainTemplate, ingressClass string) (string, error) {
158
159
  d, err := parseDevfile(devfile)
159
160
  if err != nil {
160
- return Result{"", err}
161
+ return "", err
161
162
  }
162
163
  exists, err := d.hasContainerComponents()
163
164
  if err != nil {
164
- return Result{"", err}
165
+ return "", err
165
166
  }
166
167
  if exists == false {
167
- return Result{"", err}
168
+ return "", err
168
169
  }
169
170
  labels, err := unmarshalKeyValuePair(labelsStr)
170
171
  if err != nil {
171
- return Result{"", err}
172
+ return "", err
172
173
  }
173
174
  annotations, err := unmarshalKeyValuePair(annotationsStr)
174
175
  if err != nil {
175
- return Result{"", err}
176
+ return "", err
176
177
  }
177
178
  replicasInt, err := strconv.Atoi(replicas)
178
179
  if err != nil {
179
- return Result{"", err}
180
+ return "", err
180
181
  }
181
182
  resources, err := d.getAll(name, namespace, labels, annotations, replicasInt, domainTemplate, ingressClass)
182
183
  if err != nil {
183
- return Result{"", err}
184
+ return "", err
184
185
  }
185
186
  content, err := marshalResources(resources)
186
187
  if err != nil {
187
- return Result{"", err}
188
+ return "", err
188
189
  }
189
- return Result{content, nil}
190
+ return content, nil
190
191
  }
191
192
 
192
- func flatten(devfile string) Result {
193
+ func flatten(devfile string) (string, error) {
193
194
  d, err := parseDevfile(devfile)
194
195
  if err != nil {
195
- return Result{"", err}
196
+ return "", err
196
197
  }
197
198
  flattenedDevfile := d.getFlattenedDevfileContent()
198
199
  content, err := marshalDevfile(flattenedDevfile)
199
200
  if err != nil {
200
- return Result{"", err}
201
+ return "", err
201
202
  }
202
- return Result{content, nil}
203
+ return content, err
203
204
  }
metadata CHANGED
@@ -1,17 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5.pre.alpha1
4
+ version: 0.0.11.pre.alpha1
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-09 00:00:00.000000000 Z
11
+ date: 2023-04-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Library used to generate kubernetes manifests from a Devfile.
14
- email: spatnaik@gitlab.com
14
+ email:
15
+ - cwoolley@gitlab.com
16
+ - vtak@gitlab.com
17
+ - spatnaik@gitlab.com
15
18
  executables: []
16
19
  extensions: []
17
20
  extra_rdoc_files: []
@@ -43,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
46
  - !ruby/object:Gem::Version
44
47
  version: 1.3.1
45
48
  requirements: []
46
- rubygems_version: 3.4.7
49
+ rubygems_version: 3.4.10
47
50
  signing_key:
48
51
  specification_version: 4
49
52
  summary: Parse and generate kubernetes manifests from a Devfile