-
Notifications
You must be signed in to change notification settings - Fork 95
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
✨ (WIP) Extract the logic to add cluster annotations to the driver interface and add unit and integration tests #750
Open
dtclxy64
wants to merge
4
commits into
open-cluster-management-io:main
Choose a base branch
from
guidewire-oss:feature/spoke-agent-registration-aws-irsa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cea6a14
Extract the logic to add cluster annotations to the driver interface …
dtclxy64 79f4b72
Fix the make verify logic and linting errors.
dtclxy64 7373b40
Add cluster decorator interface in register
qiujian16 69a47ed
updating ManagedClusterDecorator signature and updating clusterannota…
suvaanshkumar 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
72 changes: 72 additions & 0 deletions
72
test/integration/registration/clusterannotations_aws_test.go
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,72 @@ | ||
package registration_test | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
"time" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
|
||
operatorv1 "open-cluster-management.io/api/operator/v1" | ||
|
||
commonoptions "open-cluster-management.io/ocm/pkg/common/options" | ||
"open-cluster-management.io/ocm/pkg/registration/register/aws_irsa" | ||
"open-cluster-management.io/ocm/pkg/registration/spoke" | ||
"open-cluster-management.io/ocm/test/integration/util" | ||
) | ||
|
||
var _ = ginkgo.Describe("Cluster Annotations for aws", func() { | ||
ginkgo.It("Cluster Annotations for aws flow should be created on the managed cluster", func() { | ||
managedClusterName := "clusterannotations-spokecluster-aws" | ||
//#nosec G101 | ||
hubKubeconfigSecret := "clusterannotations-hub-kubeconfig-secret" | ||
hubKubeconfigDir := path.Join(util.TestDir, "clusterannotations", "hub-kubeconfig") | ||
|
||
managedClusterArn := "arn:aws:eks:us-west-2:123456789012:cluster/managed-cluster1" | ||
managedClusterRoleSuffix := "7f8141296c75f2871e3d030f85c35692" | ||
hubClusterArn := "arn:aws:eks:us-west-2:123456789012:cluster/hub-cluster1" | ||
agentOptions := &spoke.SpokeAgentOptions{ | ||
RegistrationAuth: spoke.AwsIrsaAuthType, | ||
HubClusterArn: hubClusterArn, | ||
ManagedClusterArn: managedClusterArn, | ||
ManagedClusterRoleSuffix: managedClusterRoleSuffix, | ||
BootstrapKubeconfig: bootstrapKubeConfigFile, | ||
HubKubeconfigSecret: hubKubeconfigSecret, | ||
ClusterHealthCheckPeriod: 1 * time.Minute, | ||
ClusterAnnotations: map[string]string{ | ||
"agent.open-cluster-management.io/foo": "bar", | ||
"foo": "bar", // this annotation should be filtered out | ||
}, | ||
} | ||
|
||
commOptions := commonoptions.NewAgentOptions() | ||
commOptions.HubKubeconfigDir = hubKubeconfigDir | ||
commOptions.SpokeClusterName = managedClusterName | ||
|
||
// run registration agent | ||
cancel := runAgent("rotationtest", agentOptions, commOptions, spokeCfg) | ||
defer cancel() | ||
|
||
// after bootstrap the spokecluster and csr should be created | ||
gomega.Eventually(func() error { | ||
mc, err := util.GetManagedCluster(clusterClient, managedClusterName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if mc.Annotations[operatorv1.ClusterAnnotationsKeyPrefix+"/"+aws_irsa.ManagedClusterArn] != managedClusterArn { | ||
return fmt.Errorf("expected annotation "+operatorv1.ClusterAnnotationsKeyPrefix+"/"+aws_irsa.ManagedClusterArn+" to be "+ | ||
""+managedClusterArn+", got %s", mc.Annotations[operatorv1.ClusterAnnotationsKeyPrefix+"/"+aws_irsa.ManagedClusterArn]) | ||
} | ||
|
||
if mc.Annotations[operatorv1.ClusterAnnotationsKeyPrefix+"/"+aws_irsa.ManagedClusterIAMRoleSuffix] != managedClusterRoleSuffix { | ||
return fmt.Errorf("expected annotation "+operatorv1.ClusterAnnotationsKeyPrefix+"/"+aws_irsa.ManagedClusterIAMRoleSuffix+" "+ | ||
"to be "+managedClusterRoleSuffix+", got %s", mc.Annotations[operatorv1.ClusterAnnotationsKeyPrefix+"/"+aws_irsa.ManagedClusterIAMRoleSuffix]) | ||
} | ||
|
||
return nil | ||
}, eventuallyTimeout, eventuallyInterval).Should(gomega.Succeed()) | ||
|
||
}) | ||
}) |
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
119 changes: 119 additions & 0 deletions
119
test/integration/registration/spokecluster_aws_joining_test.go
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,119 @@ | ||
package registration_test | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
"time" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
"k8s.io/apimachinery/pkg/util/rand" | ||
|
||
commonoptions "open-cluster-management.io/ocm/pkg/common/options" | ||
"open-cluster-management.io/ocm/pkg/registration/spoke" | ||
"open-cluster-management.io/ocm/test/integration/util" | ||
) | ||
|
||
var _ = ginkgo.Describe("Joining Process for aws flow", func() { | ||
var bootstrapKubeconfig string | ||
var managedClusterName string | ||
var hubKubeconfigSecret string | ||
var hubKubeconfigDir string | ||
|
||
ginkgo.BeforeEach(func() { | ||
postfix := rand.String(5) | ||
managedClusterName = fmt.Sprintf("joiningtest-managedcluster-%s", postfix) | ||
hubKubeconfigSecret = fmt.Sprintf("joiningtest-hub-kubeconfig-secret-%s", postfix) | ||
hubKubeconfigDir = path.Join(util.TestDir, fmt.Sprintf("joiningtest-%s", postfix), "hub-kubeconfig") | ||
}) | ||
|
||
assertJoiningSucceed := func() { | ||
ginkgo.It("managedcluster should join successfully for aws flow", func() { | ||
var err error | ||
|
||
managedClusterArn := "arn:aws:eks:us-west-2:123456789012:cluster/managed-cluster1" | ||
managedClusterRoleSuffix := "7f8141296c75f2871e3d030f85c35692" | ||
hubClusterArn := "arn:aws:eks:us-west-2:123456789012:cluster/hub-cluster1" | ||
|
||
// run registration agent | ||
agentOptions := &spoke.SpokeAgentOptions{ | ||
RegistrationAuth: spoke.AwsIrsaAuthType, | ||
HubClusterArn: hubClusterArn, | ||
ManagedClusterArn: managedClusterArn, | ||
ManagedClusterRoleSuffix: managedClusterRoleSuffix, | ||
BootstrapKubeconfig: bootstrapKubeconfig, | ||
HubKubeconfigSecret: hubKubeconfigSecret, | ||
ClusterHealthCheckPeriod: 1 * time.Minute, | ||
} | ||
commOptions := commonoptions.NewAgentOptions() | ||
commOptions.HubKubeconfigDir = hubKubeconfigDir | ||
commOptions.SpokeClusterName = managedClusterName | ||
|
||
cancel := runAgent("joiningtest", agentOptions, commOptions, spokeCfg) | ||
defer cancel() | ||
|
||
// the ManagedCluster CR should be created after bootstrap | ||
gomega.Eventually(func() error { | ||
if _, err := util.GetManagedCluster(clusterClient, managedClusterName); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred()) | ||
|
||
// the csr should not be created for aws flow after bootstrap | ||
gomega.Eventually(func() error { | ||
if _, err := util.FindUnapprovedSpokeCSR(kubeClient, managedClusterName); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, eventuallyTimeout, eventuallyInterval).Should(gomega.HaveOccurred()) | ||
|
||
// simulate hub cluster admin to accept the managedcluster | ||
err = util.AcceptManagedCluster(clusterClient, managedClusterName) | ||
gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||
|
||
err = authn.ApproveSpokeClusterCSR(kubeClient, managedClusterName, time.Hour*24) | ||
gomega.Expect(err).To(gomega.HaveOccurred()) | ||
|
||
// the hub kubeconfig secret should be filled after the ManagedCluster is accepted | ||
// TODO: Revisit while implementing slice 3 | ||
//gomega.Eventually(func() error { | ||
// secret, err := util.GetFilledHubKubeConfigSecret(kubeClient, testNamespace, hubKubeconfigSecret) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// | ||
// // check if the proxyURL is set correctly | ||
// proxyURL, err := getProxyURLFromKubeconfigData(secret.Data["kubeconfig"]) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// if proxyURL != expectedProxyURL { | ||
// return fmt.Errorf("expected proxy url %q, but got %q", expectedProxyURL, proxyURL) | ||
// } | ||
// return nil | ||
//}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred()) | ||
|
||
// the spoke cluster should have joined condition finally | ||
// TODO: Revisit while implementing slice 3 | ||
//gomega.Eventually(func() error { | ||
// spokeCluster, err := util.GetManagedCluster(clusterClient, managedClusterName) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// if !meta.IsStatusConditionTrue(spokeCluster.Status.Conditions, clusterv1.ManagedClusterConditionJoined) { | ||
// return fmt.Errorf("cluster should be joined") | ||
// } | ||
// return nil | ||
//}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred()) | ||
}) | ||
} | ||
|
||
ginkgo.Context("without proxy", func() { | ||
ginkgo.BeforeEach(func() { | ||
bootstrapKubeconfig = bootstrapKubeConfigFile | ||
}) | ||
assertJoiningSucceed() | ||
}) | ||
|
||
}) |
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.
I could understand the intension. But I wonder it is suitable for an interface since it seems quite specific to a certain implementation. I am thinking whether it makes more sense to have a method like
and call it in the creatingCluster controller.
I can try to create an example PR to show how it looks like.
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.
#752
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.
@qiujian16 We are incorporating the changes from #752 into our changes. We'll let you know once we are ready for another around of reviews. Thanks for creating the example PR to demonstrate the changes.