Skip to content

Commit

Permalink
Switch mgmtv3 cluster name to prevent v1 provisioning
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed Aug 20, 2024
1 parent 0bac345 commit d94cbb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/controllers/import_controller_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (r *CAPIImportManagementV3Reconciler) reconcileNormal(ctx context.Context,
newCluster := &managementv3.Cluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: capiCluster.Namespace,
GenerateName: "c-",
GenerateName: capiCluster.Name,
Labels: map[string]string{
capiClusterOwner: capiCluster.Name,
capiClusterOwnerNamespace: capiCluster.Namespace,
Expand Down
22 changes: 11 additions & 11 deletions internal/controllers/import_controller_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {
rancherCluster = &managementv3.Cluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: capiCluster.Namespace,
GenerateName: "c-",
GenerateName: capiCluster.Name,
Labels: map[string]string{
capiClusterOwner: capiCluster.Name,
capiClusterOwnerNamespace: capiCluster.Namespace,
Expand Down Expand Up @@ -196,7 +196,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {
Eventually(ctx, func(g Gomega) {
g.Expect(cl.List(ctx, rancherClusters, selectors...)).ToNot(HaveOccurred())
g.Expect(rancherClusters.Items).To(HaveLen(1))
g.Expect(rancherClusters.Items[0].Name).To(ContainSubstring("c-"))
g.Expect(rancherClusters.Items[0].Name).To(ContainSubstring(capiCluster.Name))
g.Expect(rancherClusters.Items[0].Labels).To(HaveKeyWithValue(testLabelName, testLabelVal))
g.Expect(rancherClusters.Items[0].Finalizers).To(ContainElement(managementv3.CapiClusterFinalizer))
}).Should(Succeed())
Expand Down Expand Up @@ -227,7 +227,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(cl.List(ctx, rancherClusters, selectors...)).ToNot(HaveOccurred())
g.Expect(rancherClusters.Items).To(HaveLen(1))
}).Should(Succeed())
Expect(rancherClusters.Items[0].Name).To(ContainSubstring("c-"))
Expect(rancherClusters.Items[0].Name).To(ContainSubstring(capiCluster.Name))
})

It("should reconcile a CAPI cluster when rancher cluster exists, and have finalizers set", func() {
Expand All @@ -254,7 +254,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(rancherClusters.Items[0].Finalizers).ToNot(ContainElement(managementv3.CapiClusterFinalizer))
}).Should(Succeed())
cluster := rancherClusters.Items[0]
Expect(cluster.Name).To(ContainSubstring("c-"))
Expect(cluster.Name).To(ContainSubstring(capiCluster.Name))

clusterRegistrationToken.Name = cluster.Name
clusterRegistrationToken.Namespace = cluster.Name
Expand Down Expand Up @@ -297,7 +297,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {

g.Expect(cl.List(ctx, rancherClusters, selectors...)).ToNot(HaveOccurred())
g.Expect(rancherClusters.Items).To(HaveLen(1))
g.Expect(rancherClusters.Items[0].Name).To(ContainSubstring("c-"))
g.Expect(rancherClusters.Items[0].Name).To(ContainSubstring(capiCluster.Name))
g.Expect(rancherClusters.Items[0].Labels).To(HaveKeyWithValue(testLabelName, testLabelVal))
g.Expect(rancherClusters.Items[0].Finalizers).To(ContainElement(managementv3.CapiClusterFinalizer))
}, 10*time.Second).Should(Succeed())
Expand All @@ -314,7 +314,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(rancherClusters.Items).To(HaveLen(1))
}).Should(Succeed())
cluster := rancherClusters.Items[0]
Expect(cluster.Name).To(ContainSubstring("c-"))
Expect(cluster.Name).To(ContainSubstring(capiCluster.Name))

_, err := testEnv.CreateNamespaceWithName(ctx, cluster.Name)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -343,7 +343,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(rancherClusters.Items).To(HaveLen(1))
}).Should(Succeed())
cluster := rancherClusters.Items[0]
Expect(cluster.Name).To(ContainSubstring("c-"))
Expect(cluster.Name).To(ContainSubstring(capiCluster.Name))

conditions.Set(&cluster, conditions.TrueCondition(managementv3.ClusterConditionReady))
Expect(conditions.IsTrue(&cluster, managementv3.ClusterConditionReady)).To(BeTrue())
Expand Down Expand Up @@ -378,7 +378,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(rancherClusters.Items).To(HaveLen(1))
}).Should(Succeed())
cluster := rancherClusters.Items[0]
Expect(cluster.Name).To(ContainSubstring("c-"))
Expect(cluster.Name).To(ContainSubstring(capiCluster.Name))

clusterRegistrationToken.Name = cluster.Name
clusterRegistrationToken.Namespace = cluster.Name
Expand Down Expand Up @@ -421,7 +421,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(rancherClusters.Items).To(HaveLen(1))
}).Should(Succeed())
cluster := rancherClusters.Items[0]
Expect(cluster.Name).To(ContainSubstring("c-"))
Expect(cluster.Name).To(ContainSubstring(capiCluster.Name))

clusterRegistrationToken.Name = cluster.Name
clusterRegistrationToken.Namespace = cluster.Name
Expand Down Expand Up @@ -455,7 +455,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(rancherClusters.Items).To(HaveLen(1))
}).Should(Succeed())
cluster := rancherClusters.Items[0]
Expect(cluster.Name).To(ContainSubstring("c-"))
Expect(cluster.Name).To(ContainSubstring(capiCluster.Name))

clusterRegistrationToken.Name = cluster.Name
clusterRegistrationToken.Namespace = cluster.Name
Expand Down Expand Up @@ -514,7 +514,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(cl.List(ctx, rancherClusters, selectors...)).ToNot(HaveOccurred())
g.Expect(rancherClusters.Items).To(HaveLen(1))
}).Should(Succeed())
Expect(rancherClusters.Items[0].Name).To(ContainSubstring("c-"))
Expect(rancherClusters.Items[0].Name).To(ContainSubstring(capiCluster.Name))
Expect(rancherClusters.Items[0].Labels).To(HaveKeyWithValue(testLabelName, testLabelVal))
})

Expand Down

0 comments on commit d94cbb2

Please sign in to comment.