From 3572c6a74a2115dc56b60d71476e305a6995a5ab Mon Sep 17 00:00:00 2001 From: scrungus Date: Tue, 3 Sep 2024 03:04:01 +0100 Subject: [PATCH] don't return error and don't convert to lowercase --- pkg/openstack/instancesv2.go | 5 +---- pkg/util/metadata/metadata.go | 2 +- pkg/util/util.go | 5 ++--- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/openstack/instancesv2.go b/pkg/openstack/instancesv2.go index 999bbd7dd4..f8a9b5e74e 100644 --- a/pkg/openstack/instancesv2.go +++ b/pkg/openstack/instancesv2.go @@ -134,10 +134,7 @@ func (i *InstancesV2) InstanceMetadata(ctx context.Context, node *v1.Node) (*clo return nil, err } - availabilityZone, err := util.SanitizeLabel(server.AvailabilityZone) - if err != nil { - return nil, err - } + availabilityZone := util.SanitizeLabel(server.AvailabilityZone) return &cloudprovider.InstanceMetadata{ ProviderID: i.makeInstanceID(&server), diff --git a/pkg/util/metadata/metadata.go b/pkg/util/metadata/metadata.go index e7cba7dddd..58076c488b 100644 --- a/pkg/util/metadata/metadata.go +++ b/pkg/util/metadata/metadata.go @@ -306,7 +306,7 @@ func (m *metadataService) GetAvailabilityZone() (string, error) { if err != nil { return "", err } - return util.SanitizeLabel(md.AvailabilityZone) + return util.SanitizeLabel(md.AvailabilityZone), nil } func CheckMetadataSearchOrder(order string) error { diff --git a/pkg/util/util.go b/pkg/util/util.go index 0c6cc90cdb..4f0986b121 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -169,7 +169,7 @@ func GetAZFromTopology(topologyKey string, requirement *csi.TopologyRequirement) return zone } -func SanitizeLabel(input string) (string, error) { +func SanitizeLabel(input string) string { // Replace non-alphanumeric characters (except '-', '_', '.') with '-' reg := regexp.MustCompile(`[^-a-zA-Z0-9_.]+`) sanitized := reg.ReplaceAllString(input, "-") @@ -182,6 +182,5 @@ func SanitizeLabel(input string) (string, error) { sanitized = sanitized[:63] } - // Convert to lowercase - return strings.ToLower(sanitized), nil + return sanitized }