2021-11-30 17:29:42 +01:00
|
|
|
package helm
|
|
|
|
|
2022-05-06 13:42:53 +02:00
|
|
|
import "sync"
|
|
|
|
|
|
|
|
var (
|
|
|
|
made = make(map[string]bool)
|
|
|
|
locker = sync.Mutex{}
|
|
|
|
)
|
|
|
|
|
|
|
|
// ResetMadePVC resets the cache of made PVCs.
|
|
|
|
// Useful in tests only.
|
|
|
|
func ResetMadePVC() {
|
|
|
|
locker.Lock()
|
|
|
|
defer locker.Unlock()
|
|
|
|
made = make(map[string]bool)
|
|
|
|
}
|
|
|
|
|
2022-05-05 09:43:52 +02:00
|
|
|
// Storage is a struct for a PersistentVolumeClaim.
|
2021-11-30 17:29:42 +01:00
|
|
|
type Storage struct {
|
|
|
|
*K8sBase `yaml:",inline"`
|
|
|
|
Spec *PVCSpec
|
|
|
|
}
|
|
|
|
|
2022-05-05 09:43:52 +02:00
|
|
|
// NewPVC creates a new PersistentVolumeClaim object.
|
2021-11-30 17:29:42 +01:00
|
|
|
func NewPVC(name, storageName string) *Storage {
|
2022-05-06 13:42:53 +02:00
|
|
|
locker.Lock()
|
|
|
|
defer locker.Unlock()
|
|
|
|
if _, ok := made[name+storageName]; ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
made[name+storageName] = true
|
2021-11-30 17:29:42 +01:00
|
|
|
pvc := &Storage{}
|
|
|
|
pvc.K8sBase = NewBase()
|
|
|
|
pvc.K8sBase.Kind = "PersistentVolumeClaim"
|
|
|
|
pvc.K8sBase.Metadata.Labels[K+"/pvc-name"] = storageName
|
|
|
|
pvc.K8sBase.ApiVersion = "v1"
|
2022-05-05 11:33:02 +02:00
|
|
|
pvc.K8sBase.Metadata.Name = ReleaseNameTpl + "-" + storageName
|
2021-12-01 15:17:34 +01:00
|
|
|
pvc.K8sBase.Metadata.Labels[K+"/component"] = name
|
2021-11-30 17:29:42 +01:00
|
|
|
pvc.Spec = &PVCSpec{
|
|
|
|
Resouces: map[string]interface{}{
|
|
|
|
"requests": map[string]string{
|
2021-12-01 16:50:32 +01:00
|
|
|
"storage": "{{ .Values." + name + ".persistence." + storageName + ".capacity }}",
|
2021-11-30 17:29:42 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
AccessModes: []string{"ReadWriteOnce"},
|
|
|
|
}
|
|
|
|
return pvc
|
|
|
|
}
|
|
|
|
|
2022-05-05 09:43:52 +02:00
|
|
|
// PVCSpec is a struct for a PersistentVolumeClaim spec.
|
2021-11-30 17:29:42 +01:00
|
|
|
type PVCSpec struct {
|
|
|
|
Resouces map[string]interface{} `yaml:"resources"`
|
|
|
|
AccessModes []string `yaml:"accessModes"`
|
|
|
|
}
|