devfile 0.0.4.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 (6) hide show
  1. checksums.yaml +4 -4
  2. data/bin/devfile +0 -0
  3. data/ext/devfile.go +41 -19
  4. data/ext/main.go +59 -58
  5. data/lib/devfile.rb +12 -6
  6. metadata +7 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4a0cbfc19ce498b326dd1965e0e1c0b6bd0770c0be0883d0dc2a25b8a64cb02
4
- data.tar.gz: d6faa2a25ebb91b46210c94a7781aef81c1f448e15cafa4e8cd515fc419ad212
3
+ metadata.gz: 022c2013340f8ac58d39c78763e2820e5ecdbde4b4bfad366756a4c018ad610c
4
+ data.tar.gz: f3f50f92496f1361859f2140f264fc17817aa4f2d80c7608f12270a84a869c40
5
5
  SHA512:
6
- metadata.gz: 2cdb63e4378984c54e7819a65f55004ade1b6999aa019b3dc8baf1cc5bd5ca3792c25956c5c15c19f8187a5785be53ea6b081a64f5de7ab3be02d622184bd2b3
7
- data.tar.gz: 69eb6890060ec6fae9c16f9ff6d2f9bf7e3ae216803af4540737a3c7bc751d488a280c9fc51e938c9df0ff06da70383f92ad5dbb83a1d98945721c5491844474
6
+ metadata.gz: 78758a78eb281a2ed9e65230425a33fb43b1b0da61419351e73efe154a47aee552dee439d9b0ad45f6fb307bdb5f35dbf435925c3ac6add0f35534b25ba1c1a9
7
+ data.tar.gz: 06e0da12b3a91d20e53cfcc1d500cdc03c73e8121047b35af1ce5ca3d7e8ca62b72785c5f37ead01eadd181ad8d7078297744525c77b0dafae2abfea654884f3
data/bin/devfile CHANGED
Binary file
data/ext/devfile.go CHANGED
@@ -3,10 +3,14 @@ package main
3
3
  import "C"
4
4
  import (
5
5
  "bytes"
6
- "fmt"
6
+ "strconv"
7
+ "text/template"
8
+
7
9
  "github.com/devfile/library/v2/pkg/devfile/generator"
8
10
  "github.com/devfile/library/v2/pkg/devfile/parser"
9
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"
10
14
  networkingv1 "k8s.io/api/networking/v1"
11
15
  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12
16
  "k8s.io/apimachinery/pkg/runtime"
@@ -18,7 +22,7 @@ type Devfile struct {
18
22
  devfileObj parser.DevfileObj
19
23
  }
20
24
 
21
- 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) {
22
26
  containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
23
27
  if err != nil {
24
28
  return nil, err
@@ -50,7 +54,7 @@ func (d Devfile) getDeployment(name, namespace string, labels, annotations map[s
50
54
  return deployment, err
51
55
  }
52
56
 
53
- 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) {
54
58
  service, err := generator.GetService(d.devfileObj, generator.ServiceParams{
55
59
  TypeMeta: generator.GetTypeMeta("Service", "v1"),
56
60
  ObjectMeta: generator.GetObjectMeta(name, namespace, labels, annotations),
@@ -63,7 +67,12 @@ func (d Devfile) getService(name, namespace string, labels, annotations map[stri
63
67
  return service, err
64
68
  }
65
69
 
66
- func (d Devfile) getIngress(name, namespace string, labels, annotations map[string]string, domainSuffix, 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
+
67
76
  components, err := d.devfileObj.Data.GetDevfileContainerComponents(common.DevfileOptions{})
68
77
  if err != nil {
69
78
  return nil, err
@@ -72,12 +81,22 @@ func (d Devfile) getIngress(name, namespace string, labels, annotations map[stri
72
81
  var hosts []string
73
82
  var rules []networkingv1.IngressRule
74
83
 
84
+ // Create a new template and parse the letter into it.
85
+ t, err := template.New("domainTemplate").Parse(domainTemplate)
86
+ if err != nil {
87
+ return nil, err
88
+ }
89
+
75
90
  for _, component := range components {
76
91
  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)
92
+ var domain bytes.Buffer
93
+ err := t.Execute(&domain, map[string]string{"port": strconv.Itoa(endpoint.TargetPort)})
94
+ if err != nil {
95
+ return nil, err
96
+ }
97
+ hosts = append(hosts, domain.String())
79
98
  rules = append(rules, networkingv1.IngressRule{
80
- Host: domain,
99
+ Host: domain.String(),
81
100
  IngressRuleValue: networkingv1.IngressRuleValue{
82
101
  HTTP: &networkingv1.HTTPIngressRuleValue{
83
102
  Paths: []networkingv1.HTTPIngressPath{
@@ -104,23 +123,16 @@ func (d Devfile) getIngress(name, namespace string, labels, annotations map[stri
104
123
  return nil, nil
105
124
  }
106
125
 
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
126
  ingress := &networkingv1.Ingress{
116
127
  TypeMeta: generator.GetTypeMeta("Ingress", "networking.k8s.io/v1"),
117
128
  ObjectMeta: metav1.ObjectMeta{
118
129
  Name: name,
119
130
  Namespace: namespace,
120
131
  Labels: labels,
121
- Annotations: ingressAnnotations,
132
+ Annotations: annotations,
122
133
  },
123
134
  Spec: networkingv1.IngressSpec{
135
+ IngressClassName: &ingressClass,
124
136
  //TLS: []networkingv1.IngressTLS{
125
137
  // {
126
138
  // Hosts: hosts,
@@ -134,21 +146,31 @@ func (d Devfile) getIngress(name, namespace string, labels, annotations map[stri
134
146
  return ingress, nil
135
147
  }
136
148
 
137
- func (d Devfile) getAll(name, namespace string, labels, annotations map[string]string, replicas int, domainSuffix, ingressClass string) ([]runtime.Object, error) {
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
+
138
153
  deployment, err := d.getDeployment(name, namespace, labels, annotations, replicas)
139
154
  if err != nil {
140
155
  return nil, err
141
156
  }
157
+ result = append(result, deployment)
158
+
142
159
  service, err := d.getService(name, namespace, labels, annotations)
143
160
  if err != nil {
144
161
  return nil, err
145
162
  }
146
- ingress, err := d.getIngress(name, namespace, labels, annotations, domainSuffix, ingressClass)
163
+ result = append(result, service)
164
+
165
+ ingress, err := d.getIngress(name, namespace, labels, annotations, domainTemplate, ingressClass)
147
166
  if err != nil {
148
167
  return nil, err
149
168
  }
169
+ if ingress != nil {
170
+ result = append(result, ingress)
171
+ }
150
172
 
151
- return []runtime.Object{deployment, service, ingress}, nil
173
+ return result, nil
152
174
  }
153
175
 
154
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, domainSuffix, 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
- ingress, err := d.getIngress(name, namespace, labels, annotations, domainSuffix, ingressClass)
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, domainSuffix, 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
- resources, err := d.getAll(name, namespace, labels, annotations, replicasInt, domainSuffix, ingressClass)
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
  }
data/lib/devfile.rb CHANGED
@@ -10,7 +10,9 @@ module Devfile
10
10
 
11
11
  class << self
12
12
  def get_deployment(devfile, name, namespace, labels, annotations, replicas)
13
- stdout, stderr, status = Open3.capture3("#{FILE_PATH} deployment '#{devfile}' #{name} #{namespace} '#{labels}' '#{annotations}' #{replicas}")
13
+ stdout, stderr, status = Open3.capture3(
14
+ "#{FILE_PATH} deployment '#{devfile}' #{name} #{namespace} '#{labels}' '#{annotations}' #{replicas}"
15
+ )
14
16
 
15
17
  raise stderr unless status.success?
16
18
 
@@ -18,24 +20,28 @@ module Devfile
18
20
  end
19
21
 
20
22
  def get_service(devfile, name, namespace, labels, annotations)
21
- stdout, stderr, status = Open3.capture3("#{FILE_PATH} service '#{devfile}' #{name} #{namespace} '#{labels}' '#{annotations}'")
23
+ stdout, stderr, status = Open3.capture3(
24
+ "#{FILE_PATH} service '#{devfile}' #{name} #{namespace} '#{labels}' '#{annotations}'"
25
+ )
22
26
 
23
27
  raise stderr unless status.success?
24
28
 
25
29
  stdout
26
30
  end
27
31
 
28
- def get_ingress(devfile, name, namespace, labels, annotations, domain_suffix, ingress_class)
29
- stdout, stderr, status = Open3.capture3("#{FILE_PATH} ingress '#{devfile}' #{name} #{namespace} '#{labels}' '#{annotations}' #{domain_suffix} #{ingress_class}")
32
+ def get_ingress(devfile, name, namespace, labels, annotations, domain_template, ingress_class)
33
+ stdout, stderr, status = Open3.capture3(
34
+ "#{FILE_PATH} ingress '#{devfile}' #{name} #{namespace} '#{labels}' '#{annotations}' #{domain_template} #{ingress_class}"
35
+ )
30
36
 
31
37
  raise stderr unless status.success?
32
38
 
33
39
  stdout
34
40
  end
35
41
 
36
- def get_all(devfile, name, namespace, labels, annotations, replicas, domain_suffix, ingress_class)
42
+ def get_all(devfile, name, namespace, labels, annotations, replicas, domain_template, ingress_class)
37
43
  stdout, stderr, status = Open3.capture3(
38
- "#{FILE_PATH} all '#{devfile}' #{name} #{namespace} '#{labels}' '#{annotations}' #{replicas} #{domain_suffix} #{ingress_class}"
44
+ "#{FILE_PATH} all '#{devfile}' #{name} #{namespace} '#{labels}' '#{annotations}' #{replicas} #{domain_template} #{ingress_class}"
39
45
  )
40
46
 
41
47
  raise stderr unless status.success?
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.4.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-08 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