diff --git a/internal/controllers/bundledeployment/bundledeployment.go b/internal/controllers/bundledeployment/bundledeployment.go index 39bdb2ec..4be977c2 100644 --- a/internal/controllers/bundledeployment/bundledeployment.go +++ b/internal/controllers/bundledeployment/bundledeployment.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "github.com/operator-framework/rukpak/internal/probing" "io" "strings" "sync" @@ -371,7 +372,33 @@ func (c *controller) reconcile(ctx context.Context, bd *rukpakv1alpha1.BundleDep bd.Status.ActiveBundle = bundle.GetName() if features.RukpakFeatureGate.Enabled(features.BundleDeploymentHealth) { - if err = healthchecks.AreObjectsHealthy(ctx, c.cl, relObjects); err != nil { + doit := func() error { + probe, err := probing.Parse(ctx, bd.Spec.AvailabilityProbes) + if err != nil { + log.FromContext(ctx).V(1).Info("failed to parse probes - using default health-check", "error", err) + return healthchecks.AreObjectsHealthy(ctx, c.cl, relObjects) + } + + var probeSuccess = true + var messages []string + for _, obj := range relObjects { + unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj) + if err != nil { + return err + } + success, message := probe.Probe(&unstructured.Unstructured{Object: unstructuredObj}) + probeSuccess = probeSuccess && success + if !success { + messages = append(messages, message) + } + } + if !probeSuccess { + return errors.New(strings.Join(messages, ", ")) + } + return nil + } + + if err = doit(); err != nil { meta.SetStatusCondition(&bd.Status.Conditions, metav1.Condition{ Type: rukpakv1alpha1.TypeHealthy, Status: metav1.ConditionFalse, diff --git a/internal/probing/cel.go b/internal/probing/cel.go index 3a028a95..392b54b7 100644 --- a/internal/probing/cel.go +++ b/internal/probing/cel.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/google/cel-go/cel" - "github.com/google/cel-go/ext" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apiserver/pkg/cel/library" ) @@ -25,7 +24,8 @@ func newCELProbe(rule, message string) (*celProbe, error) { cel.EagerlyValidateDeclarations(true), cel.DefaultUTCTimeZone(true), - ext.Strings(ext.StringsVersion(0)), + // TODO: this doesn't exist in the working version of the cel library + // ext.Strings(ext.StringsVersion(0)), library.URLs(), library.Regex(), library.Lists(),