github.com/verrazzano/verrazzano@v1.7.0/platform-operator/controllers/secrets/install_override_secret.go (about) 1 // Copyright (c) 2022, 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package secrets 5 6 import ( 7 "context" 8 9 installv1alpha1 "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1alpha1" 10 "github.com/verrazzano/verrazzano/platform-operator/constants" 11 "github.com/verrazzano/verrazzano/platform-operator/controllers" 12 "github.com/verrazzano/verrazzano/platform-operator/controllers/verrazzano/component/spi" 13 "go.uber.org/zap" 14 corev1 "k8s.io/api/core/v1" 15 "k8s.io/apimachinery/pkg/api/errors" 16 ctrl "sigs.k8s.io/controller-runtime" 17 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" 18 "sigs.k8s.io/controller-runtime/pkg/reconcile" 19 ) 20 21 // reconcileInstallOverrideSecret looks through the Verrazzano CR for the Secret 22 // if the request is from the same namespace as the CR 23 func (r *VerrazzanoSecretsReconciler) reconcileInstallOverrideSecret(ctx context.Context, req ctrl.Request, vz *installv1alpha1.Verrazzano) (ctrl.Result, error) { 24 25 secret := &corev1.Secret{} 26 if vz.Namespace == req.Namespace { 27 // Get the secret if the request namespace matches verrazzano namespace 28 if err := r.Get(ctx, req.NamespacedName, secret); err != nil { 29 // Do not retry if secret is deleted 30 if errors.IsNotFound(err) { 31 if err := controllers.ProcDeletedOverride(r.StatusUpdater, r.Client, vz, req.Name, constants.SecretKind); err != nil { 32 // Do not return an error as it's most likely due to timing 33 return newRequeueWithDelay(), nil 34 } 35 return reconcile.Result{}, nil 36 } 37 zap.S().Errorf("Failed to fetch Secret in Verrazzano CR namespace: %v", err) 38 return newRequeueWithDelay(), err 39 } 40 41 if result, err := r.initLogger(req.NamespacedName, secret); err != nil { 42 return result, err 43 } 44 45 componentCtx, err := spi.NewContext(r.log, r.Client, vz, nil, false) 46 if err != nil { 47 r.log.Errorf("Failed to construct component context: %v", err) 48 return newRequeueWithDelay(), err 49 } 50 51 if componentName, ok := controllers.VzContainsResource(componentCtx, secret.Name, secret.Kind); ok { 52 if secret.DeletionTimestamp.IsZero() { 53 54 // Add finalizer if not added 55 if !controllerutil.ContainsFinalizer(secret, constants.OverridesFinalizer) { 56 secret.Finalizers = append(secret.Finalizers, constants.OverridesFinalizer) 57 err := r.Update(context.TODO(), secret) 58 if err != nil { 59 return newRequeueWithDelay(), nil 60 } 61 return reconcile.Result{Requeue: true}, nil 62 } 63 64 } else { 65 // Requeue as other finalizers haven't been removed 66 if secret.Finalizers != nil && !controllerutil.ContainsFinalizer(secret, constants.OverridesFinalizer) { 67 return reconcile.Result{Requeue: true}, nil 68 } 69 70 controllerutil.RemoveFinalizer(secret, constants.OverridesFinalizer) 71 err := r.Update(context.TODO(), secret) 72 if err != nil { 73 return newRequeueWithDelay(), err 74 } 75 } 76 77 err := controllers.UpdateVerrazzanoForInstallOverrides(r.StatusUpdater, componentCtx, componentName) 78 if err != nil { 79 r.log.ErrorfThrottled("Failed to reconcile Secret: %v", err) 80 return newRequeueWithDelay(), err 81 } 82 r.log.Infof("Updated Verrazzano Resource") 83 } 84 } 85 return ctrl.Result{}, nil 86 }