Skip to content

Commit

Permalink
Fix for region fetch from GetAWSRegion()
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Dec 3, 2024
1 parent 2bca4d8 commit b3b1b9c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
nbapis "github.com/noobaa/noobaa-operator/v5/pkg/apis"
nbv1 "github.com/noobaa/noobaa-operator/v5/pkg/apis/noobaa/v1alpha1"
"github.com/noobaa/noobaa-operator/v5/pkg/bundle"
configv1 "github.com/openshift/api/config/v1"
routev1 "github.com/openshift/api/route/v1"
secv1 "github.com/openshift/api/security/v1"
cloudcredsv1 "github.com/openshift/cloud-credential-operator/pkg/apis/cloudcredential/v1"
Expand Down Expand Up @@ -185,6 +186,7 @@ func init() {
Panic(autoscalingv1.AddToScheme(scheme.Scheme))
Panic(kedav1alpha1.AddToScheme(scheme.Scheme))
Panic(apiregistration.AddToScheme(scheme.Scheme))
Panic(configv1.AddToScheme(scheme.Scheme))
}

// KubeConfig loads kubernetes client config from default locations (flags, user dir, etc)
Expand Down Expand Up @@ -1164,15 +1166,16 @@ func GetAWSRegion() (string, error) {
"af-south-1": "af-south-1",
"il-central-1": "il-central-1",
}
nodesList := &corev1.NodeList{}
if ok := KubeList(nodesList); !ok || len(nodesList.Items) == 0 {
return "", fmt.Errorf("Failed to list kubernetes nodes")
infrastructure := &configv1.Infrastructure{}
infrastructure.SetName("cluster")
if _, _, err := KubeGet(infrastructure); err != nil {
return "", fmt.Errorf("failed to fetch cluster infrastructure details: %w", err)
}
nameSplit := strings.Split(nodesList.Items[0].Name, ".")
if len(nameSplit) < 2 {
return "", fmt.Errorf("Unexpected node name format: %q", nodesList.Items[0].Name)

var awsRegion string
if infrastructure.Status.PlatformStatus != nil && infrastructure.Status.PlatformStatus.AWS != nil {
awsRegion = mapValidAWSRegions[infrastructure.Status.PlatformStatus.AWS.Region]
}
awsRegion := mapValidAWSRegions[nameSplit[1]]
if awsRegion == "" {
return "", fmt.Errorf("The parsed AWS region is invalid: %q", awsRegion)
}
Expand Down

0 comments on commit b3b1b9c

Please sign in to comment.