Skip to content

Commit

Permalink
Fix condition error of ManifestApplied. (#273) (#274)
Browse files Browse the repository at this point in the history
Signed-off-by: xuezhaojun <[email protected]>
  • Loading branch information
xuezhaojun authored Jun 3, 2024
1 parent cee1ae4 commit c8c2cd9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pkg/addonmanager/controllers/agentdeploy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions pkg/addonmanager/controllers/agentdeploy/hosted_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
},
},
{
Expand Down
14 changes: 14 additions & 0 deletions test/integration/agent_hosting_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit c8c2cd9

Please sign in to comment.