-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Assume prerequisite role on hub if initailize with aws-irsa #807
Merged
openshift-merge-bot
merged 2 commits into
open-cluster-management-io:main
from
guidewire-oss:managed-cluster-identity-creator-role-changes
Jan 17, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not quite extensible, e.g. the key is specifically for eks. How do you think the keys/values could be configured from the template?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think same needs to be applied on klusterlet SA as well. Will address it in a seperate PR.