2021-12-05 10:13:11 +01:00
|
|
|
package writers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"katenary/helm"
|
2022-05-08 09:55:25 +02:00
|
|
|
"log"
|
2021-12-05 10:13:11 +01:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
2022-05-08 09:55:25 +02:00
|
|
|
// BuildStorage writes the persistentVolumeClaim.
|
2021-12-05 10:13:11 +01:00
|
|
|
func BuildStorage(storage *helm.Storage, name, templatesDir string) {
|
|
|
|
kind := "pvc"
|
2022-02-16 17:40:11 +01:00
|
|
|
name = storage.Metadata.Labels[helm.K+"/component"]
|
|
|
|
pvcname := storage.Metadata.Labels[helm.K+"/pvc-name"]
|
|
|
|
fname := filepath.Join(templatesDir, name+"-"+pvcname+"."+kind+".yaml")
|
2022-05-08 09:55:25 +02:00
|
|
|
fp, err := os.Create(fname)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer fp.Close()
|
2021-12-05 10:13:11 +01:00
|
|
|
volname := storage.K8sBase.Metadata.Labels[helm.K+"/pvc-name"]
|
2022-02-16 17:40:11 +01:00
|
|
|
|
2021-12-05 10:13:11 +01:00
|
|
|
fp.WriteString("{{ if .Values." + name + ".persistence." + volname + ".enabled }}\n")
|
|
|
|
enc := yaml.NewEncoder(fp)
|
2022-02-16 10:56:21 +01:00
|
|
|
enc.SetIndent(IndentSize)
|
2022-05-08 09:55:25 +02:00
|
|
|
if err := enc.Encode(storage); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2021-12-05 10:13:11 +01:00
|
|
|
fp.WriteString("{{- end -}}")
|
|
|
|
}
|