Skip to content

Commit 1ac15a7

Browse files
committed
controllers: approve all installplans ocs-client-operator namespace
this also depends on locking all the dependencies to an exact version which will be changed in d/s. Signed-off-by: Leela Venkaiah G <lgangava@ibm.com>
1 parent a1f0dde commit 1ac15a7

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ spec:
304304
- get
305305
- list
306306
- watch
307+
- apiGroups:
308+
- operators.coreos.com
309+
resources:
310+
- installplans
311+
verbs:
312+
- get
313+
- list
314+
- patch
315+
- watch
307316
- apiGroups:
308317
- operators.coreos.com
309318
resources:

config/rbac/role.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ rules:
265265
- get
266266
- list
267267
- watch
268+
- apiGroups:
269+
- operators.coreos.com
270+
resources:
271+
- installplans
272+
verbs:
273+
- get
274+
- list
275+
- patch
276+
- watch
268277
- apiGroups:
269278
- operators.coreos.com
270279
resources:

internal/controller/operatorconfigmap_controller.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const (
7474
clusterVersionName = "version"
7575
manageNoobaaSubKey = "manageNoobaaSubscription"
7676
disableVersionChecksKey = "disableVersionChecks"
77+
disableInstallPlanAutoApprovalKey = "disableInstallPlanAutoApproval"
7778
subscriptionLabelKey = "managed-by"
7879
subscriptionLabelValue = "webhook.subscription.ocs.openshift.io"
7980
generateRbdOMapInfoKey = "generateRbdOMapInfo"
@@ -189,6 +190,18 @@ func (c *OperatorConfigMapReconciler) SetupWithManager(mgr ctrl.Manager) error {
189190
builder.OnlyMetadata,
190191
).
191192
Watches(&opv1a1.Subscription{}, enqueueConfigMapRequest, subscriptionPredicates).
193+
Watches(
194+
&opv1a1.InstallPlan{},
195+
enqueueConfigMapRequest,
196+
builder.WithPredicates(
197+
utils.EventTypePredicate(
198+
true,
199+
false,
200+
false,
201+
false,
202+
),
203+
),
204+
).
192205
Watches(&admrv1.ValidatingWebhookConfiguration{}, enqueueConfigMapRequest, webhookPredicates).
193206
Watches(&v1alpha1.StorageClient{}, enqueueConfigMapRequest, builder.WithPredicates(predicate.AnnotationChangedPredicate{}))
194207

@@ -219,6 +232,8 @@ func (c *OperatorConfigMapReconciler) SetupWithManager(mgr ctrl.Manager) error {
219232
//+kubebuilder:rbac:groups=console.openshift.io,resources=consoleplugins,verbs=*
220233
//+kubebuilder:rbac:groups=operators.coreos.com,resources=subscriptions,verbs=get;list;watch;update;delete
221234
//+kubebuilder:rbac:groups=operators.coreos.com,resources=clusterserviceversions,verbs=delete;list
235+
//+kubebuilder:rbac:groups=operators.coreos.com,resources=installplans,verbs=get;list;watch;patch
236+
//+kubebuilder:rbac:groups=operators.coreos.com,resources=clusterserviceversions,verbs=delete;list
222237
//+kubebuilder:rbac:groups=admissionregistration.k8s.io,resources=validatingwebhookconfigurations,verbs=get;list;update;create;watch;delete
223238
//+kubebuilder:rbac:groups=csi.ceph.io,resources=operatorconfigs,verbs=get;list;update;create;watch;delete
224239
//+kubebuilder:rbac:groups=csi.ceph.io,resources=drivers,verbs=get;list;update;create;watch;delete
@@ -342,6 +357,13 @@ func (c *OperatorConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Re
342357
return ctrl.Result{}, err
343358
}
344359

360+
if c.shouldAutoApproveInstallPlans() {
361+
if err := c.reconcileInstallPlans(); err != nil {
362+
c.log.Error(err, "unable to reconcile InstallPlans")
363+
return ctrl.Result{}, err
364+
}
365+
}
366+
345367
if err := c.ensureConsolePlugin(); err != nil {
346368
c.log.Error(err, "unable to deploy client console")
347369
return ctrl.Result{}, err
@@ -386,6 +408,38 @@ func (c *OperatorConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Re
386408
return ctrl.Result{}, nil
387409
}
388410

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

0 commit comments

Comments
 (0)