Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Jaswal <[email protected]>
  • Loading branch information
jaswalkiranavtar committed Jan 17, 2025
1 parent 942f19b commit 6132fc7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ metadata:
{{ if .ManagedClusterIdentityCreatorRole }}
annotations:
eks.amazonaws.com/role-arn: {{ .ManagedClusterIdentityCreatorRole }}
{{end}}
{{ else }}
annotations:
eks.amazonaws.com/role-arn-: ""
{{end}}
6 changes: 6 additions & 0 deletions pkg/common/helpers/parser.go → pkg/common/helpers/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ package helpers

import "strings"

// GetAwsAccountIdAndClusterName Parses aws accountId and cluster-name from clusterArn
// e.g. if clusterArn is arn:aws:eks:us-west-2:123456789012:cluster/hub-cluster1
// accountId is 123456789012 and clusterName is hub-cluster1
func GetAwsAccountIdAndClusterName(clusterArn string) (string, string) {
clusterStringParts := strings.Split(clusterArn, ":")
clusterName := strings.Split(clusterStringParts[5], "/")[1]
awsAccountId := clusterStringParts[4]
return awsAccountId, clusterName
}

// GetAwsRegion Parses aws accountId and cluster-name from clusterArn
// e.g. if clusterArn is arn:aws:eks:us-west-2:123456789012:cluster/hub-cluster1
// awsRegion is us-west-2
func GetAwsRegion(clusterArn string) string {
clusterStringParts := strings.Split(clusterArn, ":")
return clusterStringParts[3]
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions test/integration/operator/clustermanager_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ var _ = ginkgo.Describe("ClusterManager Default Mode with aws registration", fun
return false
}
annotation := registrationControllerSA.Annotations["eks.amazonaws.com/role-arn"]

// The same cluster-manager CR is used for other tests.
// Hence updating it here, so that annotation is removed for other test testing with csr or empty registration
clusterManager, err := operatorClient.OperatorV1().ClusterManagers().Get(context.Background(), clusterManagerName, metav1.GetOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
clusterManager.Spec.RegistrationConfiguration = nil
_, err = operatorClient.OperatorV1().ClusterManagers().Update(context.Background(), clusterManager, metav1.UpdateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())

return annotation == "arn:aws:iam::123456789012:role/hub-cluster_managed-cluster-identity-creator"
}, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue())

Expand Down

0 comments on commit 6132fc7

Please sign in to comment.