Skip to content

Commit 7b2a16d

Browse files
authored
🐛 dont set negative addon conds if no addon ops were performed (#64)
* fix: dont set neg addon conds if no addon ops were performed Signed-off-by: Artur Shad Nik <[email protected]> * chore: dont obscure crd error when addons are requested Signed-off-by: Artur Shad Nik <[email protected]> * chore: add logging if addontemplate crd is not found Signed-off-by: Artur Shad Nik <[email protected]> --------- Signed-off-by: Artur Shad Nik <[email protected]>
1 parent c8efab6 commit 7b2a16d

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

fleetconfig-controller/internal/controller/v1alpha1/addon.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,23 @@ const (
3535
hubAddon = "hub-addon"
3636
)
3737

38-
func handleAddonConfig(ctx context.Context, kClient client.Client, addonC *addonapi.Clientset, fc *v1alpha1.FleetConfig) error {
38+
func handleAddonConfig(ctx context.Context, kClient client.Client, addonC *addonapi.Clientset, fc *v1alpha1.FleetConfig) (bool, error) {
3939
logger := log.FromContext(ctx)
4040
logger.V(0).Info("handleAddOnConfig", "fleetconfig", fc.Name)
4141

42+
requestedAddOns := fc.Spec.AddOnConfigs
43+
4244
// get existing addons
4345
createdAddOns, err := addonC.AddonV1alpha1().AddOnTemplates().List(ctx, metav1.ListOptions{LabelSelector: v1alpha1.ManagedBySelector.String()})
4446
if err != nil {
45-
return err
47+
logger.V(1).Info("failed to list AddOnTemplates, ensure CRDs are installed.", "error", err)
48+
return len(requestedAddOns) > 0, err
4649
}
4750

48-
requestedAddOns := fc.Spec.AddOnConfigs
49-
5051
// nothing to do
5152
if len(requestedAddOns) == 0 && len(createdAddOns.Items) == 0 {
5253
logger.V(5).Info("no addons to reconcile")
53-
return nil
54+
return false, nil
5455
}
5556

5657
// compare existing to requested
@@ -83,15 +84,15 @@ func handleAddonConfig(ctx context.Context, kClient client.Client, addonC *addon
8384
// do deletes first, then creates.
8485
err = handleAddonDelete(ctx, addonC, fc, addonsToDelete)
8586
if err != nil {
86-
return err
87+
return true, err
8788
}
8889

8990
err = handleAddonCreate(ctx, kClient, fc, addonsToCreate)
9091
if err != nil {
91-
return err
92+
return true, err
9293
}
9394

94-
return nil
95+
return true, nil
9596
}
9697

9798
func handleAddonCreate(ctx context.Context, kClient client.Client, fc *v1alpha1.FleetConfig, addons []v1alpha1.AddOnConfig) error {
@@ -408,7 +409,7 @@ func isHubAddOnMatching(installed v1alpha1.InstalledHubAddOn, desired v1alpha1.H
408409
installed.BundleVersion == bundleVersion
409410
}
410411

411-
func handleHubAddons(ctx context.Context, addonC *addonapi.Clientset, fc *v1alpha1.FleetConfig) error {
412+
func handleHubAddons(ctx context.Context, addonC *addonapi.Clientset, fc *v1alpha1.FleetConfig) (bool, error) {
412413
logger := log.FromContext(ctx)
413414
logger.V(0).Info("handleHubAddons", "fleetconfig", fc.Name)
414415

@@ -419,7 +420,7 @@ func handleHubAddons(ctx context.Context, addonC *addonapi.Clientset, fc *v1alph
419420
// nothing to do
420421
if len(desiredAddOns) == 0 && len(installedAddOns) == 0 {
421422
logger.V(5).Info("no hub addons to reconcile")
422-
return nil
423+
return false, nil
423424
}
424425

425426
// Find addons that need to be uninstalled (present in installed, missing from desired or version mismatch)
@@ -447,12 +448,12 @@ func handleHubAddons(ctx context.Context, addonC *addonapi.Clientset, fc *v1alph
447448
// do uninstalls first, then installs
448449
err := handleHubAddonUninstall(ctx, addonsToUninstall, fc)
449450
if err != nil {
450-
return err
451+
return true, err
451452
}
452453

453454
err = handleHubAddonInstall(ctx, addonC, addonsToInstall, bundleVersion, fc)
454455
if err != nil {
455-
return err
456+
return true, err
456457
}
457458

458459
// build the new installed addons list
@@ -465,7 +466,7 @@ func handleHubAddons(ctx context.Context, addonC *addonapi.Clientset, fc *v1alph
465466
})
466467
}
467468
fc.Status.InstalledHubAddOns = newInstalledAddOns
468-
return nil
469+
return true, nil
469470
}
470471

471472
func handleHubAddonUninstall(ctx context.Context, addons []v1alpha1.InstalledHubAddOn, fc *v1alpha1.FleetConfig) error {

fleetconfig-controller/internal/controller/v1alpha1/hub.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,29 @@ func handleHub(ctx context.Context, kClient client.Client, fc *v1alpha1.FleetCon
8686
v1alpha1.FleetConfigHubInitialized, v1alpha1.FleetConfigHubInitialized, metav1.ConditionTrue, metav1.ConditionTrue,
8787
))
8888

89-
err = handleAddonConfig(ctx, kClient, addonC, fc)
90-
if err != nil {
89+
addonConfigChanged, err := handleAddonConfig(ctx, kClient, addonC, fc)
90+
if err != nil && addonConfigChanged {
9191
fc.SetConditions(true, v1alpha1.NewCondition(
9292
err.Error(), v1alpha1.FleetConfigAddonsConfigured, metav1.ConditionFalse, metav1.ConditionTrue,
9393
))
9494
return err
9595
}
9696

97-
err = handleHubAddons(ctx, addonC, fc)
98-
if err != nil {
97+
hubAddonChanged, err := handleHubAddons(ctx, addonC, fc)
98+
if err != nil && hubAddonChanged {
9999
fc.SetConditions(true, v1alpha1.NewCondition(
100100
err.Error(), v1alpha1.FleetConfigAddonsConfigured, metav1.ConditionFalse, metav1.ConditionTrue,
101101
))
102102
return err
103103
}
104104

105-
if len(fc.Spec.AddOnConfigs)+len(fc.Spec.HubAddOns) > 0 {
105+
// only set success condition if we actually managed any addons
106+
if addonConfigChanged || hubAddonChanged {
106107
fc.SetConditions(true, v1alpha1.NewCondition(
107108
v1alpha1.FleetConfigAddonsConfigured, v1alpha1.FleetConfigAddonsConfigured, metav1.ConditionTrue, metav1.ConditionTrue,
108109
))
109110
}
111+
110112
// attempt an upgrade whenever the clustermanager's bundleVersion changes
111113
upgrade, err := hubNeedsUpgrade(ctx, fc, operatorC)
112114
if err != nil {

0 commit comments

Comments
 (0)