Skip to content

Commit 34464e4

Browse files
authored
Improve error handling and update to ResourceVersionChangedPredicate for OperandRequest controller (#1179)
* Improve error handling for OperandRegistry notFound case Signed-off-by: Daniel Fan <[email protected]> * update to ResourceVersionChangedPredicate in OperandRequest controllers Signed-off-by: Daniel Fan <[email protected]> * Add operatorsv1 to scheme in namespace scope tests Signed-off-by: Daniel Fan <[email protected]> --------- Signed-off-by: Daniel Fan <[email protected]>
1 parent 66fcb5c commit 34464e4

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

controllers/namespacescope/namespacescope_suite_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/onsi/gomega/gexec"
2929
olmv1 "github.com/operator-framework/api/pkg/operators/v1"
3030
olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
31+
operatorsv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
3132
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3233
"k8s.io/client-go/rest"
3334
ctrl "sigs.k8s.io/controller-runtime"
@@ -95,6 +96,8 @@ var _ = BeforeSuite(func(ctx SpecContext) {
9596
Expect(err).NotTo(HaveOccurred())
9697
err = jaegerv1.AddToScheme(clientgoscheme.Scheme)
9798
Expect(err).NotTo(HaveOccurred())
99+
err = operatorsv1.AddToScheme(clientgoscheme.Scheme)
100+
Expect(err).NotTo(HaveOccurred())
98101

99102
k8sClient, err = client.New(cfg, client.Options{Scheme: clientgoscheme.Scheme})
100103
Expect(err).ToNot(HaveOccurred())

controllers/operandrequest/operandrequest_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
181181

182182
// Check if all csv deploy succeed
183183
if requestInstance.Status.Phase != operatorv1alpha1.ClusterPhaseRunning {
184-
klog.V(2).Info("Waiting for all operators and operands to be deployed successfully ...")
184+
klog.Info("Waiting for all operators and operands to be deployed successfully ...")
185185
return ctrl.Result{RequeueAfter: constant.DefaultRequeueDuration}, nil
186186
}
187187

@@ -406,7 +406,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
406406
}
407407
return ctrl.NewControllerManagedBy(mgr).
408408
WithOptions(options).
409-
For(&operatorv1alpha1.OperandRequest{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
409+
For(&operatorv1alpha1.OperandRequest{}, builder.WithPredicates(predicate.ResourceVersionChangedPredicate{})).
410410
Watches(&olmv1alpha1.Subscription{}, handler.EnqueueRequestsFromMapFunc(r.getSubToRequestMapper), builder.WithPredicates(predicate.Funcs{
411411
UpdateFunc: func(e event.UpdateEvent) bool {
412412
oldObject := e.ObjectOld.(*olmv1alpha1.Subscription)

controllers/operandrequest/reconcile_operator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (r *Reconciler) reconcileOperator(ctx context.Context, requestInstance *ope
8585
return utilerrors.NewAggregate([]error{err, patchErr})
8686
}
8787
klog.Errorf("Failed to get suitable OperandRegistry %s: %v", registryKey.String(), err)
88+
return utilerrors.NewAggregate([]error{err, fmt.Errorf("failed to get suitable OperandRegistry %s", registryKey.String())})
8889
}
8990
merr := &util.MultiErr{}
9091

controllers/operandrequestnoolm/operandrequestnoolm_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
179179
//TODO update this block to check deployments and their operands instead
180180
// Check if all csv deploy succeed
181181
if requestInstance.Status.Phase != operatorv1alpha1.ClusterPhaseRunning {
182-
klog.V(2).Info("Waiting for all operators and operands to be deployed successfully ...")
182+
klog.Info("Waiting for all operators and operands to be deployed successfully ...")
183183
return ctrl.Result{RequeueAfter: constant.DefaultRequeueDuration}, nil
184184
}
185185

@@ -351,7 +351,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
351351
}
352352
return ctrl.NewControllerManagedBy(mgr).
353353
WithOptions(options).
354-
For(&operatorv1alpha1.OperandRequest{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
354+
For(&operatorv1alpha1.OperandRequest{}, builder.WithPredicates(predicate.ResourceVersionChangedPredicate{})).
355355
Watches(&corev1.ConfigMap{}, handler.EnqueueRequestsFromMapFunc(r.getReferenceToRequestMapper), builder.WithPredicates(predicate.Funcs{
356356
UpdateFunc: func(e event.UpdateEvent) bool {
357357
oldObject := e.ObjectOld.(*corev1.ConfigMap)

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ require (
1919
github.com/stretchr/testify v1.9.0
2020
golang.org/x/mod v0.17.0
2121
k8s.io/api v0.28.2
22-
k8s.io/apiextensions-apiserver v0.28.2
2322
k8s.io/apimachinery v0.28.2
2423
k8s.io/client-go v0.28.2
2524
k8s.io/klog v1.0.0
2625
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
2726
sigs.k8s.io/controller-runtime v0.16.1
2827
)
2928

29+
require k8s.io/apiextensions-apiserver v0.28.2 // indirect
30+
3031
require (
3132
github.com/Shopify/logrus-bugsnag v0.0.0-20240507214313-004243a594f4 // indirect
3233
github.com/beorn7/perks v1.0.1 // indirect

0 commit comments

Comments
 (0)