...
1 package storage
2
3 import (
4 devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
5 "github.com/devfile/library/v2/pkg/devfile/generator"
6 "github.com/devfile/library/v2/pkg/devfile/parser"
7 "github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
8 )
9
10 const (
11
12 DefaultVolumeSize = "1Gi"
13 )
14
15
16 type LocalStorage struct {
17
18 Name string `yaml:"Name,omitempty"`
19
20 Size string `yaml:"Size,omitempty"`
21
22 Ephemeral *bool `yaml:"Ephemeral,omitempty"`
23
24 Path string `yaml:"Path,omitempty"`
25
26 Container string `yaml:"-" json:"-"`
27 }
28
29
30 func ListStorage(devfileObj parser.DevfileObj) ([]LocalStorage, error) {
31 var storageList []LocalStorage
32
33 volumeMap := make(map[string]devfilev1.Volume)
34 components, err := devfileObj.Data.GetComponents(common.DevfileOptions{})
35 if err != nil {
36 return storageList, err
37 }
38
39 for _, component := range components {
40 if component.Volume == nil {
41 continue
42 }
43 if component.Volume.Size == "" {
44 component.Volume.Size = DefaultVolumeSize
45 }
46 volumeMap[component.Name] = component.Volume.Volume
47 }
48
49 for _, component := range components {
50 if component.Container == nil {
51 continue
52 }
53 for _, volumeMount := range component.Container.VolumeMounts {
54 vol, ok := volumeMap[volumeMount.Name]
55 if ok {
56 storageList = append(storageList, LocalStorage{
57 Name: volumeMount.Name,
58 Size: vol.Size,
59 Ephemeral: vol.Ephemeral,
60 Path: generator.GetVolumeMountPath(volumeMount),
61 Container: component.Name,
62 })
63 }
64 }
65 }
66
67 return storageList, nil
68 }
69
View as plain text