diff --git a/internal/pkg/resource_name_utils/resource_name_utils.go b/internal/pkg/resource_name_utils/resource_name_utils.go index cd263428..800a95c0 100644 --- a/internal/pkg/resource_name_utils/resource_name_utils.go +++ b/internal/pkg/resource_name_utils/resource_name_utils.go @@ -3,6 +3,7 @@ package resource_name_utils import ( "fmt" "regexp" + "strings" ) type ResouceNameUtils struct{} @@ -43,8 +44,12 @@ func (resouceNameUtils *ResouceNameUtils) VolumeName(name string) string { return fmt.Sprintf("volume-%v", rfcName) } +// A lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', +// and must start and end with an alphanumeric character (e.g. 'example.com', +// regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*') func toRfc(str string) string { regexp := regexp.MustCompile(`(\/|~|\.|_)`) + replacedStr := regexp.ReplaceAllString(str, "-") - return regexp.ReplaceAllString(str, "-") + return strings.Trim(replacedStr, "-") } diff --git a/internal/types/domain/container_volume.go b/internal/types/domain/container_volume.go index 1a2c848c..73406646 100644 --- a/internal/types/domain/container_volume.go +++ b/internal/types/domain/container_volume.go @@ -24,7 +24,7 @@ func (volume ContainerVolume) BuildUniqName(container *Container) string { case ContainerVolumeTypeNamed: return volume.Source case ContainerVolumeTypeHost: - return fmt.Sprintf("host-%s-%s", container.ServiceName, volume.Source) + return fmt.Sprintf("host-%s", volume.Source) default: return "" }