Skip to content

Commit

Permalink
Merge pull request #54 from banzaicloud/precondition-error
Browse files Browse the repository at this point in the history
Use custom error for checking preconditions
  • Loading branch information
pbalogh-sa authored Feb 11, 2021
2 parents bb74394 + 6cdb622 commit a53c2f0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pkg/helm/templatereconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/banzaicloud/operator-tools/pkg/resources"
"github.com/banzaicloud/operator-tools/pkg/types"
"github.com/go-logr/logr"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/discovery"
controllerruntime "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -66,6 +66,14 @@ type HelmReconciler struct {
objectParser *resources.ObjectParser
}

type preConditionsFatalErr struct {
error
}

func NewPreConditionsFatalErr(err error) error {
return &preConditionsFatalErr{err}
}

func NewHelmReconciler(
client client.Client,
scheme *runtime.Scheme,
Expand Down Expand Up @@ -102,13 +110,21 @@ func (rec *HelmReconciler) Reconcile(object runtime.Object, component Component)

if component.Enabled(object) {
if err := component.PreChecks(object); err != nil {
if preCondErr, ok := err.(*preConditionsFatalErr); ok {
if err := component.UpdateStatus(object, types.ReconcileStatusFailed, preCondErr.Error()); err != nil {
rec.logger.Error(err, "status update failed")
}

return nil, preCondErr
}
if err := component.UpdateStatus(object, types.ReconcileStatusReconciling, "waiting for precondition checks to pass"); err != nil {
rec.logger.Error(err, "status update failed")
}
rec.logger.Error(err, "precondition checks failed")
return &reconcile.Result{
RequeueAfter: time.Second * 5,
}, nil

}
}

Expand Down

0 comments on commit a53c2f0

Please sign in to comment.