devfile 0.0.12.pre.alpha1-arm64-darwin → 0.0.13.pre.alpha1-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/devfile +0 -0
- data/ext/devfile.go +25 -74
- data/ext/volume.go +117 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e655c5b49b095dd4cb57fec39ee88b65de58373c5807cfd4c690412b3f0ae76
|
4
|
+
data.tar.gz: 86a3fd022d2a7457d7f7d90ab23683bf7135e7f7682b7a97119605b279bc04d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eeb0faf58cb8adc029653c74e17257e15970fe7eb8e989341e91ba22335f80d182042443ec3add21e9712eccdbd1b45a235a507dc09cd3ff54be930ad625049
|
7
|
+
data.tar.gz: cc1628f1a5458f23b88c8786acb27dcdce42a1d18b3cf841b0aca6c8d9cebe3ae64648ebac9372f345cc8fc52bc913746180195f8fdb5299aefa2f3599ddc291
|
data/bin/devfile
CHANGED
Binary file
|
data/ext/devfile.go
CHANGED
@@ -2,8 +2,6 @@ package main
|
|
2
2
|
|
3
3
|
import (
|
4
4
|
"bytes"
|
5
|
-
"fmt"
|
6
|
-
"sort"
|
7
5
|
"strconv"
|
8
6
|
"text/template"
|
9
7
|
|
@@ -24,14 +22,21 @@ type Devfile struct {
|
|
24
22
|
devfileObj parser.DevfileObj
|
25
23
|
}
|
26
24
|
|
27
|
-
type
|
28
|
-
|
29
|
-
Size
|
30
|
-
IsEphemeral bool
|
25
|
+
type pvcOptions struct {
|
26
|
+
Name string
|
27
|
+
Size string
|
31
28
|
}
|
32
29
|
|
33
30
|
func (d Devfile) getDeployment(name, namespace string, labels, annotations map[string]string, replicas int) (*appsv1.Deployment, error) {
|
34
|
-
containers,
|
31
|
+
containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
|
32
|
+
if err != nil {
|
33
|
+
return nil, err
|
34
|
+
}
|
35
|
+
initContainers, err := generator.GetInitContainers(d.devfileObj)
|
36
|
+
if err != nil {
|
37
|
+
return nil, err
|
38
|
+
}
|
39
|
+
volumes, _, err := d.getVolumesAndVolumeMounts(containers, initContainers, name)
|
35
40
|
if err != nil {
|
36
41
|
return nil, err
|
37
42
|
}
|
@@ -147,24 +152,29 @@ func (d Devfile) getIngress(name, namespace string, labels, annotations map[stri
|
|
147
152
|
}
|
148
153
|
|
149
154
|
func (d Devfile) getPVC(name, namespace string, labels, annotations map[string]string) ([]*corev1.PersistentVolumeClaim, error) {
|
150
|
-
|
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)
|
151
164
|
if err != nil {
|
152
165
|
return nil, err
|
153
166
|
}
|
167
|
+
|
154
168
|
pvcs := make([]*corev1.PersistentVolumeClaim, 0)
|
155
|
-
for _,
|
156
|
-
|
157
|
-
if volumeOptions.IsEphemeral {
|
158
|
-
continue
|
159
|
-
}
|
160
|
-
quantity, err := resource.ParseQuantity(volumeOptions.Size)
|
169
|
+
for _, options := range pvcNameToPvcOptions {
|
170
|
+
quantity, err := resource.ParseQuantity(options.Size)
|
161
171
|
if err != nil {
|
162
172
|
return nil, err
|
163
173
|
}
|
164
174
|
pvcParams := generator.PVCParams{
|
165
175
|
TypeMeta: generator.GetTypeMeta("PersistentVolumeClaim", "v1"),
|
166
176
|
ObjectMeta: metav1.ObjectMeta{
|
167
|
-
Name:
|
177
|
+
Name: options.Name,
|
168
178
|
Namespace: namespace,
|
169
179
|
Labels: labels,
|
170
180
|
Annotations: annotations,
|
@@ -212,65 +222,6 @@ func (d Devfile) getAll(name, namespace string, labels, annotations map[string]s
|
|
212
222
|
return result, nil
|
213
223
|
}
|
214
224
|
|
215
|
-
func (d Devfile) getContainersAndVolumes(name string) ([]corev1.Container, []corev1.Container, []corev1.Volume, map[string]volumeOptions, error) {
|
216
|
-
containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
|
217
|
-
if err != nil {
|
218
|
-
return nil, nil, nil, nil, err
|
219
|
-
}
|
220
|
-
initContainers, err := generator.GetInitContainers(d.devfileObj)
|
221
|
-
if err != nil {
|
222
|
-
return nil, nil, nil, nil, err
|
223
|
-
}
|
224
|
-
allContainers := append(containers, initContainers...)
|
225
|
-
|
226
|
-
volumeComponents, err := d.devfileObj.Data.GetDevfileVolumeComponents(common.DevfileOptions{})
|
227
|
-
if err != nil {
|
228
|
-
return nil, nil, nil, nil, err
|
229
|
-
}
|
230
|
-
volumeNameToVolumeOptions := map[string]volumeOptions{}
|
231
|
-
volumeNameToVolumeInfo := map[string]generator.VolumeInfo{}
|
232
|
-
for _, volumeComponent := range volumeComponents {
|
233
|
-
info := generator.VolumeInfo{
|
234
|
-
PVCName: fmt.Sprintf("%s-%s", name, volumeComponent.Name),
|
235
|
-
VolumeName: volumeComponent.Name,
|
236
|
-
}
|
237
|
-
volumeNameToVolumeInfo[volumeComponent.Name] = info
|
238
|
-
volumeNameToVolumeOptions[volumeComponent.Name] = volumeOptions{
|
239
|
-
Info: info,
|
240
|
-
Size: volumeComponent.Volume.Size,
|
241
|
-
IsEphemeral: *volumeComponent.Volume.Ephemeral,
|
242
|
-
}
|
243
|
-
}
|
244
|
-
|
245
|
-
volumeParams := generator.VolumeParams{
|
246
|
-
Containers: allContainers,
|
247
|
-
VolumeNameToVolumeInfo: volumeNameToVolumeInfo,
|
248
|
-
}
|
249
|
-
options := common.DevfileOptions{}
|
250
|
-
// "containers" and "initContainers" are updated in place with the volume mounts parameters
|
251
|
-
// after the following function is called
|
252
|
-
volumes, err := generator.GetVolumesAndVolumeMounts(d.devfileObj, volumeParams, options)
|
253
|
-
if err != nil {
|
254
|
-
return nil, nil, nil, nil, err
|
255
|
-
}
|
256
|
-
// sort all volumes and volume mounts in the containers and initContainers
|
257
|
-
// to keep the array order deterministic
|
258
|
-
sort.SliceStable(volumes, func(i, j int) bool {
|
259
|
-
return volumes[i].Name < volumes[j].Name
|
260
|
-
})
|
261
|
-
for _, container := range containers {
|
262
|
-
sort.SliceStable(container.VolumeMounts, func(i, j int) bool {
|
263
|
-
return container.VolumeMounts[i].Name < container.VolumeMounts[j].Name
|
264
|
-
})
|
265
|
-
}
|
266
|
-
for _, initContainer := range initContainers {
|
267
|
-
sort.SliceStable(initContainer.VolumeMounts, func(i, j int) bool {
|
268
|
-
return initContainer.VolumeMounts[i].Name < initContainer.VolumeMounts[j].Name
|
269
|
-
})
|
270
|
-
}
|
271
|
-
return containers, initContainers, volumes, volumeNameToVolumeOptions, nil
|
272
|
-
}
|
273
|
-
|
274
225
|
func (d Devfile) hasContainerComponents() (bool, error) {
|
275
226
|
containers, err := generator.GetContainers(d.devfileObj, common.DevfileOptions{})
|
276
227
|
if err != nil {
|
data/ext/volume.go
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
package main
|
2
|
+
|
3
|
+
import (
|
4
|
+
"fmt"
|
5
|
+
"github.com/devfile/library/v2/pkg/devfile/generator"
|
6
|
+
"github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
|
7
|
+
corev1 "k8s.io/api/core/v1"
|
8
|
+
"k8s.io/apimachinery/pkg/api/resource"
|
9
|
+
"strings"
|
10
|
+
)
|
11
|
+
|
12
|
+
func (d Devfile) getVolumesAndVolumeMounts(containers []corev1.Container, initContainers []corev1.Container, volumeNamePrefix string) ([]corev1.Volume, map[string]pvcOptions, error) {
|
13
|
+
containerComponents, err := d.devfileObj.Data.GetDevfileContainerComponents(common.DevfileOptions{})
|
14
|
+
if err != nil {
|
15
|
+
return nil, nil, err
|
16
|
+
}
|
17
|
+
volumeComponents, err := d.devfileObj.Data.GetDevfileVolumeComponents(common.DevfileOptions{})
|
18
|
+
if err != nil {
|
19
|
+
return nil, nil, err
|
20
|
+
}
|
21
|
+
|
22
|
+
var volumes []corev1.Volume
|
23
|
+
pvcNameToPvcOptions := map[string]pvcOptions{}
|
24
|
+
for _, volumeComponent := range volumeComponents {
|
25
|
+
volumeName := fmt.Sprintf("%s-%s", volumeNamePrefix, volumeComponent.Name)
|
26
|
+
if bool(*volumeComponent.Volume.Ephemeral) == true {
|
27
|
+
emptyDir, err := getEmptyDir(volumeName, volumeComponent.Volume.Size)
|
28
|
+
if err != nil {
|
29
|
+
return nil, nil, err
|
30
|
+
}
|
31
|
+
volumes = append(volumes, emptyDir)
|
32
|
+
} else {
|
33
|
+
volumes = append(volumes, getPersistentVolumeClaim(volumeName, volumeName))
|
34
|
+
pvcNameToPvcOptions[volumeComponent.Name] = pvcOptions{
|
35
|
+
Name: volumeName,
|
36
|
+
Size: volumeComponent.Volume.Size,
|
37
|
+
}
|
38
|
+
}
|
39
|
+
// containerNameToMountPaths is a map of the Devfile container name to their Devfile Volume Mount Paths for a given Volume Name
|
40
|
+
containerNameToMountPaths := make(map[string][]string)
|
41
|
+
for _, containerComp := range containerComponents {
|
42
|
+
for _, volumeMount := range containerComp.Container.VolumeMounts {
|
43
|
+
if volumeComponent.Name == volumeMount.Name {
|
44
|
+
containerNameToMountPaths[containerComp.Name] = append(containerNameToMountPaths[containerComp.Name], generator.GetVolumeMountPath(volumeMount))
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
addVolumeMountToContainers(containers, initContainers, volumeName, containerNameToMountPaths)
|
50
|
+
}
|
51
|
+
|
52
|
+
return volumes, pvcNameToPvcOptions, nil
|
53
|
+
}
|
54
|
+
|
55
|
+
// addVolumeMountToContainers adds the Volume Mounts in containerNameToMountPaths to the containers for a given pvc and volumeName
|
56
|
+
// containerNameToMountPaths is a map of a container name to an array of its Mount Paths.
|
57
|
+
// To be moved to devfile/library.
|
58
|
+
func addVolumeMountToContainers(containers []corev1.Container, initContainers []corev1.Container, volumeName string, containerNameToMountPaths map[string][]string) {
|
59
|
+
|
60
|
+
for containerName, mountPaths := range containerNameToMountPaths {
|
61
|
+
for i := range containers {
|
62
|
+
if containers[i].Name == containerName {
|
63
|
+
for _, mountPath := range mountPaths {
|
64
|
+
containers[i].VolumeMounts = append(containers[i].VolumeMounts, corev1.VolumeMount{
|
65
|
+
Name: volumeName,
|
66
|
+
MountPath: mountPath,
|
67
|
+
SubPath: "",
|
68
|
+
},
|
69
|
+
)
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
for i := range initContainers {
|
74
|
+
if strings.HasPrefix(initContainers[i].Name, containerName) {
|
75
|
+
for _, mountPath := range mountPaths {
|
76
|
+
initContainers[i].VolumeMounts = append(initContainers[i].VolumeMounts, corev1.VolumeMount{
|
77
|
+
Name: volumeName,
|
78
|
+
MountPath: mountPath,
|
79
|
+
SubPath: "",
|
80
|
+
},
|
81
|
+
)
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
// getPersistentVolumeClaim gets a pvc type volume with the given volume name and pvc name.
|
89
|
+
func getPersistentVolumeClaim(volumeName, pvcName string) corev1.Volume {
|
90
|
+
|
91
|
+
return corev1.Volume{
|
92
|
+
Name: volumeName,
|
93
|
+
VolumeSource: corev1.VolumeSource{
|
94
|
+
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
|
95
|
+
ClaimName: pvcName,
|
96
|
+
},
|
97
|
+
},
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
// getEmptyDir gets an emptyDir type volume with the given volume name and size.
|
102
|
+
// size should be parseable as a Kubernetes `Quantity` or an error will be returned
|
103
|
+
func getEmptyDir(volumeName string, size string) (corev1.Volume, error) {
|
104
|
+
|
105
|
+
emptyDir := &corev1.EmptyDirVolumeSource{}
|
106
|
+
qty, err := resource.ParseQuantity(size)
|
107
|
+
if err != nil {
|
108
|
+
return corev1.Volume{}, err
|
109
|
+
}
|
110
|
+
emptyDir.SizeLimit = &qty
|
111
|
+
return corev1.Volume{
|
112
|
+
Name: volumeName,
|
113
|
+
VolumeSource: corev1.VolumeSource{
|
114
|
+
EmptyDir: emptyDir,
|
115
|
+
},
|
116
|
+
}, nil
|
117
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13.pre.alpha1
|
5
5
|
platform: arm64-darwin
|
6
6
|
authors:
|
7
7
|
- GitLab
|
@@ -24,6 +24,7 @@ files:
|
|
24
24
|
- ext/go.mod
|
25
25
|
- ext/go.sum
|
26
26
|
- ext/main.go
|
27
|
+
- ext/volume.go
|
27
28
|
- lib/devfile.rb
|
28
29
|
homepage: https://gitlab.com
|
29
30
|
licenses:
|