-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding managedcluster identity creator role arn
Signed-off-by: Gaurav Jaswal <[email protected]>
- Loading branch information
1 parent
54a9764
commit a21f7b4
Showing
22 changed files
with
290 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,15 @@ | ||
package helpers | ||
|
||
import "strings" | ||
|
||
func GetAwsAccountIdAndClusterName(clusterArn string) (string, string) { | ||
clusterStringParts := strings.Split(clusterArn, ":") | ||
clusterName := strings.Split(clusterStringParts[5], "/")[1] | ||
awsAccountId := clusterStringParts[4] | ||
return awsAccountId, clusterName | ||
} | ||
|
||
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,62 @@ | ||
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"] | ||
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
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.