Skip to content

Commit

Permalink
Requeue addon for deps not installed error (keikoproj#91)
Browse files Browse the repository at this point in the history
Continously requeue an addon when it has validation failed for "required dependency not installed" error

Signed-off-by: Kevin D <[email protected]>
  • Loading branch information
kevdowney authored Jul 16, 2021
1 parent fd1dabc commit 657bf88
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
18 changes: 16 additions & 2 deletions controllers/addon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,34 @@ func (r *AddonReconciler) processAddon(ctx context.Context, log logr.Logger, ins
// Validate Addon
if ok, err := addon.NewAddonValidator(instance, r.versionCache, r.dynClient).Validate(); !ok {
// if an addons dependency is in a Pending state then make the parent addon Pending
if strings.HasPrefix(err.Error(), addon.ErrDepPending) {
if err != nil && strings.HasPrefix(err.Error(), addon.ErrDepPending) {
reason := fmt.Sprintf("Addon %s/%s is waiting on dependencies to be out of Pending state.", instance.Namespace, instance.Name)
// Record an event if addon is not valid
r.recorder.Event(instance, "Normal", "Pending", reason)
instance.Status.Lifecycle.Installed = addonmgrv1alpha1.Pending
instance.Status.Reason = reason

log.Info("Addon %s/%s is waiting on dependencies to be out of Pending state.", instance.Namespace, instance.Name)
log.Info(reason)

// requeue after 10 seconds
return reconcile.Result{
Requeue: true,
RequeueAfter: 10 * time.Second,
}, nil
} else if err != nil && strings.HasPrefix(err.Error(), addon.ErrDepNotInstalled) {
reason := fmt.Sprintf("Addon %s/%s is waiting on dependencies to be installed. %v", instance.Namespace, instance.Name, err)
// Record an event if addon is not valid
r.recorder.Event(instance, "Normal", "Failed", reason)
instance.Status.Lifecycle.Installed = addonmgrv1alpha1.ValidationFailed
instance.Status.Reason = reason

log.Info(reason)

// requeue after 30 seconds
return reconcile.Result{
Requeue: true,
RequeueAfter: 30 * time.Second,
}, nil
}

reason := fmt.Sprintf("Addon %s/%s is not valid. %v", instance.Namespace, instance.Name, err)
Expand Down
2 changes: 1 addition & 1 deletion controllers/addon_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ var _ = Describe("AddonController", func() {
}

return fmt.Errorf("addon-2 is not valid")
}, timeout*2).Should(Succeed())
}, timeout*10).Should(Succeed())
})

})
Expand Down
6 changes: 3 additions & 3 deletions pkg/addon/addon_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (av *addonValidator) validateDependencies() error {
// Ignore version
versions := av.cache.GetVersions(pkgName)
if versions == nil {
return fmt.Errorf("required dependency %s is not installed", pkgName)
return fmt.Errorf(ErrDepNotInstalled+": %q", pkgName)
}

// Look for any successfully installed version
Expand All @@ -195,7 +195,7 @@ func (av *addonValidator) validateDependencies() error {
}

if !versionFound {
return fmt.Errorf("required dependency %s has no valid versions installed", pkgName)
return fmt.Errorf(ErrDepNotInstalled+": %q has no valid versions installed", pkgName)
}
} else {
// Check for specific version
Expand Down Expand Up @@ -238,7 +238,7 @@ func (av *addonValidator) resolveDependencies(n *Version, visited map[string]*Ve
v := av.cache.GetVersion(pkgName, pkgVersion)
if v == nil {
// Unresolvable dependency
return fmt.Errorf("unable to resolve required dependency %s:%s", pkgName, pkgVersion)
return fmt.Errorf(ErrDepNotInstalled+": unable to resolve required dependency %s:%s", pkgName, pkgVersion)
}

// Validate it resolves without cyclic dependency
Expand Down
2 changes: 1 addition & 1 deletion pkg/addon/addon_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func Test_addonValidator_Validate_With_Installed_Deps(t *testing.T) {
Namespace: "addon-test-ns",
},
},
}}, want: false, wantErr: true, errStartsWith: "unable to resolve required dependency"},
}}, want: false, wantErr: true, errStartsWith: "required dependency is not installed: unable to resolve required dependency"},
{name: "addon-throws-error-for-dependencies-in-pending-state", fields: fields{addon: &addonmgrv1alpha1.Addon{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"},
Spec: addonmgrv1alpha1.AddonSpec{
Expand Down

0 comments on commit 657bf88

Please sign in to comment.