@@ -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+
389443func (c * OperatorConfigMapReconciler ) errorOnRookOwnedCsi () error {
390444 rookManagedCsiObjects := []struct {
391445 gvk schema.GroupVersionKind
0 commit comments