-
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.
Extract the logic to add cluster annotations to the driver interface …
…and add unit and integration tests Signed-off-by: dtclxy64 <[email protected]>
- Loading branch information
Showing
8 changed files
with
235 additions
and
18 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
69 changes: 69 additions & 0 deletions
69
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,69 @@ | ||
package registration_test | ||
|
||
import ( | ||
"fmt" | ||
operatorv1 "open-cluster-management.io/api/operator/v1" | ||
"path" | ||
"time" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
|
||
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
118 changes: 118 additions & 0 deletions
118
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,118 @@ | ||
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() | ||
}) | ||
|
||
}) |