Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
jerry-rig custom probes into the reconciler
Browse files Browse the repository at this point in the history
Signed-off-by: Per Goncalves da Silva <[email protected]>
  • Loading branch information
Per Goncalves da Silva committed Oct 10, 2023
1 parent ac8c751 commit 390687d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
29 changes: 28 additions & 1 deletion internal/controllers/bundledeployment/bundledeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"github.com/operator-framework/rukpak/internal/probing"

Check failure on line 8 in internal/controllers/bundledeployment/bundledeployment.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed with -local github.com/operator-framework/rukpak (goimports)
"io"
"strings"
"sync"
Expand Down Expand Up @@ -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) {

Check failure on line 374 in internal/controllers/bundledeployment/bundledeployment.go

View workflow job for this annotation

GitHub Actions / lint

`if features.RukpakFeatureGate.Enabled(features.BundleDeploymentHealth)` has complex nested blocks (complexity: 5) (nestif)
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,
Expand Down
4 changes: 2 additions & 2 deletions internal/probing/cel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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(),
Expand Down

0 comments on commit 390687d

Please sign in to comment.