Skip to content

Commit 0028f1d

Browse files
Merge pull request #383 from leelavg/approve-ip
controllers: approve all installplans ocs-client-operator namespace
2 parents 42a9ed0 + e925fd6 commit 0028f1d

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

bundle/manifests/ocs-client-operator.clusterserviceversion.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
categories: Storage
88
console.openshift.io/plugins: '["odf-client-console"]'
99
containerImage: quay.io/ocs-dev/ocs-client-operator:latest
10-
createdAt: "2025-09-03T10:30:43Z"
10+
createdAt: "2025-09-15T05:45:11Z"
1111
description: OpenShift Data Foundation client operator enables consumption of
1212
storage services from a remote centralized OpenShift Data Foundation provider
1313
cluster.
@@ -313,6 +313,15 @@ spec:
313313
- get
314314
- list
315315
- watch
316+
- apiGroups:
317+
- operators.coreos.com
318+
resources:
319+
- installplans
320+
verbs:
321+
- get
322+
- list
323+
- patch
324+
- watch
316325
- apiGroups:
317326
- operators.coreos.com
318327
resources:

config/rbac/role.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,15 @@ rules:
274274
- get
275275
- list
276276
- watch
277+
- apiGroups:
278+
- operators.coreos.com
279+
resources:
280+
- installplans
281+
verbs:
282+
- get
283+
- list
284+
- patch
285+
- watch
277286
- apiGroups:
278287
- operators.coreos.com
279288
resources:

internal/controller/operatorconfigmap_controller.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const (
7272
clusterVersionName = "version"
7373
manageNoobaaSubKey = "manageNoobaaSubscription"
7474
disableVersionChecksKey = "disableVersionChecks"
75+
disableInstallPlanAutoApprovalKey = "disableInstallPlanAutoApproval"
7576
subscriptionLabelKey = "managed-by"
7677
subscriptionLabelValue = "webhook.subscription.ocs.openshift.io"
7778
generateRbdOMapInfoKey = "generateRbdOMapInfo"
@@ -184,6 +185,18 @@ func (c *OperatorConfigMapReconciler) SetupWithManager(mgr ctrl.Manager) error {
184185
builder.OnlyMetadata,
185186
).
186187
Watches(&opv1a1.Subscription{}, enqueueConfigMapRequest, subscriptionPredicates).
188+
Watches(
189+
&opv1a1.InstallPlan{},
190+
enqueueConfigMapRequest,
191+
builder.WithPredicates(
192+
utils.EventTypePredicate(
193+
true,
194+
false,
195+
false,
196+
false,
197+
),
198+
),
199+
).
187200
Watches(&admrv1.ValidatingWebhookConfiguration{}, enqueueConfigMapRequest, webhookPredicates).
188201
Watches(&v1alpha1.StorageClient{}, enqueueConfigMapRequest, builder.WithPredicates(predicate.AnnotationChangedPredicate{}))
189202

@@ -213,6 +226,7 @@ func (c *OperatorConfigMapReconciler) SetupWithManager(mgr ctrl.Manager) error {
213226
//+kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update;patch;delete
214227
//+kubebuilder:rbac:groups=console.openshift.io,resources=consoleplugins,verbs=*
215228
//+kubebuilder:rbac:groups=operators.coreos.com,resources=subscriptions,verbs=get;list;watch;update;delete
229+
//+kubebuilder:rbac:groups=operators.coreos.com,resources=installplans,verbs=get;list;watch;patch
216230
//+kubebuilder:rbac:groups=operators.coreos.com,resources=clusterserviceversions,verbs=delete;list
217231
//+kubebuilder:rbac:groups=admissionregistration.k8s.io,resources=validatingwebhookconfigurations,verbs=get;list;update;create;watch;delete
218232
//+kubebuilder:rbac:groups=csi.ceph.io,resources=operatorconfigs,verbs=get;list;update;create;watch;delete
@@ -342,6 +356,13 @@ func (c *OperatorConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Re
342356
return ctrl.Result{}, err
343357
}
344358

359+
if c.shouldAutoApproveInstallPlans() {
360+
if err := c.reconcileInstallPlans(); err != nil {
361+
c.log.Error(err, "unable to reconcile InstallPlans")
362+
return ctrl.Result{}, err
363+
}
364+
}
365+
345366
if err := c.ensureConsolePlugin(); err != nil {
346367
c.log.Error(err, "unable to deploy client console")
347368
return ctrl.Result{}, err
@@ -386,6 +407,38 @@ func (c *OperatorConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Re
386407
return ctrl.Result{}, nil
387408
}
388409

410+
func (c *OperatorConfigMapReconciler) shouldAutoApproveInstallPlans() bool {
411+
valueAsString, exist := c.operatorConfigMap.Data[disableInstallPlanAutoApprovalKey]
412+
if !exist {
413+
return true
414+
}
415+
416+
disableInstallPlanAutoApproval, err := strconv.ParseBool(valueAsString)
417+
if err != nil {
418+
c.log.Error(err, "failed to parse configmap key data", "key", disableInstallPlanAutoApprovalKey)
419+
return true
420+
}
421+
422+
return !disableInstallPlanAutoApproval
423+
}
424+
425+
func (c *OperatorConfigMapReconciler) reconcileInstallPlans() error {
426+
approvePatch := client.RawPatch(types.MergePatchType, []byte(`{"spec":{"approved":true}}`))
427+
installPlans := &opv1a1.InstallPlanList{}
428+
if err := c.list(installPlans, client.InNamespace(c.OperatorNamespace)); err != nil {
429+
return err
430+
}
431+
for idx := range installPlans.Items {
432+
installPlan := &installPlans.Items[idx]
433+
if !installPlan.Spec.Approved {
434+
if err := c.Patch(c.ctx, installPlan, approvePatch); err != nil {
435+
return err
436+
}
437+
}
438+
}
439+
return nil
440+
}
441+
389442
func (c *OperatorConfigMapReconciler) errorOnRookOwnedCsi() error {
390443
rookManagedCsiObjects := []struct {
391444
gvk schema.GroupVersionKind

0 commit comments

Comments
 (0)