From 3b51f41716a4e99d736cd16f380bc0a597da9ca9 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Thu, 21 Nov 2024 11:12:38 +0100 Subject: [PATCH] chore(names): Fix resource name Use an utility function to fix some names --- generator/generator.go | 2 +- utils/utils.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/generator/generator.go b/generator/generator.go index 0ba4746..75b1831 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -273,7 +273,7 @@ func buildVolumes(service types.ServiceConfig, chart *HelmChart, deployments map } switch v.Type { case "volume": - v.Source = strings.ReplaceAll(v.Source, "-", "_") + v.Source = utils.AsResourceName(v.Source) pvc := NewVolumeClaim(service, v.Source, appName) // if the service is integrated in another deployment, we need to add the volume diff --git a/utils/utils.go b/utils/utils.go index 0e2e196..1c75e58 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -198,3 +198,9 @@ func EncodeBasicYaml(data any) ([]byte, error) { func FixedResourceName(name string) string { return strings.ReplaceAll(name, "_", "-") } + +// AsResourceName returns a resource name with underscores to respect the kubernetes naming convention. +// It's the opposite of FixedResourceName. +func AsResourceName(name string) string { + return strings.ReplaceAll(name, "-", "_") +}