From d9e1a87ceb5c1d44990157060140b4943579228a Mon Sep 17 00:00:00 2001 From: Shivaani Gupta Date: Tue, 11 Apr 2023 13:06:19 -0700 Subject: [PATCH] Reverting back changes for earlier trials for fixing unit tests --- .../clusterbootstrap_controller_test.go | 23 ++++++++++++++----- .../testdata/test-cluster-bootstrap-9.yaml | 11 +++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/addons/controllers/clusterbootstrap_controller_test.go b/addons/controllers/clusterbootstrap_controller_test.go index e93177cf46..e7d45d1700 100644 --- a/addons/controllers/clusterbootstrap_controller_test.go +++ b/addons/controllers/clusterbootstrap_controller_test.go @@ -1295,15 +1295,26 @@ var _ = Describe("ClusterBootstrap Reconciler", func() { if err := k8sClient.Get(ctx, key, config); err != nil { return false } - ownerRef := metav1.OwnerReference{ - APIVersion: clusterapiv1beta1.GroupVersion.String(), - Kind: "Cluster", - Name: cluster.Name, - UID: cluster.UID, + + if len(config.OwnerReferences) > 0 { + return false } - return clusterapiutil.HasOwnerRef(config.OwnerReferences, ownerRef) + + Expect(len(config.OwnerReferences)).Should(Equal(0)) + return true }, waitTimeout, pollingInterval).Should(BeTrue()) + patchedSecret := config.DeepCopy() + ownerRef := metav1.OwnerReference{ + APIVersion: clusterapiv1beta1.GroupVersion.String(), + Kind: "Cluster", + Name: cluster.Name, + UID: cluster.UID, + } + + patchedSecret.OwnerReferences = clusterapiutil.EnsureOwnerRef(patchedSecret.OwnerReferences, ownerRef) + Expect(k8sClient.Patch(ctx, patchedSecret, client.MergeFrom(config))).ShouldNot(HaveOccurred()) + Expect(config.ObjectMeta.Labels["tkg.tanzu.vmware.com/package-name"]).Should(Equal("load-balancer-and-ingress-service.tanzu.vmware.com.0.0.4")) By("ClusterBootstrap CR is created with correct ownerReference added") diff --git a/addons/controllers/testdata/test-cluster-bootstrap-9.yaml b/addons/controllers/testdata/test-cluster-bootstrap-9.yaml index 60cd4d407d..8fefdcc4d2 100644 --- a/addons/controllers/testdata/test-cluster-bootstrap-9.yaml +++ b/addons/controllers/testdata/test-cluster-bootstrap-9.yaml @@ -1042,6 +1042,17 @@ stringData: identity_management_type: none tkg_cluster_role: workload --- +apiVersion: v1 +kind: Secret +metadata: + name: default-pinniped-config-v1.23.5---vmware.1-tkg.1 + namespace: cluster-namespace-9 +stringData: + values.yaml: | + infrastructure_provider: vsphere + identity_management_type: none + tkg_cluster_role: workload +--- apiVersion: cni.tanzu.vmware.com/v1alpha1 kind: CalicoConfig metadata: