devfile 0.0.10.pre.alpha1 → 0.0.13.pre.alpha1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9ffc2558fc821c9b249b7ca050985cf42e747093c6f1268833c75d8e0880a72
4
- data.tar.gz: 54e90aac87a83464f3dcf6e7421e8e4c12d7b671231e56d351f540d563ec10ff
3
+ metadata.gz: 794a08b4df806752813a0ab4df2561291220f1ffd1e52886688c2af7929b62ad
4
+ data.tar.gz: 21afe7859698dc11d52a0e26ec3dc24fb51749ae1ab6d2a2fc2dde1e96ac41b4
5
5
  SHA512:
6
- metadata.gz: 44296fcffbb0418ecf18534b4fc999f0fb175b29959eb1fcbb205bbd2a0b5446d7506cb6a3ae6aa3a2e23b70263dc79cb4c04101afdff2a00a3ce0ef199e73b8
7
- data.tar.gz: f3ff2153186857c6a5db7ca31151f4091a728065366d2a488b7e7fd91b2b3d609a07c881a01633cea31d05ed095325085d17086cc87cb0fb7642b490bed39391
6
+ metadata.gz: 63809486c1e80f8b5648a094409ffa2d47baa2e5837be47eb587634bb6a20e8cba49a3647faeda9a3add4082cc466955fec31a42941a36d40973d776eb2d9299
7
+ data.tar.gz: de34040a781b618c4dfa222cf5518cb77d6104b82df762ecf8bec51b72c479fcfe6d0dd2be338e920d5e1de5b71f84a27a50f02da44ff3ec5037978d173f53e0
data/bin/devfile ADDED
Binary file
data/ext/devfile.go CHANGED
@@ -1,6 +1,5 @@
1
1
  package main
2
2
 
3
- import "C"
4
3
  import (
5
4
  "bytes"
6
5
  "strconv"
@@ -12,6 +11,7 @@ import (
12
11
  appsv1 "k8s.io/api/apps/v1"
13
12
  corev1 "k8s.io/api/core/v1"
14
13
  networkingv1 "k8s.io/api/networking/v1"
14
+ "k8s.io/apimachinery/pkg/api/resource"
15
15
  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
16
  "k8s.io/apimachinery/pkg/runtime"
17
17
  "k8s.io/cli-runtime/pkg/printers"
@@ -22,6 +22,11 @@ type Devfile struct {
22
22
  devfileObj parser.DevfileObj
23
23
  }
24
24
 
25
+ type pvcOptions struct {
26
+ Name string
27
+ Size string
28
+ }
29
+
25
30
  func (d Devfile) getDeployment(name, namespace string, labels, annotations map[string]string, replicas int) (*appsv1.Deployment, error) {
26
31
  containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
27
32
  if err != nil {
@@ -31,7 +36,7 @@ func (d Devfile) getDeployment(name, namespace string, labels, annotations map[s
31
36
  if err != nil {
32
37
  return nil, err
33
38
  }
34
- volumes, err := d.getVolumesAndVolumeMounts(containers, initContainers, name)
39
+ volumes, _, err := d.getVolumesAndVolumeMounts(containers, initContainers, name)
35
40
  if err != nil {
36
41
  return nil, err
37
42
  }
@@ -146,6 +151,42 @@ func (d Devfile) getIngress(name, namespace string, labels, annotations map[stri
146
151
  return ingress, nil
147
152
  }
148
153
 
154
+ func (d Devfile) getPVC(name, namespace string, labels, annotations map[string]string) ([]*corev1.PersistentVolumeClaim, error) {
155
+ containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
156
+ if err != nil {
157
+ return nil, err
158
+ }
159
+ initContainers, err := generator.GetInitContainers(d.devfileObj)
160
+ if err != nil {
161
+ return nil, err
162
+ }
163
+ _, pvcNameToPvcOptions, err := d.getVolumesAndVolumeMounts(containers, initContainers, name)
164
+ if err != nil {
165
+ return nil, err
166
+ }
167
+
168
+ pvcs := make([]*corev1.PersistentVolumeClaim, 0)
169
+ for _, options := range pvcNameToPvcOptions {
170
+ quantity, err := resource.ParseQuantity(options.Size)
171
+ if err != nil {
172
+ return nil, err
173
+ }
174
+ pvcParams := generator.PVCParams{
175
+ TypeMeta: generator.GetTypeMeta("PersistentVolumeClaim", "v1"),
176
+ ObjectMeta: metav1.ObjectMeta{
177
+ Name: options.Name,
178
+ Namespace: namespace,
179
+ Labels: labels,
180
+ Annotations: annotations,
181
+ },
182
+ Quantity: quantity,
183
+ }
184
+ pvc := generator.GetPVC(pvcParams)
185
+ pvcs = append(pvcs, pvc)
186
+ }
187
+ return pvcs, nil
188
+ }
189
+
149
190
  func (d Devfile) getAll(name, namespace string, labels, annotations map[string]string, replicas int, domainTemplate, ingressClass string) ([]runtime.Object, error) {
150
191
 
151
192
  var result []runtime.Object
@@ -170,6 +211,14 @@ func (d Devfile) getAll(name, namespace string, labels, annotations map[string]s
170
211
  result = append(result, ingress)
171
212
  }
172
213
 
214
+ pvcs, err := d.getPVC(name, namespace, labels, annotations)
215
+ if err != nil {
216
+ return nil, err
217
+ }
218
+ for _, pvc := range pvcs {
219
+ result = append(result, pvc)
220
+ }
221
+
173
222
  return result, nil
174
223
  }
175
224
 
data/ext/go.mod CHANGED
@@ -1,4 +1,4 @@
1
- module gitlab.com/gitlab-org/incubation-engineering/server-runtime/devfilerubyffi
1
+ module gitlab-org/remote-development/devfile-gem
2
2
 
3
3
  go 1.18
4
4
 
@@ -7,6 +7,7 @@ require (
7
7
  k8s.io/api v0.26.1
8
8
  k8s.io/apimachinery v0.26.1
9
9
  k8s.io/cli-runtime v0.26.1
10
+ sigs.k8s.io/yaml v1.3.0
10
11
  )
11
12
 
12
13
  require (
@@ -115,5 +116,4 @@ require (
115
116
  sigs.k8s.io/controller-runtime v0.13.1 // indirect
116
117
  sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
117
118
  sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
118
- sigs.k8s.io/yaml v1.3.0 // indirect
119
119
  )
data/ext/main.go CHANGED
@@ -30,6 +30,8 @@ func main() {
30
30
  content, err = getService(devfile, args[3], args[4], args[5], args[6])
31
31
  case "ingress":
32
32
  content, err = getIngress(devfile, args[3], args[4], args[5], args[6], args[7], args[8])
33
+ case "pvc":
34
+ content, err = getPVC(devfile, args[3], args[4], args[5], args[6])
33
35
  case "all":
34
36
  content, err = getAll(devfile, args[3], args[4], args[5], args[6], args[7], args[8], args[9])
35
37
  case "flatten":
@@ -62,8 +64,8 @@ func getDeployment(devfile, name, namespace, labelsStr, annotationsStr, replicas
62
64
  if err != nil {
63
65
  return "", err
64
66
  }
65
- if exists == false {
66
- return "", err
67
+ if !exists {
68
+ return "", nil
67
69
  }
68
70
  labels, err := unmarshalKeyValuePair(labelsStr)
69
71
  if err != nil {
@@ -97,8 +99,8 @@ func getService(devfile, name, namespace, labelsStr, annotationsStr string) (str
97
99
  if err != nil {
98
100
  return "", err
99
101
  }
100
- if exists == false {
101
- return "", err
102
+ if !exists {
103
+ return "", nil
102
104
  }
103
105
  labels, err := unmarshalKeyValuePair(labelsStr)
104
106
  if err != nil {
@@ -128,8 +130,8 @@ func getIngress(devfile, name, namespace, labelsStr, annotationsStr, domainTempl
128
130
  if err != nil {
129
131
  return "", err
130
132
  }
131
- if exists == false {
132
- return "", err
133
+ if !exists {
134
+ return "", nil
133
135
  }
134
136
  labels, err := unmarshalKeyValuePair(labelsStr)
135
137
  if err != nil {
@@ -155,7 +157,7 @@ func getIngress(devfile, name, namespace, labelsStr, annotationsStr, domainTempl
155
157
  return content, nil
156
158
  }
157
159
 
158
- func getAll(devfile string, name, namespace, labelsStr, annotationsStr, replicas, domainTemplate, ingressClass string) (string, error) {
160
+ func getPVC(devfile, name, namespace, labelsStr, annotationsStr string) (string, error) {
159
161
  d, err := parseDevfile(devfile)
160
162
  if err != nil {
161
163
  return "", err
@@ -164,9 +166,44 @@ func getAll(devfile string, name, namespace, labelsStr, annotationsStr, replicas
164
166
  if err != nil {
165
167
  return "", err
166
168
  }
167
- if exists == false {
169
+ if !exists {
170
+ return "", nil
171
+ }
172
+ labels, err := unmarshalKeyValuePair(labelsStr)
173
+ if err != nil {
174
+ return "", err
175
+ }
176
+ annotations, err := unmarshalKeyValuePair(annotationsStr)
177
+ if err != nil {
178
+ return "", err
179
+ }
180
+ pvcs, err := d.getPVC(name, namespace, labels, annotations)
181
+ if err != nil {
182
+ return "", err
183
+ }
184
+ var result []runtime.Object
185
+ for _, pvc := range pvcs {
186
+ result = append(result, pvc)
187
+ }
188
+ content, err := marshalResources(result)
189
+ if err != nil {
190
+ return "", err
191
+ }
192
+ return content, nil
193
+ }
194
+
195
+ func getAll(devfile string, name, namespace, labelsStr, annotationsStr, replicas, domainTemplate, ingressClass string) (string, error) {
196
+ d, err := parseDevfile(devfile)
197
+ if err != nil {
198
+ return "", err
199
+ }
200
+ exists, err := d.hasContainerComponents()
201
+ if err != nil {
168
202
  return "", err
169
203
  }
204
+ if !exists {
205
+ return "", nil
206
+ }
170
207
  labels, err := unmarshalKeyValuePair(labelsStr)
171
208
  if err != nil {
172
209
  return "", err
data/ext/volume.go CHANGED
@@ -9,44 +9,47 @@ import (
9
9
  "strings"
10
10
  )
11
11
 
12
- func (d Devfile) getVolumesAndVolumeMounts(containers []corev1.Container, initContainers []corev1.Container, pvcNamePrefix string) ([]corev1.Volume, error) {
12
+ func (d Devfile) getVolumesAndVolumeMounts(containers []corev1.Container, initContainers []corev1.Container, volumeNamePrefix string) ([]corev1.Volume, map[string]pvcOptions, error) {
13
13
  containerComponents, err := d.devfileObj.Data.GetDevfileContainerComponents(common.DevfileOptions{})
14
14
  if err != nil {
15
- return nil, err
15
+ return nil, nil, err
16
16
  }
17
17
  volumeComponents, err := d.devfileObj.Data.GetDevfileVolumeComponents(common.DevfileOptions{})
18
18
  if err != nil {
19
- return nil, err
19
+ return nil, nil, err
20
20
  }
21
21
 
22
22
  var volumes []corev1.Volume
23
+ pvcNameToPvcOptions := map[string]pvcOptions{}
23
24
  for _, volumeComponent := range volumeComponents {
24
- volName := volumeComponent.Name
25
+ volumeName := fmt.Sprintf("%s-%s", volumeNamePrefix, volumeComponent.Name)
25
26
  if bool(*volumeComponent.Volume.Ephemeral) == true {
26
- emptyDir, err := getEmptyDir(volName, volumeComponent.Volume.Size)
27
+ emptyDir, err := getEmptyDir(volumeName, volumeComponent.Volume.Size)
27
28
  if err != nil {
28
- return nil, err
29
+ return nil, nil, err
29
30
  }
30
31
  volumes = append(volumes, emptyDir)
31
32
  } else {
32
- // TODO: figure this out; how should we pass PVC name? should the object be generated here?
33
- pvcName := fmt.Sprintf("%s-%s", pvcNamePrefix, volName)
34
- volumes = append(volumes, getPVC(volName, pvcName))
33
+ volumes = append(volumes, getPersistentVolumeClaim(volumeName, volumeName))
34
+ pvcNameToPvcOptions[volumeComponent.Name] = pvcOptions{
35
+ Name: volumeName,
36
+ Size: volumeComponent.Volume.Size,
37
+ }
35
38
  }
36
39
  // containerNameToMountPaths is a map of the Devfile container name to their Devfile Volume Mount Paths for a given Volume Name
37
40
  containerNameToMountPaths := make(map[string][]string)
38
41
  for _, containerComp := range containerComponents {
39
42
  for _, volumeMount := range containerComp.Container.VolumeMounts {
40
- if volName == volumeMount.Name {
43
+ if volumeComponent.Name == volumeMount.Name {
41
44
  containerNameToMountPaths[containerComp.Name] = append(containerNameToMountPaths[containerComp.Name], generator.GetVolumeMountPath(volumeMount))
42
45
  }
43
46
  }
44
47
  }
45
48
 
46
- addVolumeMountToContainers(containers, initContainers, volName, containerNameToMountPaths)
49
+ addVolumeMountToContainers(containers, initContainers, volumeName, containerNameToMountPaths)
47
50
  }
48
51
 
49
- return volumes, nil
52
+ return volumes, pvcNameToPvcOptions, nil
50
53
  }
51
54
 
52
55
  // addVolumeMountToContainers adds the Volume Mounts in containerNameToMountPaths to the containers for a given pvc and volumeName
@@ -82,8 +85,8 @@ func addVolumeMountToContainers(containers []corev1.Container, initContainers []
82
85
  }
83
86
  }
84
87
 
85
- // getPVC gets a pvc type volume with the given volume name and pvc name.
86
- func getPVC(volumeName, pvcName string) corev1.Volume {
88
+ // getPersistentVolumeClaim gets a pvc type volume with the given volume name and pvc name.
89
+ func getPersistentVolumeClaim(volumeName, pvcName string) corev1.Volume {
87
90
 
88
91
  return corev1.Volume{
89
92
  Name: volumeName,
data/lib/devfile.rb CHANGED
@@ -39,6 +39,16 @@ module Devfile
39
39
  stdout
40
40
  end
41
41
 
42
+ def get_pvc(devfile, name, namespace, labels, annotations)
43
+ stdout, stderr, status = Open3.capture3(
44
+ "#{FILE_PATH} deployment '#{devfile}' #{name} #{namespace} '#{labels}' '#{annotations}'"
45
+ )
46
+
47
+ raise stderr unless status.success?
48
+
49
+ stdout
50
+ end
51
+
42
52
  def get_all(devfile, name, namespace, labels, annotations, replicas, domain_template, ingress_class)
43
53
  stdout, stderr, status = Open3.capture3(
44
54
  "#{FILE_PATH} all '#{devfile}' #{name} #{namespace} '#{labels}' '#{annotations}' #{replicas} #{domain_template} #{ingress_class}"
metadata CHANGED
@@ -1,23 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10.pre.alpha1
4
+ version: 0.0.13.pre.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-19 00:00:00.000000000 Z
11
+ date: 2023-04-26 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
- extensions:
17
- - "./ext/extconf.rb"
19
+ extensions: []
18
20
  extra_rdoc_files: []
19
21
  files:
20
- - "./ext/extconf.rb"
22
+ - bin/devfile
21
23
  - ext/devfile.go
22
24
  - ext/go.mod
23
25
  - ext/go.sum
@@ -44,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
46
  - !ruby/object:Gem::Version
45
47
  version: 1.3.1
46
48
  requirements: []
47
- rubygems_version: 3.4.8
49
+ rubygems_version: 3.4.9
48
50
  signing_key:
49
51
  specification_version: 4
50
52
  summary: Parse and generate kubernetes manifests from a Devfile
data/ext/extconf.rb DELETED
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- makefile_contents = "all:\n\techo \"Starting...\"\n\ninstall:\n\tmkdir -p ../bin && go build -o ../bin/devfile ./...\n\n"
4
-
5
- File.write('Makefile', makefile_contents)