From 27f87d67113cf581f0129447060e8e63c6e93f37 Mon Sep 17 00:00:00 2001 From: Josh Lucas Date: Tue, 19 Sep 2023 10:24:17 -0400 Subject: [PATCH 1/2] Add test to ensure LogStorage secrets controller takes no action on managed clusters --- Makefile | 6 ++--- .../logstorage/secrets/secret_controller.go | 2 -- .../secrets/secret_controller_test.go | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 2b54144131..e063be0ac6 100644 --- a/Makefile +++ b/Makefile @@ -290,21 +290,21 @@ clean: ############################################################################### UT_DIR?=./pkg FV_DIR?=./test -GINKGO_ARGS?= -v +GINKGO_ARGS?= -v -trace -r GINKGO_FOCUS?=.* .PHONY: ut ut: -mkdir -p .go-pkg-cache report $(CONTAINERIZED) $(CALICO_BUILD) sh -c '$(GIT_CONFIG_SSH) \ - ginkgo -trace -r -focus="$(GINKGO_FOCUS)" $(GINKGO_ARGS) "$(UT_DIR)"' + ginkgo -focus="$(GINKGO_FOCUS)" $(GINKGO_ARGS) "$(UT_DIR)"' ## Run the functional tests fv: cluster-create load-container-images run-fvs cluster-destroy run-fvs: -mkdir -p .go-pkg-cache report $(CONTAINERIZED) $(CALICO_BUILD) sh -c '$(GIT_CONFIG_SSH) \ - ginkgo -trace -r -focus="$(GINKGO_FOCUS)" $(GINKGO_ARGS) "$(FV_DIR)"' + ginkgo -focus="$(GINKGO_FOCUS)" $(GINKGO_ARGS) "$(FV_DIR)"' ## Create a local kind dual stack cluster. KIND_KUBECONFIG?=./kubeconfig.yaml diff --git a/pkg/controller/logstorage/secrets/secret_controller.go b/pkg/controller/logstorage/secrets/secret_controller.go index 73dc3f838c..8a1667abeb 100644 --- a/pkg/controller/logstorage/secrets/secret_controller.go +++ b/pkg/controller/logstorage/secrets/secret_controller.go @@ -196,8 +196,6 @@ func (r *SecretSubController) Reconcile(ctx context.Context, request reconcile.R return reconcile.Result{}, err } - // TODO: Do we need to handle managed clusters differently? Should this controller run at all? - // Wait for the initializing controller to indicate that the LogStorage object is actionable. if ls.Status.State != operatorv1.TigeraStatusReady { r.status.SetDegraded(operatorv1.ResourceNotReady, "Waiting for LogStorage to be ready", nil, reqLogger) diff --git a/pkg/controller/logstorage/secrets/secret_controller_test.go b/pkg/controller/logstorage/secrets/secret_controller_test.go index 9d0b7f8e5e..2e84d6ccdb 100644 --- a/pkg/controller/logstorage/secrets/secret_controller_test.go +++ b/pkg/controller/logstorage/secrets/secret_controller_test.go @@ -476,6 +476,30 @@ var _ = Describe("LogStorage Secrets controller", func() { Expect(err).ShouldNot(HaveOccurred()) Expect(result).Should(Equal(successResult)) }) + + It("should not take any action in managed cluster", func() { + // Create a LogStorage instance with a default configuration. + ls := &operatorv1.LogStorage{} + ls.Name = "tigera-secure" + ls.Status.State = operatorv1.TigeraStatusReady + CreateLogStorage(cli, ls) + + // Create a ManagementCluster object + mcc := &operatorv1.ManagementClusterConnection{} + mcc.Name = "tigera-secure" + Expect(cli.Create(ctx, mcc)).ShouldNot(HaveOccurred()) + + // Run the reconciler. + r, err := NewSecretControllerWithShims(cli, scheme, mockStatus, operatorv1.ProviderNone, dns.DefaultClusterDomain) + Expect(err).ShouldNot(HaveOccurred()) + _, err = r.Reconcile(ctx, reconcile.Request{}) + Expect(err).ShouldNot(HaveOccurred()) + + // Query all secrets, the returned list should only contain the CA secret created in BeforeEach + var secrets corev1.SecretList + Expect(cli.List(ctx, &secrets)).ShouldNot(HaveOccurred()) + Expect(len(secrets.Items)).To(Equal(1)) + }) }) // CreateLogStorage creates a LogStorage object with the given parameters after filling in defaults, From 4f53f7ba8e86f2e4a95d302cb2b7db7fd48bb1af Mon Sep 17 00:00:00 2001 From: Josh Lucas Date: Tue, 26 Sep 2023 10:35:47 -0400 Subject: [PATCH 2/2] Fix comment typo --- pkg/controller/logstorage/secrets/secret_controller_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstorage/secrets/secret_controller_test.go b/pkg/controller/logstorage/secrets/secret_controller_test.go index 2e84d6ccdb..65d17f3c07 100644 --- a/pkg/controller/logstorage/secrets/secret_controller_test.go +++ b/pkg/controller/logstorage/secrets/secret_controller_test.go @@ -484,7 +484,7 @@ var _ = Describe("LogStorage Secrets controller", func() { ls.Status.State = operatorv1.TigeraStatusReady CreateLogStorage(cli, ls) - // Create a ManagementCluster object + // Create a ManagementClusterConnection object mcc := &operatorv1.ManagementClusterConnection{} mcc.Name = "tigera-secure" Expect(cli.Create(ctx, mcc)).ShouldNot(HaveOccurred())