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