-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Assume prerequisite role on hub if initailize with aws-irsa (#807)
* Adding managedcluster identity creator role arn Signed-off-by: Gaurav Jaswal <[email protected]> * Addressing review comments Signed-off-by: Gaurav Jaswal <[email protected]> --------- Signed-off-by: Gaurav Jaswal <[email protected]> Co-authored-by: Amrutha <[email protected]>
- Loading branch information
1 parent
d323b60
commit f62242d
Showing
22 changed files
with
310 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package helpers | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestGetAwsAccountIdAndClusterName(t *testing.T) { | ||
|
||
awsAccountId, clusterName := GetAwsAccountIdAndClusterName("arn:aws:eks:us-west-2:123456789012:cluster/hub-cluster") | ||
if awsAccountId != "123456789012" && clusterName != "hub-cluster" { | ||
t.Errorf("awsAccountId and cluster id are not valid") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package operator | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
operatorapiv1 "open-cluster-management.io/api/operator/v1" | ||
) | ||
|
||
var _ = ginkgo.Describe("ClusterManager Default Mode with aws registration", func() { | ||
var cancel context.CancelFunc | ||
var hubRegistrationSA = "registration-controller-sa" | ||
|
||
ginkgo.BeforeEach(func() { | ||
var ctx context.Context | ||
ctx, cancel = context.WithCancel(context.Background()) | ||
go startHubOperator(ctx, operatorapiv1.InstallModeDefault) | ||
}) | ||
|
||
ginkgo.AfterEach(func() { | ||
// delete deployment for clustermanager here so tests are not impacted with each other | ||
err := kubeClient.AppsV1().Deployments(hubNamespace).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{}) | ||
gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||
if cancel != nil { | ||
cancel() | ||
} | ||
}) | ||
|
||
ginkgo.Context("Deploy hub with aws auth", func() { | ||
|
||
ginkgo.It("should have IAM role annotation when initialized with awsirsa", func() { | ||
|
||
clusterManager, err := operatorClient.OperatorV1().ClusterManagers().Get(context.Background(), clusterManagerName, metav1.GetOptions{}) | ||
gomega.Expect(err).ToNot(gomega.HaveOccurred()) | ||
|
||
if clusterManager.Spec.RegistrationConfiguration == nil { | ||
clusterManager.Spec.RegistrationConfiguration = &operatorapiv1.RegistrationHubConfiguration{} | ||
clusterManager.Spec.RegistrationConfiguration.RegistrationDrivers = []operatorapiv1.RegistrationDriverHub{ | ||
{ | ||
AuthType: "awsirsa", | ||
HubClusterArn: "arn:aws:eks:us-west-2:123456789012:cluster/hub-cluster", | ||
}, | ||
} | ||
} | ||
_, err = operatorClient.OperatorV1().ClusterManagers().Update(context.Background(), clusterManager, metav1.UpdateOptions{}) | ||
gomega.Expect(err).ToNot(gomega.HaveOccurred()) | ||
|
||
gomega.Eventually(func() bool { | ||
registrationControllerSA, err := kubeClient.CoreV1().ServiceAccounts(hubNamespace).Get( | ||
context.Background(), hubRegistrationSA, metav1.GetOptions{}) | ||
if err != nil { | ||
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()) | ||
|
||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.