devfile 0.0.6.pre.alpha1-x86_64-linux → 0.0.11.pre.alpha1-x86_64-linux

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 +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb435b8f1497c4dbfbb5f8baa9cb61823eeae8d555a7a71a80d041dda1f4b537
4
- data.tar.gz: ce594d2dc04ffaa2a0e63257c6251b5ca41be907bcecb1ffd804afe48f478fab
3
+ metadata.gz: 1791e8e7ff6b1f3de970040c705db46fef04cfb524b95f1e0a41d57f97e6d61d
4
+ data.tar.gz: 26ede5ee22624b25fa8142879703a1c80b0fd78bf7e6598da89eec1c4310afbe
5
5
  SHA512:
6
- metadata.gz: 60c599546b8e91f593d9400a79c39f87f3e07c3660649d254d3f587078cafdd3daeab8bfac632900680834b32524b1ac735e5e26dcd0a44fbcbc75ffdc928339
7
- data.tar.gz: 5f69f2979faf1a0900be36a467ec4c70636892b11b6107dae73f5ca7c603922d8f1e760013a0eeac7cfce842f8e0fe69a4fd5405b5616f074d85fa66a7197a48
6
+ metadata.gz: cfba06a846d7ec1a8c18b51cf86d4ff1c96af5ccef21df42e21ddfe0004bcbefabc4fde89c86c67077c1769b44a0a3d4ef7cd237278324b6c26090d8fd2e3b8d
7
+ data.tar.gz: de8183ccfddadb4e3e59a21df545cedcd2b59967c3be488bccf93e8882c37e8e3bc728dbb670dbc62e15460b9f7bfa35ac517acb89421ea24569dcf140a21e19
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6.pre.alpha1
4
+ version: 0.0.11.pre.alpha1
5
5
  platform: x86_64-linux
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-03-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Library used to generate kubernetes manifests from a Devfile.
14
14
  email: spatnaik@gitlab.com