Skip to content

Commit

Permalink
use a map instead of a slice
Browse files Browse the repository at this point in the history
  • Loading branch information
yithian committed Sep 17, 2024
1 parent fff757b commit 5ed140e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/api/v20240812preview/openshiftcluster_validatestatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net"
"net/http"
"net/url"
"slices"
"strings"

azcorearm "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
Expand Down Expand Up @@ -480,7 +479,7 @@ func (sv openShiftClusterStaticValidator) validatePlatformWorkloadIdentityProfil
}

// collect operator names to check for duplicates
operatorNames := []string{}
operators := map[string]struct{}{}

// Validate the PlatformWorkloadIdentities
for n, p := range pwip.PlatformWorkloadIdentities {
Expand All @@ -493,10 +492,10 @@ func (sv openShiftClusterStaticValidator) validatePlatformWorkloadIdentityProfil
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, fmt.Sprintf("%s.PlatformWorkloadIdentities[%d].resourceID", path, n), "Operator name is empty.")
}

if slices.Contains(operatorNames, p.OperatorName) {
if _, found := operators[p.OperatorName]; found {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, fmt.Sprintf("%s.platformWorkloadIdentities", path), "Operator identities cannot have duplicate names.")
}
operatorNames = append(operatorNames, p.OperatorName)
operators[p.OperatorName] = struct{}{}

if resource.ResourceType.Type != "userAssignedIdentities" {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, fmt.Sprintf("%s.PlatformWorkloadIdentities[%d].resourceID", path, n), "Resource must be a user assigned identity.")
Expand Down

0 comments on commit 5ed140e

Please sign in to comment.