From 1dc8ceb011a63bfc00e583989bd8308d7cb2010a Mon Sep 17 00:00:00 2001 From: xuezhao Date: Mon, 3 Jun 2024 21:29:54 +0800 Subject: [PATCH] Fix condition error of ManifestApplied. (#273) Signed-off-by: xuezhaojun --- .../controllers/agentdeploy/controller.go | 17 ++++++++--------- .../controllers/agentdeploy/hosted_sync_test.go | 14 ++++++++++++++ test/integration/agent_hosting_deploy_test.go | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/pkg/addonmanager/controllers/agentdeploy/controller.go b/pkg/addonmanager/controllers/agentdeploy/controller.go index 7129a9aa0..f88160049 100644 --- a/pkg/addonmanager/controllers/agentdeploy/controller.go +++ b/pkg/addonmanager/controllers/agentdeploy/controller.go @@ -386,15 +386,6 @@ func (c *addonDeployController) buildDeployManifestWorks(installMode, workNamesp }) return nil, nil, err } - if len(objects) == 0 { - meta.SetStatusCondition(&addon.Status.Conditions, metav1.Condition{ - Type: appliedType, - Status: metav1.ConditionTrue, - Reason: addonapiv1alpha1.AddonManifestAppliedReasonManifestsApplied, - Message: "no manifest need to apply", - }) - return nil, nil, nil - } manifestOptions := getManifestConfigOption(agentAddon, cluster, addon) existingWorksCopy := []workapiv1.ManifestWork{} @@ -411,6 +402,14 @@ func (c *addonDeployController) buildDeployManifestWorks(installMode, workNamesp }) return nil, nil, err } + if len(appliedWorks) == 0 { + meta.SetStatusCondition(&addon.Status.Conditions, metav1.Condition{ + Type: appliedType, + Status: metav1.ConditionTrue, + Reason: addonapiv1alpha1.AddonManifestAppliedReasonManifestsApplied, + Message: "no manifest need to apply", + }) + } return appliedWorks, deleteWorks, nil } func (c *addonDeployController) buildHookManifestWork(installMode, workNamespace string, diff --git a/pkg/addonmanager/controllers/agentdeploy/hosted_sync_test.go b/pkg/addonmanager/controllers/agentdeploy/hosted_sync_test.go index 0979a75e7..8e2bca30e 100644 --- a/pkg/addonmanager/controllers/agentdeploy/hosted_sync_test.go +++ b/pkg/addonmanager/controllers/agentdeploy/hosted_sync_test.go @@ -236,6 +236,20 @@ func TestHostingReconcile(t *testing.T) { if meta.IsStatusConditionFalse(addOn.Status.Conditions, addonapiv1alpha1.ManagedClusterAddOnHostingManifestApplied) { t.Errorf("Condition Reason is not correct: %v", addOn.Status.Conditions) } + + manifestAppliyedCondition := meta.FindStatusCondition(addOn.Status.Conditions, addonapiv1alpha1.ManagedClusterAddOnManifestApplied) + if manifestAppliyedCondition == nil { + t.Fatal("manifestapplied condition should not be nil") + } + if manifestAppliyedCondition.Reason != addonapiv1alpha1.AddonManifestAppliedReasonManifestsApplied { + t.Errorf("Condition Reason is not correct: %v", manifestAppliyedCondition.Reason) + } + if manifestAppliyedCondition.Message != "no manifest need to apply" { + t.Errorf("Condition Message is not correct: %v", manifestAppliyedCondition.Message) + } + if manifestAppliyedCondition.Status != metav1.ConditionTrue { + t.Errorf("Condition Status is not correct: %v", manifestAppliyedCondition.Status) + } }, }, { diff --git a/test/integration/agent_hosting_deploy_test.go b/test/integration/agent_hosting_deploy_test.go index cf2587afe..324f25946 100644 --- a/test/integration/agent_hosting_deploy_test.go +++ b/test/integration/agent_hosting_deploy_test.go @@ -198,6 +198,20 @@ var _ = ginkgo.Describe("Agent deploy", func() { if !meta.IsStatusConditionTrue(addon.Status.Conditions, addonapiv1alpha1.ManagedClusterAddOnHostingManifestApplied) { return fmt.Errorf("Unexpected addon applied condition, %v", addon.Status.Conditions) } + + manifestAppliyedCondition := meta.FindStatusCondition(addon.Status.Conditions, addonapiv1alpha1.ManagedClusterAddOnManifestApplied) + if manifestAppliyedCondition == nil { + return fmt.Errorf("%s Condition is not found", addonapiv1alpha1.ManagedClusterAddOnManifestApplied) + } + if manifestAppliyedCondition.Reason != addonapiv1alpha1.AddonManifestAppliedReasonManifestsApplied { + return fmt.Errorf("Condition Reason is not correct: %v", manifestAppliyedCondition.Reason) + } + if manifestAppliyedCondition.Message != "no manifest need to apply" { + return fmt.Errorf("Condition Message is not correct: %v", manifestAppliyedCondition.Message) + } + if manifestAppliyedCondition.Status != metav1.ConditionTrue { + return fmt.Errorf("Condition Status is not correct: %v", manifestAppliyedCondition.Status) + } return nil }, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred())