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 c39f14b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
8 changes: 8 additions & 0 deletions deploy/cluster_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,11 @@ rules:
- delete
- update
- create
- apiGroups:
- config.openshift.io
resources:
- infrastructures
verbs:
- get
- list
- watch
10 changes: 9 additions & 1 deletion pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package bundle

const Version = "5.18.0"

const Sha256_deploy_cluster_role_yaml = "3f8118853db73926c4f9d14be84ac8f81833c3a7a94a52ecf1e9ebcf712eee93"
const Sha256_deploy_cluster_role_yaml = "31fc622ff7fa66617be3895bddcb6cfdb97883b75b20bdb2bf04052bd14221a8"

const File_deploy_cluster_role_yaml = `apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down Expand Up @@ -189,6 +189,14 @@ rules:
- delete
- update
- create
- apiGroups:
- config.openshift.io
resources:
- infrastructures
verbs:
- get
- list
- watch
`

const Sha256_deploy_cluster_role_binding_yaml = "15c78355aefdceaf577bd96b4ae949ae424a3febdc8853be0917cf89a63941fc"
Expand Down
18 changes: 18 additions & 0 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 @@ -236,6 +238,7 @@ func MapperProvider(config *rest.Config, httpClient *http.Client) (meta.RESTMapp
g.Name == "autoscaling" ||
g.Name == "batch" ||
g.Name == "keda.sh" ||
g.Name == "config.openshift.io" ||
strings.HasSuffix(g.Name, ".k8s.io") {
return true
}
Expand Down Expand Up @@ -1173,6 +1176,21 @@ func GetAWSRegion() (string, error) {
return "", fmt.Errorf("Unexpected node name format: %q", nodesList.Items[0].Name)
}
awsRegion := mapValidAWSRegions[nameSplit[1]]

// Fetching aws region from cluster if not fetched from node name
if awsRegion == "" {
infrastructure := &configv1.Infrastructure{}
infrastructure.SetName("cluster")
if _, _, err := KubeGet(infrastructure); err != nil {
return "", fmt.Errorf("failed to fetch cluster infrastructure details: %w", err)
}

if infrastructure.Status.PlatformStatus != nil && infrastructure.Status.PlatformStatus.AWS != nil {
awsRegion = mapValidAWSRegions[infrastructure.Status.PlatformStatus.AWS.Region]
}
}

// returning error if not fetched from either node name or cluster
if awsRegion == "" {
return "", fmt.Errorf("The parsed AWS region is invalid: %q", awsRegion)
}
Expand Down

0 comments on commit c39f14b

Please sign in to comment.