Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
CB controller should ignore clusters with legacy-tkr label (#2624)
Browse files Browse the repository at this point in the history
UTKG Addons manager needs to only process TKRs which do NOT
 have "run.tanzu.vmware.com/legacy-tkr" label

Fixes #2546
  • Loading branch information
Adolfo Duarte authored Jun 14, 2022
1 parent 2602583 commit 6bd1816
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
5 changes: 5 additions & 0 deletions addons/controllers/clusterbootstrap_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ func (r *ClusterBootstrapReconciler) Reconcile(ctx context.Context, req ctrl.Req
return ctrl.Result{}, nil
}

if _, labelFound := tkr.Labels[constants.TKRLableLegacyClusters]; labelFound {
log.Info("Skipping reconciling due to tkr label", "name", tkrName, "label", constants.TKRLableLegacyClusters)
return ctrl.Result{}, nil
}

log.Info("Reconciling cluster")

// if deletion timestamp is set, handle cluster deletion
Expand Down
16 changes: 16 additions & 0 deletions addons/controllers/clusterbootstrap_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,22 @@ var _ = Describe("ClusterBootstrap Reconciler", func() {
})
})

When("Legacy cluster is created", func() {
BeforeEach(func() {
clusterName = "test-cluster-legacy"
clusterNamespace = "legacy-namespace"
clusterResourceFilePath = "testdata/test-cluster-legacy.yaml"
})
Context("and clusterboostrap template does not exists", func() {
It("clusterbootstrap controller should not attempt to reconcile it", func() {
By("verifying CAPI cluster is created properly")
cluster := &clusterapiv1beta1.Cluster{}
Expect(k8sClient.Get(ctx, client.ObjectKey{Namespace: clusterNamespace, Name: clusterName}, cluster)).To(Succeed())
cluster.Status.Phase = string(clusterapiv1beta1.ClusterPhaseProvisioned)
Expect(k8sClient.Status().Update(ctx, cluster)).To(Succeed())
})
})
})
})

func assertSecretContains(ctx context.Context, k8sClient client.Client, namespace, name string, secretContent map[string][]byte) {
Expand Down
69 changes: 69 additions & 0 deletions addons/controllers/testdata/test-cluster-legacy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: legacy-namespace
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: test-cluster-legacy
namespace: legacy-namespace
labels:
tkg.tanzu.vmware.com/cluster-name: test-cluster-legacy
run.tanzu.vmware.com/tkr: v1.12.1
spec:
infrastructureRef:
kind: VSphereCluster
clusterNetwork:
pods:
cidrBlocks: [ "192.168.0.0/16","fd00:100:96::/48" ]
services:
cidrBlocks: [ "192.168.0.0/16","fd00:100:96::/48" ]
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
name: test-cluster-legacy-control-plane
namespace: legacy-namespace
topology:
class: test-clusterclass-legasy
version: v1.22.3
variables:
- name: tkg.tanzu.vmware.com/tkg-ip-family
value: "ipv4"
- name: proxy
value:
httpProxy: "foo.com"
httpsProxy: "bar.com"
noProxy: "foobar.com"
- name: trust
value:
additionalTrustedCAs:
- name: CompanyInternalCA-1
data: aGVsbG8=
- name: CompanyInternalCA-2
data: bHWtcH9=
- name: skipTLSVerify
value:
- registry1
- registry2
---
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
metadata:
name: test-cluster-legacy-control-plane
namespace: legacy-namespace
ownerReferences:
- apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
name: test-cluster-legacy
uid: bd834522-d9a5-4841-beac-991ff3798c01
spec:
kubeadmConfigSpec: {}
machineTemplate:
infrastructureRef: {}
replicas: 3
version: v1.22.3



14 changes: 14 additions & 0 deletions addons/controllers/testdata/test-tkg-system-ns-resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ spec:
imageRepository: foo
osImages: []
bootstrapPackages: []
---
apiVersion: run.tanzu.vmware.com/v1alpha3
kind: TanzuKubernetesRelease
metadata:
name: v1.12.1
labels:
run.tanzu.vmware.com/legacy-tkr: ""
spec:
version: v1.12.1
kubernetes:
version: v1.12.1
imageRepository: foo
osImages: [ ]
bootstrapPackages: [ ]
---
apiVersion: run.tanzu.vmware.com/v1alpha3
kind: ClusterBootstrapTemplate
Expand Down
3 changes: 3 additions & 0 deletions addons/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const (
// TKRLabelClassyClusters is the TKR label for the clusters created using cluster-class
TKRLabelClassyClusters = "run.tanzu.vmware.com/tkr"

// TKRLabelLegacyClusters is the TKR label for legacy clusters
TKRLableLegacyClusters = "run.tanzu.vmware.com/legacy-tkr"

// TKGBomContent is the TKG BOM content.
TKGBomContent = "bomContent"

Expand Down

0 comments on commit 6bd1816

Please sign in to comment.