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

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: 1791e8e7ff6b1f3de970040c705db46fef04cfb524b95f1e0a41d57f97e6d61d
4
- data.tar.gz: 26ede5ee22624b25fa8142879703a1c80b0fd78bf7e6598da89eec1c4310afbe
3
+ metadata.gz: 2828c04bd596361245d3c284bc14a54c665480503bee24306bd05c112a7eead5
4
+ data.tar.gz: fbcc19449ed34019693d5ef30d4f5499cf36b90e6f0f96fd48439e234873cde3
5
5
  SHA512:
6
- metadata.gz: cfba06a846d7ec1a8c18b51cf86d4ff1c96af5ccef21df42e21ddfe0004bcbefabc4fde89c86c67077c1769b44a0a3d4ef7cd237278324b6c26090d8fd2e3b8d
7
- data.tar.gz: de8183ccfddadb4e3e59a21df545cedcd2b59967c3be488bccf93e8882c37e8e3bc728dbb670dbc62e15460b9f7bfa35ac517acb89421ea24569dcf140a21e19
6
+ metadata.gz: bdb5fb6df7de30d29c351b584746ca0fd149054a43162d9c9cadae5fd0bb577f694c0fb72b3d19512889282af121d75b80e3ac94ec9a6e6e46febff7eb6c04b3
7
+ data.tar.gz: '04308c3afdf61e819014e6d63e9e0460a7e6a402d9c9f271a79b54132aa27ea77ae17182aa9ad691cd08a01b5b1c25c6e7a2b3dcd3c3ed211263f6c6747035f1'
data/bin/devfile CHANGED
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,17 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11.pre.alpha1
4
+ version: 0.0.13.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-20 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
19
  extensions: []
17
20
  extra_rdoc_files: []