From 4b541f47a0e762e0065bd67ee5fc569f61a93322 Mon Sep 17 00:00:00 2001 From: Ben Luzarraga Date: Fri, 31 Jan 2025 14:08:47 -0600 Subject: [PATCH 01/11] refactor no olm controller code to handle deletion Signed-off-by: Ben Luzarraga --- api/v1alpha1/operandrequest_types.go | 2 + .../operandrequestnoolm_controller.go | 32 +- .../operandrequestnoolm/reconcile_operand.go | 65 --- .../operandrequestnoolm/reconcile_operator.go | 415 ++++++------------ controllers/operator/manager.go | 84 ++++ 5 files changed, 239 insertions(+), 359 deletions(-) diff --git a/api/v1alpha1/operandrequest_types.go b/api/v1alpha1/operandrequest_types.go index 717e49ac..0ddc839d 100644 --- a/api/v1alpha1/operandrequest_types.go +++ b/api/v1alpha1/operandrequest_types.go @@ -131,6 +131,8 @@ const ( ResourceTypeCsv ResourceType = "csv" ResourceTypeOperator ResourceType = "operator" ResourceTypeOperand ResourceType = "operands" + ResourceTypeConfigmap ResourceType = "configmap" + ResourceTypeDeployment ResourceType = "deployment" ) // Condition represents the current state of the Request Service. diff --git a/controllers/operandrequestnoolm/operandrequestnoolm_controller.go b/controllers/operandrequestnoolm/operandrequestnoolm_controller.go index 86b7d1ad..a3d582ed 100644 --- a/controllers/operandrequestnoolm/operandrequestnoolm_controller.go +++ b/controllers/operandrequestnoolm/operandrequestnoolm_controller.go @@ -26,7 +26,6 @@ import ( "time" gset "github.com/deckarep/golang-set" - olmv1 "github.com/operator-framework/api/pkg/operators/v1" olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" "github.com/pkg/errors" authorizationv1 "k8s.io/api/authorization/v1" @@ -56,9 +55,8 @@ type Reconciler struct { Mutex sync.Mutex } type clusterObjects struct { - namespace *corev1.Namespace - operatorGroup *olmv1.OperatorGroup - subscription *olmv1alpha1.Subscription + namespace *corev1.Namespace + configmap *corev1.ConfigMap } //+kubebuilder:rbac:groups=operator.ibm.com,resources=certmanagers;auditloggings,verbs=get;delete @@ -114,13 +112,13 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re // Remove finalizer when DeletionTimestamp none zero if !requestInstance.ObjectMeta.DeletionTimestamp.IsZero() { - //TODO determine if necessary - // Check and clean up the subscriptions - // err := r.checkFinalizer(ctx, requestInstance) - // if err != nil { - // klog.Errorf("failed to clean up the subscriptions for OperandRequest %s: %v", req.NamespacedName.String(), err) - // return ctrl.Result{}, err - // } + //Checkfinalizers calls the delete function, not necessarily subscription based + //Check and clean up the operands + err := r.checkFinalizer(ctx, requestInstance) + if err != nil { + klog.Errorf("failed to clean up the operands for OperandRequest %s: %v", req.NamespacedName.String(), err) + return ctrl.Result{}, err + } originalReq := requestInstance.DeepCopy() // Update finalizer to allow delete CR @@ -163,12 +161,13 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re return ctrl.Result{Requeue: true}, err } - // TODO remove this section + // TODO this section is likely where we need to put in opreq cleanup logic. + //Many of the cleanup functions are run through reconcileoperator as of 1/31/25 // Reconcile Operators - // if err := r.reconcileOperator(ctx, requestInstance); err != nil { - // klog.Errorf("failed to reconcile Operators for OperandRequest %s: %v", req.NamespacedName.String(), err) - // return ctrl.Result{}, err - // } + if err := r.reconcileOperator(ctx, requestInstance); err != nil { + klog.Errorf("failed to reconcile Operators for OperandRequest %s: %v", req.NamespacedName.String(), err) + return ctrl.Result{}, err + } // Reconcile Operands if merr := r.reconcileOperand(ctx, requestInstance); len(merr.Errors) != 0 { @@ -176,6 +175,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re return ctrl.Result{}, merr } + //TODO update this block to check deployments and their operands instead // Check if all csv deploy succeed if requestInstance.Status.Phase != operatorv1alpha1.ClusterPhaseRunning { klog.V(2).Info("Waiting for all operators and operands to be deployed successfully ...") diff --git a/controllers/operandrequestnoolm/reconcile_operand.go b/controllers/operandrequestnoolm/reconcile_operand.go index 2fe2a9bf..3ac4cdf2 100644 --- a/controllers/operandrequestnoolm/reconcile_operand.go +++ b/controllers/operandrequestnoolm/reconcile_operand.go @@ -97,55 +97,8 @@ func (r *Reconciler) reconcileOperand(ctx context.Context, requestInstance *oper // Looking for the CSV namespace := r.GetOperatorNamespace(opdRegistry.InstallMode, opdRegistry.Namespace) - //TODO remove this section - // sub, err := r.GetSubscription(ctx, operatorName, namespace, registryInstance.Namespace, opdRegistry.PackageName) - // if err != nil { - // merr.Add(errors.Wrapf(err, "failed to get the Subscription %s in the namespace %s and %s", operatorName, namespace, registryInstance.Namespace)) - // return merr - // } - - // if !opdRegistry.UserManaged { - // if sub == nil { - // klog.Warningf("There is no Subscription %s or %s in the namespace %s and %s", operatorName, opdRegistry.PackageName, namespace, registryInstance.Namespace) - // continue - // } - - // if _, ok := sub.Labels[constant.OpreqLabel]; !ok { - // // Subscription existing and not managed by OperandRequest controller - // klog.Warningf("Subscription %s in the namespace %s isn't created by ODLM", sub.Name, sub.Namespace) - // } - - // // It the installplan is not created yet, ODLM will try later - // if sub.Status.Install == nil || sub.Status.InstallPlanRef.Name == "" { - // klog.Warningf("The Installplan for Subscription %s is not ready. Will check it again", sub.Name) - // requestInstance.SetMemberStatus(operand.Name, operatorv1alpha1.OperatorInstalling, "", &r.Mutex) - // continue - // } - - // // If the installplan is deleted after is completed, ODLM won't block the CR update. - // ipName := sub.Status.InstallPlanRef.Name - // ipNamespace := sub.Namespace - // ip := &olmv1alpha1.InstallPlan{} - // ipKey := types.NamespacedName{ - // Name: ipName, - // Namespace: ipNamespace, - // } - // if err := r.Client.Get(ctx, ipKey, ip); err != nil { - // if !apierrors.IsNotFound(err) { - // merr.Add(errors.Wrapf(err, "failed to get Installplan")) - // } - // } else if ip.Status.Phase == olmv1alpha1.InstallPlanPhaseFailed { - // klog.Errorf("installplan %s/%s is failed", ipNamespace, ipName) - // requestInstance.SetMemberStatus(operand.Name, operatorv1alpha1.OperatorFailed, "", &r.Mutex) - // continue - // } - - // } - - //var csv *olmv1alpha1.ClusterServiceVersion var deployment *appsv1.Deployment - //TODO need to translate this if block to look for deployments and not CSVs deploymentList, err := r.GetDeploymentListFromPackage(ctx, opdRegistry.PackageName, opdRegistry.Namespace) if err != nil { merr.Add(err) @@ -154,7 +107,6 @@ func (r *Reconciler) reconcileOperand(ctx context.Context, requestInstance *oper } deployment = deploymentList[0] - //TODO change this block to deal with an empty list of deployments instead of csvs if deployment == nil { klog.Warningf("Deployment for %s in the namespace %s is not ready yet, retry", operatorName, namespace) requestInstance.SetMemberStatus(operand.Name, operatorv1alpha1.OperatorInstalling, "", &r.Mutex) @@ -169,19 +121,6 @@ func (r *Reconciler) reconcileOperand(ctx context.Context, requestInstance *oper // continue // } - //TODO git rid of this section - // if !opdRegistry.UserManaged { - // // find the OperandRequest which has the same operator's channel or fallback channels as existing subscription. - // // ODLM will only reconcile Operand based on OperandConfig for this OperandRequest - // channels := []string{opdRegistry.Channel} - // if channels = append(channels, opdRegistry.FallbackChannels...); !util.Contains(channels, sub.Spec.Channel) { - // klog.Infof("Subscription %s in the namespace %s is NOT managed by %s/%s, Skip reconciling Operands", sub.Name, sub.Namespace, requestInstance.Namespace, requestInstance.Name) - // requestInstance.SetMemberStatus(operand.Name, operatorv1alpha1.OperatorFailed, "", &r.Mutex) - // continue - // } - // } - - //TODO update to deployment name klog.V(3).Info("Generating customresource base on Deployment: ", deployment.GetName()) requestInstance.SetMemberStatus(operand.Name, operatorv1alpha1.OperatorRunning, "", &r.Mutex) @@ -195,7 +134,6 @@ func (r *Reconciler) reconcileOperand(ctx context.Context, requestInstance *oper klog.V(2).Infof("There is no service: %s from the OperandConfig instance: %s/%s, Skip reconciling Operands", operand.Name, registryKey.Namespace, req.Registry) continue } - //TODO pass through deployment values here err = r.reconcileCRwithConfig(ctx, opdConfig, configInstance.Name, configInstance.Namespace, deployment, requestInstance, operand.Name, deployment.Namespace, &r.Mutex) if err != nil { merr.Add(err) @@ -263,7 +201,6 @@ func (r *Reconciler) reconcileCRwithConfig(ctx context.Context, service *operato } } - //TODO change this to deployment, make sure GetAnnotations works for deployments the same way almExamples := deployment.GetAnnotations()["alm-examples"] // Convert CR template string to slice @@ -320,7 +257,6 @@ func (r *Reconciler) reconcileCRwithConfig(ctx context.Context, service *operato } if !foundInConfig { - //TODO change to deployment klog.Warningf("%v in the alm-example doesn't exist in the OperandConfig for %v", crFromALM.GetKind(), deployment.GetName()) continue } @@ -365,7 +301,6 @@ func (r *Reconciler) reconcileCRwithConfig(ctx context.Context, service *operato for cr, found := range foundMap { if !found { - //TODO change to deployment klog.Warningf("Custom resource %v doesn't exist in the alm-example of %v", cr, deployment.GetName()) } } diff --git a/controllers/operandrequestnoolm/reconcile_operator.go b/controllers/operandrequestnoolm/reconcile_operator.go index 96e94a8b..16fa36a1 100644 --- a/controllers/operandrequestnoolm/reconcile_operator.go +++ b/controllers/operandrequestnoolm/reconcile_operator.go @@ -26,10 +26,6 @@ import ( "time" gset "github.com/deckarep/golang-set" - olmv1 "github.com/operator-framework/api/pkg/operators/v1" - olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" - "github.com/pkg/errors" - "golang.org/x/mod/semver" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -95,7 +91,7 @@ func (r *Reconciler) reconcileOperator(ctx context.Context, requestInstance *ope chunkSize = 1 } - // reconcile subscription in batch + // reconcile tracking configmaps in batch for i := 0; i < len(req.Operands); i += chunkSize { j := i + chunkSize if j > len(req.Operands) { @@ -108,7 +104,7 @@ func (r *Reconciler) reconcileOperator(ctx context.Context, requestInstance *ope wg.Add(1) go func(ctx context.Context, requestInstance *operatorv1alpha1.OperandRequest, registryInstance *operatorv1alpha1.OperandRegistry, operand operatorv1alpha1.Operand, registryKey types.NamespacedName, mu *sync.Mutex) { defer wg.Done() - if err := r.reconcileSubscription(ctx, requestInstance, registryInstance, operand, registryKey, mu); err != nil { + if err := r.reconcileOpReqCM(ctx, requestInstance, registryInstance, operand, registryKey, mu); err != nil { mu.Lock() defer mu.Unlock() merr.Add(err) @@ -132,12 +128,13 @@ func (r *Reconciler) reconcileOperator(ctx context.Context, requestInstance *ope return nil } -func (r *Reconciler) reconcileSubscription(ctx context.Context, requestInstance *operatorv1alpha1.OperandRequest, registryInstance *operatorv1alpha1.OperandRegistry, operand operatorv1alpha1.Operand, registryKey types.NamespacedName, mu sync.Locker) error { +// In No olm installs, we create empty configmaps that house the annotations ODLM looks for when cleaning up operators once an opreq is deleted +func (r *Reconciler) reconcileOpReqCM(ctx context.Context, requestInstance *operatorv1alpha1.OperandRequest, registryInstance *operatorv1alpha1.OperandRegistry, operand operatorv1alpha1.Operand, registryKey types.NamespacedName, mu sync.Locker) error { // Check the requested Operand if exist in specific OperandRegistry var opt *operatorv1alpha1.Operator if registryInstance != nil { var err error - opt, err = r.GetOperandFromRegistry(ctx, registryInstance, operand.Name) + opt, err = r.GetOperandFromRegistryNoOLM(ctx, registryInstance, operand.Name) if err != nil { return err } @@ -156,30 +153,17 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, requestInstance return nil } - // Check subscription if exist + // Check configmap if exist namespace := r.GetOperatorNamespace(opt.InstallMode, opt.Namespace) - sub, err := r.GetSubscription(ctx, opt.Name, namespace, registryInstance.Namespace, opt.PackageName) + cm, err := r.GetOpReqCM(ctx, opt.Name, namespace, registryInstance.Namespace, opt.PackageName) - if opt.UserManaged { - klog.Infof("Skip installing operator %s because it is managed by user", opt.PackageName) - csvList, err := r.GetClusterServiceVersionListFromPackage(ctx, opt.PackageName, namespace) - if err != nil { - return errors.Wrapf(err, "failed to get CSV from package %s/%s", namespace, opt.PackageName) - } - if len(csvList) == 0 { - return errors.New("operator " + opt.Name + " is user managed, but no CSV exists, waiting...") - } - requestInstance.SetMemberStatus(opt.Name, operatorv1alpha1.OperatorUpdating, "", mu) - return nil - } - - if sub == nil && err == nil { + if cm == nil && err == nil { if opt.InstallMode == operatorv1alpha1.InstallModeNoop { requestInstance.SetNoSuitableRegistryCondition(registryKey.String(), opt.Name+" is in maintenance status", operatorv1alpha1.ResourceTypeOperandRegistry, corev1.ConditionTrue, &r.Mutex) requestInstance.SetMemberStatus(operand.Name, operatorv1alpha1.OperatorRunning, operatorv1alpha1.ServiceRunning, mu) } else { - // Subscription does not exist, create a new one - if err = r.createSubscription(ctx, requestInstance, opt, registryKey); err != nil { + // CM does not exist, create a new one + if err = r.createOpReqCM(ctx, requestInstance, opt, registryKey); err != nil { requestInstance.SetMemberStatus(opt.Name, operatorv1alpha1.OperatorFailed, "", mu) return err } @@ -190,30 +174,27 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, requestInstance return err } - // Subscription existing and managed by OperandRequest controller - if _, ok := sub.Labels[constant.OpreqLabel]; ok { - originalSub := sub.DeepCopy() - var isMatchedChannel bool + // Operator existing and managed by OperandRequest controller + if _, ok := cm.Labels[constant.OpreqLabel]; ok { + originalCM := cm.DeepCopy() var isInScope bool - if sub.Namespace == opt.Namespace { + if cm.Namespace == opt.Namespace { isInScope = true } else { var nsAnnoSlice []string namespaceReg, _ := regexp.Compile(`^(.*)\.(.*)\.(.*)\/operatorNamespace`) - for anno, ns := range sub.Annotations { + for anno, ns := range cm.Annotations { if namespaceReg.MatchString(anno) { nsAnnoSlice = append(nsAnnoSlice, ns) } } - if len(nsAnnoSlice) != 0 && !util.Contains(nsAnnoSlice, sub.Namespace) { - - if r.checkUninstallLabel(sub) { + if len(nsAnnoSlice) != 0 && !util.Contains(nsAnnoSlice, cm.Namespace) { + if r.checkUninstallLabel(cm) { klog.V(1).Infof("Operator %s has label operator.ibm.com/opreq-do-not-uninstall. Skip the uninstall", opt.Name) return nil } - - if err = r.deleteSubscription(ctx, requestInstance, sub); err != nil { + if err = r.deleteOpReqCM(ctx, requestInstance, cm); err != nil { requestInstance.SetMemberStatus(opt.Name, operatorv1alpha1.OperatorFailed, "", mu) return err } @@ -222,66 +203,30 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, requestInstance } } - // add annotations to existing Subscriptions for upgrade case - if sub.Annotations == nil { - sub.Annotations = make(map[string]string) + // add annotations to existing tracking configmap for upgrade case + if cm.Annotations == nil { + cm.Annotations = make(map[string]string) } - sub.Annotations[registryKey.Namespace+"."+registryKey.Name+"/registry"] = "true" - sub.Annotations[registryKey.Namespace+"."+registryKey.Name+"/config"] = "true" - sub.Annotations[requestInstance.Namespace+"."+requestInstance.Name+"."+operand.Name+"/request"] = opt.Channel - sub.Annotations[requestInstance.Namespace+"."+requestInstance.Name+"."+operand.Name+"/operatorNamespace"] = namespace + cm.Annotations[registryKey.Namespace+"."+registryKey.Name+"/registry"] = "true" + cm.Annotations[registryKey.Namespace+"."+registryKey.Name+"/config"] = "true" + cm.Annotations[requestInstance.Namespace+"."+requestInstance.Name+"."+operand.Name+"/request"] = opt.Channel + cm.Annotations[requestInstance.Namespace+"."+requestInstance.Name+"."+operand.Name+"/operatorNamespace"] = namespace if opt.InstallMode == operatorv1alpha1.InstallModeNoop { - isMatchedChannel = true requestInstance.SetNoSuitableRegistryCondition(registryKey.String(), opt.Name+" is in maintenance status", operatorv1alpha1.ResourceTypeOperandRegistry, corev1.ConditionTrue, &r.Mutex) requestInstance.SetMemberStatus(operand.Name, operatorv1alpha1.OperatorRunning, operatorv1alpha1.ServiceRunning, mu) - - // check if sub.Spec.Channel and opt.Channel are valid semantic version - // set annotation channel back to previous one if sub.Spec.Channel is lower than opt.Channel - // To avoid upgrade from one maintenance version to another maintenance version like from v3 to v3.23 - subChanel := util.FindSemantic(sub.Spec.Channel) - optChannel := util.FindSemantic(opt.Channel) - if semver.IsValid(subChanel) && semver.IsValid(optChannel) && semver.Compare(subChanel, optChannel) < 0 { - sub.Annotations[requestInstance.Namespace+"."+requestInstance.Name+"."+operand.Name+"/request"] = sub.Spec.Channel - } - } else if opt.SourceNamespace == "" || opt.SourceName == "" { - klog.Errorf("Failed to find catalogsource for operator %s with channel %s", opt.Name, opt.Channel) - requestInstance.SetMemberStatus(operand.Name, operatorv1alpha1.OperatorFailed, "", mu) } else { - requestInstance.SetNotFoundOperatorFromRegistryCondition(operand.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionFalse, mu) - - if minChannel := util.FindMinSemverFromAnnotations(sub.Annotations, sub.Spec.Channel); minChannel != "" { - sub.Spec.Channel = minChannel - } - - channels := []string{opt.Channel} - if channels = append(channels, opt.FallbackChannels...); util.Contains(channels, sub.Spec.Channel) { - isMatchedChannel = true - } - // update the spec iff channel in sub matches channel - if sub.Spec.Channel == opt.Channel { - sub.Spec.CatalogSource = opt.SourceName - sub.Spec.CatalogSourceNamespace = opt.SourceNamespace - sub.Spec.Package = opt.PackageName - - if opt.InstallPlanApproval != "" && sub.Spec.InstallPlanApproval != opt.InstallPlanApproval { - sub.Spec.InstallPlanApproval = opt.InstallPlanApproval - } - if opt.SubscriptionConfig != nil { - sub.Spec.Config = opt.SubscriptionConfig - } - } - + requestInstance.SetNotFoundOperatorFromRegistryCondition(operand.Name, operatorv1alpha1.ResourceTypeConfigmap, corev1.ConditionFalse, mu) } - if compareSub(sub, originalSub) { - if err = r.updateSubscription(ctx, requestInstance, sub); err != nil { + if compareOpReqCM(cm, originalCM) { + if err = r.updateOpReqCM(ctx, requestInstance, cm); err != nil { requestInstance.SetMemberStatus(opt.Name, operatorv1alpha1.OperatorFailed, "", mu) return err } requestInstance.SetMemberStatus(opt.Name, operatorv1alpha1.OperatorUpdating, "", mu) } - if !isMatchedChannel || !isInScope { + if !isInScope { requestInstance.SetNoConflictOperatorCondition(operand.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionFalse, mu) requestInstance.SetMemberStatus(opt.Name, operatorv1alpha1.OperatorFailed, "", mu) } else { @@ -289,14 +234,14 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, requestInstance } } else { // Subscription existing and not managed by OperandRequest controller - klog.V(1).Infof("Subscription %s in namespace %s isn't created by ODLM. Ignore update/delete it.", sub.Name, sub.Namespace) + klog.V(1).Infof("Configmap %s in namespace %s isn't created by ODLM. Ignore update/delete it.", cm.Name, cm.Namespace) } return nil } -func (r *Reconciler) createSubscription(ctx context.Context, cr *operatorv1alpha1.OperandRequest, opt *operatorv1alpha1.Operator, key types.NamespacedName) error { +func (r *Reconciler) createOpReqCM(ctx context.Context, cr *operatorv1alpha1.OperandRequest, opt *operatorv1alpha1.Operator, key types.NamespacedName) error { namespace := r.GetOperatorNamespace(opt.InstallMode, opt.Namespace) - klog.V(3).Info("Subscription Namespace: ", namespace) + klog.V(3).Info("Cofigmap Namespace: ", namespace) co := r.generateClusterObjects(opt, key, types.NamespacedName{Namespace: cr.Namespace, Name: cr.Name}) @@ -312,188 +257,135 @@ func (r *Reconciler) createSubscription(ctx context.Context, cr *operatorv1alpha } } - if namespace != constant.ClusterOperatorNamespace { - // Create required operatorgroup - existOG := &olmv1.OperatorGroupList{} - if err := r.Client.List(ctx, existOG, &client.ListOptions{Namespace: co.operatorGroup.Namespace}); err != nil { - return err - } - if len(existOG.Items) == 0 { - og := co.operatorGroup - klog.V(3).Info("Creating the OperatorGroup for Subscription: " + opt.Name) - if err := r.Create(ctx, og); err != nil && !apierrors.IsAlreadyExists(err) { - return err - } - } - } - - // Create subscription - klog.V(2).Info("Creating the Subscription: " + opt.Name) - if co.subscription.Spec.CatalogSource == "" || co.subscription.Spec.CatalogSourceNamespace == "" { - return fmt.Errorf("failed to find catalogsource for subscription %s/%s", co.subscription.Namespace, co.subscription.Name) - } + // Create CM + klog.V(2).Info("Creating the Configmap: " + opt.Name) - sub := co.subscription - cr.SetCreatingCondition(sub.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionTrue, &r.Mutex) + cm := co.configmap + cr.SetCreatingCondition(cm.Name, operatorv1alpha1.ResourceTypeConfigmap, corev1.ConditionTrue, &r.Mutex) - if err := r.Create(ctx, sub); err != nil && !apierrors.IsAlreadyExists(err) { - cr.SetCreatingCondition(sub.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionFalse, &r.Mutex) + if err := r.Create(ctx, cm); err != nil && !apierrors.IsAlreadyExists(err) { + cr.SetCreatingCondition(cm.Name, operatorv1alpha1.ResourceTypeConfigmap, corev1.ConditionFalse, &r.Mutex) return err } return nil } -func (r *Reconciler) updateSubscription(ctx context.Context, cr *operatorv1alpha1.OperandRequest, sub *olmv1alpha1.Subscription) error { +func (r *Reconciler) deleteOpReqCM(ctx context.Context, cr *operatorv1alpha1.OperandRequest, cm *corev1.ConfigMap) error { - klog.V(2).Infof("Updating Subscription %s/%s ...", sub.Namespace, sub.Name) - cr.SetUpdatingCondition(sub.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionTrue, &r.Mutex) + klog.V(2).Infof("Deleting Subscription %s/%s ...", cm.Namespace, cm.Name) - if err := r.Update(ctx, sub); err != nil { - cr.SetUpdatingCondition(sub.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionFalse, &r.Mutex) - return err + klog.V(2).Infof("Deleting the Configmap, Namespace: %s, Name: %s", cm.Namespace, cm.Name) + cr.SetDeletingCondition(cm.Name, operatorv1alpha1.ResourceTypeConfigmap, corev1.ConditionTrue, &r.Mutex) + + if err := r.Delete(ctx, cm); err != nil { + if apierrors.IsNotFound(err) { + klog.Warningf("Configmap %s was not found in namespace %s", cm.Name, cm.Namespace) + } else { + cr.SetDeletingCondition(cm.Name, operatorv1alpha1.ResourceTypeConfigmap, corev1.ConditionFalse, &r.Mutex) + return err + } } + + klog.V(1).Infof("Configmap %s/%s is deleted", cm.Namespace, cm.Name) return nil } -func (r *Reconciler) deleteSubscription(ctx context.Context, cr *operatorv1alpha1.OperandRequest, sub *olmv1alpha1.Subscription) error { +func (r *Reconciler) updateOpReqCM(ctx context.Context, cr *operatorv1alpha1.OperandRequest, cm *corev1.ConfigMap) error { - klog.V(2).Infof("Deleting Subscription %s/%s ...", sub.Namespace, sub.Name) + klog.V(2).Infof("Updating Configmap %s/%s ...", cm.Namespace, cm.Name) + cr.SetUpdatingCondition(cm.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionTrue, &r.Mutex) - csvList, err := r.GetClusterServiceVersionList(ctx, sub) - // If can't get CSV, requeue the request - if err != nil { + if err := r.Update(ctx, cm); err != nil { + cr.SetUpdatingCondition(cm.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionFalse, &r.Mutex) return err } - - if csvList != nil { - klog.Infof("Found %d ClusterServiceVersions for Subscription %s/%s", len(csvList), sub.Namespace, sub.Name) - for _, csv := range csvList { - klog.V(3).Info("Set Deleting Condition in the operandRequest") - cr.SetDeletingCondition(csv.Name, operatorv1alpha1.ResourceTypeCsv, corev1.ConditionTrue, &r.Mutex) - - klog.V(1).Infof("Deleting the ClusterServiceVersion, Namespace: %s, Name: %s", csv.Namespace, csv.Name) - if err := r.Delete(ctx, csv); err != nil { - cr.SetDeletingCondition(csv.Name, operatorv1alpha1.ResourceTypeCsv, corev1.ConditionFalse, &r.Mutex) - return err - } - } - } - - klog.V(2).Infof("Deleting the Subscription, Namespace: %s, Name: %s", sub.Namespace, sub.Name) - cr.SetDeletingCondition(sub.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionTrue, &r.Mutex) - - if err := r.Delete(ctx, sub); err != nil { - if apierrors.IsNotFound(err) { - klog.Warningf("Subscription %s was not found in namespace %s", sub.Name, sub.Namespace) - } else { - cr.SetDeletingCondition(sub.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionFalse, &r.Mutex) - return err - } - } - - klog.V(1).Infof("Subscription %s/%s is deleted", sub.Namespace, sub.Name) return nil } func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandName string, requestInstance *operatorv1alpha1.OperandRequest, registryInstance *operatorv1alpha1.OperandRegistry, configInstance *operatorv1alpha1.OperandConfig) error { // No error handling for un-installation step in case Catalog has been deleted - op, _ := r.GetOperandFromRegistry(ctx, registryInstance, operandName) + op, _ := r.GetOperandFromRegistryNoOLM(ctx, registryInstance, operandName) if op == nil { klog.Warningf("Operand %s not found", operandName) return nil } namespace := r.GetOperatorNamespace(op.InstallMode, op.Namespace) - sub, err := r.GetSubscription(ctx, operandName, namespace, registryInstance.Namespace, op.PackageName) - if sub == nil && err == nil { - klog.V(3).Infof("There is no Subscription %s or %s in the namespace %s and %s", operandName, op.PackageName, namespace, registryInstance.Namespace) + + //Assuing we can still use op as a parameter, we should be able to get the deployment with ease + deploy, err := r.GetDeployment(ctx, operandName, namespace, registryInstance.Namespace, op.PackageName) + if deploy == nil && err == nil { + klog.V(3).Infof("There is no Deployment called %s or using package name %s in the namespace %s and %s", operandName, op.PackageName, namespace, registryInstance.Namespace) return nil } else if err != nil { - klog.Errorf("Failed to get Subscription %s or %s in the namespace %s and %s", operandName, op.PackageName, namespace, registryInstance.Namespace) + klog.Errorf("Failed to get Deployment called %s or using package name %s in the namespace %s and %s", operandName, op.PackageName, namespace, registryInstance.Namespace) return err } - if sub.Labels == nil { + if deploy.Labels == nil { // Subscription existing and not managed by OperandRequest controller - klog.V(2).Infof("Subscription %s in the namespace %s isn't created by ODLM", sub.Name, sub.Namespace) + klog.V(2).Infof("Deployment %s in the namespace %s isn't created by ODLM", deploy.Name, deploy.Namespace) return nil } - if _, ok := sub.Labels[constant.OpreqLabel]; !ok { + if _, ok := deploy.Labels[constant.OpreqLabel]; !ok { if !op.UserManaged { - klog.V(2).Infof("Subscription %s in the namespace %s isn't created by ODLM and isn't user managed", sub.Name, sub.Namespace) + klog.V(2).Infof("Deployment %s in the namespace %s isn't created by ODLM and isn't user managed", deploy.Name, deploy.Namespace) return nil } } - uninstallOperator, uninstallOperand := checkSubAnnotationsForUninstall(requestInstance.ObjectMeta.Name, requestInstance.ObjectMeta.Namespace, op.Name, op.InstallMode, sub) - if !uninstallOperand && !uninstallOperator { - if err = r.updateSubscription(ctx, requestInstance, sub); err != nil { - requestInstance.SetMemberStatus(op.Name, operatorv1alpha1.OperatorFailed, "", &r.Mutex) - return err - } - requestInstance.SetMemberStatus(op.Name, operatorv1alpha1.OperatorUpdating, "", &r.Mutex) - - klog.V(1).Infof("No deletion, subscription %s/%s and its operands are still requested by other OperandRequests", sub.Namespace, sub.Name) - return nil - } - - if deploymentList, err := r.GetDeploymentListFromPackage(ctx, op.PackageName, op.Namespace); err != nil { - // If can't get deployment, requeue the request - return err - } else if deploymentList != nil { - klog.Infof("Found %d Deployment for package %s/%s", len(deploymentList), op.Name, namespace) - if uninstallOperand { - klog.V(2).Infof("Deleting all the Custom Resources for Deployment, Namespace: %s, Name: %s", deploymentList[0].Namespace, deploymentList[0].Name) - if err := r.deleteAllCustomResource(ctx, deploymentList[0], requestInstance, configInstance, operandName, configInstance.Namespace); err != nil { - return err - } - klog.V(2).Infof("Deleting all the k8s Resources for Deployment, Namespace: %s, Name: %s", deploymentList[0].Namespace, deploymentList[0].Name) - if err := r.deleteAllK8sResource(ctx, configInstance, operandName, configInstance.Namespace); err != nil { + cm, err := r.GetOpReqCM(ctx, op.Name, deploy.Namespace, registryInstance.Namespace, op.PackageName) + if cm != nil && err == nil { + uninstallOperator, uninstallOperand := checkOpReqCMAnnotationsForUninstall(requestInstance.ObjectMeta.Name, requestInstance.ObjectMeta.Namespace, op.Name, op.InstallMode, cm) + if !uninstallOperand && !uninstallOperator { + if err = r.updateOpReqCM(ctx, requestInstance, cm); err != nil { + requestInstance.SetMemberStatus(op.Name, operatorv1alpha1.OperatorFailed, "", &r.Mutex) return err } - } - if uninstallOperator { - if r.checkUninstallLabel(sub) { - klog.V(1).Infof("Operator %s has label operator.ibm.com/opreq-do-not-uninstall. Skip the uninstall", op.Name) - return nil - } + requestInstance.SetMemberStatus(op.Name, operatorv1alpha1.OperatorUpdating, "", &r.Mutex) - klog.V(3).Info("Set Deleting Condition in the operandRequest") - //TODO replace the resource types set in these setdeletingcondition functions - requestInstance.SetDeletingCondition(deploymentList[0].Name, operatorv1alpha1.ResourceTypeCsv, corev1.ConditionTrue, &r.Mutex) - - for _, deployment := range deploymentList { - klog.V(1).Infof("Deleting the deployment, Namespace: %s, Name: %s", deployment.Namespace, deployment.Name) - if err := r.Delete(ctx, deployment); err != nil { - requestInstance.SetDeletingCondition(deployment.Name, operatorv1alpha1.ResourceTypeCsv, corev1.ConditionFalse, &r.Mutex) - return errors.Wrapf(err, "failed to delete the deployment %s/%s", deployment.Namespace, deployment.Name) - } - } - } - } - - if uninstallOperator { - klog.V(2).Infof("Deleting the Subscription, Namespace: %s, Name: %s", namespace, op.Name) - requestInstance.SetDeletingCondition(op.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionTrue, &r.Mutex) - - if err := r.Delete(ctx, sub); err != nil { - if apierrors.IsNotFound(err) { - klog.Warningf("Subscription %s was not found in namespace %s", op.Name, namespace) - } else { - requestInstance.SetDeletingCondition(op.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionFalse, &r.Mutex) - return errors.Wrap(err, "failed to delete subscription") - } + klog.V(1).Infof("No deletion, operator %s/%s and its operands are still requested by other OperandRequests", cm.Namespace, cm.Name) + return nil } - - klog.V(1).Infof("Subscription %s/%s is deleted", namespace, op.Name) - } else { - if err = r.updateSubscription(ctx, requestInstance, sub); err != nil { - requestInstance.SetMemberStatus(op.Name, operatorv1alpha1.OperatorFailed, "", &r.Mutex) + if deploymentList, err := r.GetDeploymentListFromPackage(ctx, op.PackageName, op.Namespace); err != nil { + // If can't get deployment, requeue the request return err + } else if deploymentList != nil { + klog.Infof("Found %d Deployment for package %s/%s", len(deploymentList), op.Name, namespace) + if uninstallOperand { + klog.V(2).Infof("Deleting all the Custom Resources for Deployment, Namespace: %s, Name: %s", deploymentList[0].Namespace, deploymentList[0].Name) + if err := r.deleteAllCustomResource(ctx, deploymentList[0], requestInstance, configInstance, operandName, configInstance.Namespace); err != nil { + return err + } + klog.V(2).Infof("Deleting all the k8s Resources for Deployment, Namespace: %s, Name: %s", deploymentList[0].Namespace, deploymentList[0].Name) + if err := r.deleteAllK8sResource(ctx, configInstance, operandName, configInstance.Namespace); err != nil { + return err + } + } + //TODO should odlm delete deployments or should that be handled by helm? + // if uninstallOperator { + // if r.checkUninstallLabel(cm) { + // klog.V(1).Infof("Operator %s has label operator.ibm.com/opreq-do-not-uninstall. Skip the uninstall", op.Name) + // return nil + // } + + // klog.V(3).Info("Set Deleting Condition in the operandRequest") + // //TODO replace the resource types set in these setdeletingcondition functions + // requestInstance.SetDeletingCondition(deploymentList[0].Name, operatorv1alpha1.ResourceTypeDeployment, corev1.ConditionTrue, &r.Mutex) + + // for _, deployment := range deploymentList { + // klog.V(1).Infof("Deleting the deployment, Namespace: %s, Name: %s", deployment.Namespace, deployment.Name) + // if err := r.Delete(ctx, deployment); err != nil { + // requestInstance.SetDeletingCondition(deployment.Name, operatorv1alpha1.ResourceTypeDeployment, corev1.ConditionFalse, &r.Mutex) + // return errors.Wrapf(err, "failed to delete the deployment %s/%s", deployment.Namespace, deployment.Name) + // } + // } + // } } - requestInstance.SetMemberStatus(op.Name, operatorv1alpha1.OperatorUpdating, "", &r.Mutex) - klog.V(1).Infof("Subscription %s/%s is not deleted due to the annotation from OperandRequest", namespace, op.Name) + } else if err != nil { + klog.Errorf("Failed to get Configmap called %s or using package name %s in the namespace %s and %s", operandName, op.PackageName, namespace, registryInstance.Namespace) + return err } return nil @@ -501,7 +393,7 @@ func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandN func (r *Reconciler) uninstallOperands(ctx context.Context, operandName string, requestInstance *operatorv1alpha1.OperandRequest, registryInstance *operatorv1alpha1.OperandRegistry, configInstance *operatorv1alpha1.OperandConfig) error { // No error handling for un-installation step in case Catalog has been deleted - op, _ := r.GetOperandFromRegistry(ctx, registryInstance, operandName) + op, _ := r.GetOperandFromRegistryNoOLM(ctx, registryInstance, operandName) if op == nil { klog.Warningf("Operand %s not found", operandName) return nil @@ -577,11 +469,13 @@ func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInst wg.Add(1) go func() { defer wg.Done() - op, _ := r.GetOperandFromRegistry(ctx, registryInstance, fmt.Sprintf("%v", o)) + op, _ := r.GetOperandFromRegistryNoOLM(ctx, registryInstance, fmt.Sprintf("%v", o)) if op == nil { klog.Warningf("Operand %s not found", fmt.Sprintf("%v", o)) } if op != nil && !op.UserManaged { + //TODO do we need to uninstall operators and operands? Should the user uninstall operators with helm uninstall going forward? + //The below function currently does not delete operators if err := r.uninstallOperatorsAndOperands(ctx, fmt.Sprintf("%v", o), requestInstance, registryInstance, configInstance); err != nil { r.Mutex.Lock() defer r.Mutex.Unlock() @@ -653,11 +547,6 @@ func (r *Reconciler) generateClusterObjects(o *operatorv1alpha1.Operator, regist }, } - // Operator Group Object - klog.V(3).Info("Generating Operator Group in the Namespace: ", o.Namespace, " with target namespace: ", o.TargetNamespaces) - og := generateOperatorGroup(o.Namespace, o.TargetNamespaces) - co.operatorGroup = og - // The namespace is 'openshift-operators' when installMode is cluster namespace := r.GetOperatorNamespace(o.InstallMode, o.Namespace) @@ -668,60 +557,30 @@ func (r *Reconciler) generateClusterObjects(o *operatorv1alpha1.Operator, regist requestKey.Namespace + "." + requestKey.Name + "." + o.Name + "/operatorNamespace": namespace, } - // Subscription Object - sub := &olmv1alpha1.Subscription{ + //CM object + cm := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: o.PackageName, Namespace: namespace, Labels: labels, Annotations: annotations, }, - Spec: &olmv1alpha1.SubscriptionSpec{ - Channel: o.Channel, - Package: o.PackageName, - CatalogSource: o.SourceName, - CatalogSourceNamespace: o.SourceNamespace, - InstallPlanApproval: o.InstallPlanApproval, - StartingCSV: o.StartingCSV, - Config: o.SubscriptionConfig, - }, + Data: map[string]string{}, } - sub.SetGroupVersionKind(schema.GroupVersionKind{Group: olmv1alpha1.SchemeGroupVersion.Group, Kind: "Subscription", Version: olmv1alpha1.SchemeGroupVersion.Version}) - klog.V(3).Info("Generating Subscription: ", o.PackageName, " in the Namespace: ", namespace) - co.subscription = sub - return co -} - -func generateOperatorGroup(namespace string, targetNamespaces []string) *olmv1.OperatorGroup { - labels := map[string]string{ - constant.OpreqLabel: "true", - } - if targetNamespaces == nil { - targetNamespaces = append(targetNamespaces, namespace) - } - // Operator Group Object - og := &olmv1.OperatorGroup{ - ObjectMeta: metav1.ObjectMeta{ - Name: "operand-deployment-lifecycle-manager-operatorgroup", - Namespace: namespace, - Labels: labels, - }, - Spec: olmv1.OperatorGroupSpec{ - TargetNamespaces: targetNamespaces, - }, - } - og.SetGroupVersionKind(schema.GroupVersionKind{Group: olmv1.SchemeGroupVersion.Group, Kind: "OperatorGroup", Version: olmv1.SchemeGroupVersion.Version}) - return og + cm.SetGroupVersionKind(schema.GroupVersionKind{Group: corev1.SchemeGroupVersion.Group, Kind: "Configmap", Version: corev1.SchemeGroupVersion.Version}) + klog.V(3).Info("Generating Configmap: ", o.PackageName, " in the Namespace: ", namespace) + co.configmap = cm + return co } -func (r *Reconciler) checkUninstallLabel(sub *olmv1alpha1.Subscription) bool { - subLabels := sub.GetLabels() - return subLabels[constant.NotUninstallLabel] == "true" +func (r *Reconciler) checkUninstallLabel(cm *corev1.ConfigMap) bool { + cmLabels := cm.GetLabels() + return cmLabels[constant.NotUninstallLabel] == "true" } -func compareSub(sub *olmv1alpha1.Subscription, originalSub *olmv1alpha1.Subscription) (needUpdate bool) { - return !equality.Semantic.DeepEqual(sub.Spec, originalSub.Spec) || !equality.Semantic.DeepEqual(sub.Annotations, originalSub.Annotations) +func compareOpReqCM(cm *corev1.ConfigMap, originalCM *corev1.ConfigMap) (needUpdate bool) { + return !equality.Semantic.DeepEqual(cm.Annotations, originalCM.Annotations) } func CheckSingletonServices(operator string) bool { @@ -729,26 +588,26 @@ func CheckSingletonServices(operator string) bool { return util.Contains(singletonServices, operator) } -// checkSubAnnotationsForUninstall checks the annotations of a Subscription object +// checkOpReqCMAnnotationsForUninstall checks the annotations of a tracking configmap object // to determine whether the operator and operand should be uninstalled. // It takes the name of the OperandRequest, the namespace of the OperandRequest, -// the name of the operator, and a pointer to the Subscription object as input. +// the name of the operator, and a pointer to the configmap object as input. // It returns two boolean values: uninstallOperator and uninstallOperand. // If uninstallOperator is true, it means the operator should be uninstalled. // If uninstallOperand is true, it means the operand should be uninstalled. -func checkSubAnnotationsForUninstall(reqName, reqNs, opName, installMode string, sub *olmv1alpha1.Subscription) (bool, bool) { +func checkOpReqCMAnnotationsForUninstall(reqName, reqNs, opName, installMode string, cm *corev1.ConfigMap) (bool, bool) { uninstallOperator := true uninstallOperand := true - delete(sub.Annotations, reqNs+"."+reqName+"."+opName+"/request") - delete(sub.Annotations, reqNs+"."+reqName+"."+opName+"/operatorNamespace") + delete(cm.Annotations, reqNs+"."+reqName+"."+opName+"/request") + delete(cm.Annotations, reqNs+"."+reqName+"."+opName+"/operatorNamespace") var opreqNsSlice []string var operatorNameSlice []string namespaceReg, _ := regexp.Compile(`^(.*)\.(.*)\.(.*)\/operatorNamespace`) channelReg, _ := regexp.Compile(`^(.*)\.(.*)\.(.*)\/request`) - for key, value := range sub.Annotations { + for key, value := range cm.Annotations { if namespaceReg.MatchString(key) { opreqNsSlice = append(opreqNsSlice, value) } @@ -763,11 +622,11 @@ func checkSubAnnotationsForUninstall(reqName, reqNs, opName, installMode string, // If one of remaining /operatorNamespace annotations' values is the same as subscription's namespace, // the operator should NOT be uninstalled. - if util.Contains(opreqNsSlice, sub.Namespace) { + if util.Contains(opreqNsSlice, cm.Namespace) { uninstallOperator = false } - if value, ok := sub.Labels[constant.OpreqLabel]; !ok || value != "true" { + if value, ok := cm.Labels[constant.OpreqLabel]; !ok || value != "true" { uninstallOperator = false } diff --git a/controllers/operator/manager.go b/controllers/operator/manager.go index cfbadb4d..8ab5e673 100644 --- a/controllers/operator/manager.go +++ b/controllers/operator/manager.go @@ -462,6 +462,82 @@ func (m *ODLMOperator) GetSubscription(ctx context.Context, name, operatorNs, se return &subCandidates[0], nil } +// GetDeployment gets Deployment by name and package name +func (m *ODLMOperator) GetDeployment(ctx context.Context, name, operatorNs, servicesNs, packageName string) (*appsv1.Deployment, error) { + klog.V(3).Infof("Fetch Deployment %s (package name: %s) in operatorNamespace %s and servicesNamespace %s", name, packageName, operatorNs, servicesNs) + + tenantScope := make(map[string]struct{}) + for _, ns := range []string{operatorNs, servicesNs} { + tenantScope[ns] = struct{}{} + } + + var depCandidates []appsv1.Deployment + for ns := range tenantScope { + depList := &appsv1.DeploymentList{} + if err := m.Client.List(ctx, depList, &client.ListOptions{ + Namespace: ns, + }); err != nil { + return nil, err + } + + for _, dep := range depList.Items { + if dep.Name == name || dep.Annotations["packageName"] == packageName { + depCandidates = append(depCandidates, dep) + } + } + } + + if len(depCandidates) == 0 { + return nil, nil + } + + if len(depCandidates) > 1 { + return nil, fmt.Errorf("there are multiple deployments using package %v", packageName) + } + + return &depCandidates[0], nil +} + +func (m *ODLMOperator) GetOpReqCM(ctx context.Context, name, operatorNs, servicesNs, packageName string) (*corev1.ConfigMap, error) { + klog.V(3).Infof("Fetch tracking configmap %s in operatorNamespace %s and servicesNamespace %s", name, operatorNs, servicesNs) + + tenantScope := make(map[string]struct{}) + for _, ns := range []string{operatorNs, servicesNs} { + tenantScope[ns] = struct{}{} + } + + var cmCandidates []corev1.ConfigMap + for ns := range tenantScope { + cmList := &corev1.ConfigMapList{} + if err := m.Client.List(ctx, cmList, &client.ListOptions{ + Namespace: ns, + }); err != nil { + return nil, err + } + + // for _, sub := range subList.Items { + // if sub.Name == name || sub.Spec.Package == packageName { + // subCandidates = append(subCandidates, sub) + // } + // } + for _, cm := range cmList.Items { + if cm.Name == packageName { + cmCandidates = append(cmCandidates, cm) + } + } + } + + if len(cmCandidates) == 0 { + return nil, nil + } + + if len(cmCandidates) > 1 { + return nil, fmt.Errorf("there are multiple subscriptions using package %v", packageName) + } + + return &cmCandidates[0], nil +} + // GetClusterServiceVersion gets the ClusterServiceVersion from the subscription func (m *ODLMOperator) GetClusterServiceVersion(ctx context.Context, sub *olmv1alpha1.Subscription) (*olmv1alpha1.ClusterServiceVersion, error) { // Check if subscription is nil @@ -699,6 +775,14 @@ func (m *ODLMOperator) GetOperandFromRegistry(ctx context.Context, reg *apiv1alp return opt, nil } +func (m *ODLMOperator) GetOperandFromRegistryNoOLM(ctx context.Context, reg *apiv1alpha1.OperandRegistry, operandName string) (*apiv1alpha1.Operator, error) { + opt := reg.GetOperator(operandName) + if opt == nil { + return nil, nil + } + return opt, nil +} + func (m *ODLMOperator) CheckLabel(unstruct unstructured.Unstructured, labels map[string]string) bool { for k, v := range labels { if !m.HasLabel(unstruct, k) { From d2a618526502e20a3610da9e8211a5114d08e024 Mon Sep 17 00:00:00 2001 From: Ben Luzarraga Date: Fri, 31 Jan 2025 14:19:45 -0600 Subject: [PATCH 02/11] cleanup Signed-off-by: Ben Luzarraga --- .../operandrequestnoolm_controller.go | 19 +++---------------- .../operandrequestnoolm/reconcile_operator.go | 2 +- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/controllers/operandrequestnoolm/operandrequestnoolm_controller.go b/controllers/operandrequestnoolm/operandrequestnoolm_controller.go index a3d582ed..31026802 100644 --- a/controllers/operandrequestnoolm/operandrequestnoolm_controller.go +++ b/controllers/operandrequestnoolm/operandrequestnoolm_controller.go @@ -161,8 +161,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re return ctrl.Result{Requeue: true}, err } - // TODO this section is likely where we need to put in opreq cleanup logic. - //Many of the cleanup functions are run through reconcileoperator as of 1/31/25 + //Many of the cleanup functions are run through reconcileoperator as of 1.31.25 + //technically nothing is done to the operator deployment as of this writing (1.31.25) // Reconcile Operators if err := r.reconcileOperator(ctx, requestInstance); err != nil { klog.Errorf("failed to reconcile Operators for OperandRequest %s: %v", req.NamespacedName.String(), err) @@ -246,20 +246,7 @@ func (r *Reconciler) checkFinalizer(ctx context.Context, requestInstance *operat for _, m := range requestInstance.Status.Members { remainingOperands.Add(m.Name) } - // TODO: update to check OperandRequest status to see if member is user managed or not - // existingSub := &olmv1alpha1.SubscriptionList{} - - // opts := []client.ListOption{ - // client.MatchingLabels(map[string]string{constant.OpreqLabel: "true"}), - // } - - // if err := r.Client.List(ctx, existingSub, opts...); err != nil { - // return err - // } - // if len(existingSub.Items) == 0 { - // return nil - // } - // Delete all the subscriptions that created by current request + // Delete all the operands and configmaps that created by current request if err := r.absentOperatorsAndOperands(ctx, requestInstance, &remainingOperands); err != nil { return err } diff --git a/controllers/operandrequestnoolm/reconcile_operator.go b/controllers/operandrequestnoolm/reconcile_operator.go index 16fa36a1..8e5da485 100644 --- a/controllers/operandrequestnoolm/reconcile_operator.go +++ b/controllers/operandrequestnoolm/reconcile_operator.go @@ -233,7 +233,7 @@ func (r *Reconciler) reconcileOpReqCM(ctx context.Context, requestInstance *oper requestInstance.SetNoConflictOperatorCondition(operand.Name, operatorv1alpha1.ResourceTypeSub, corev1.ConditionTrue, mu) } } else { - // Subscription existing and not managed by OperandRequest controller + // Operator existing and not managed by OperandRequest controller klog.V(1).Infof("Configmap %s in namespace %s isn't created by ODLM. Ignore update/delete it.", cm.Name, cm.Namespace) } return nil From 0e2967b63137b2bf04a253ea24beaf4f09e43136 Mon Sep 17 00:00:00 2001 From: Ben Luzarraga Date: Fri, 31 Jan 2025 14:24:36 -0600 Subject: [PATCH 03/11] update build params for testing Signed-off-by: Ben Luzarraga --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e0c488cb..3e1f49b9 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ OPERATOR_VERSION ?= 4.3.9 # Kind cluster name KIND_CLUSTER_NAME ?= "odlm" # Operator image tag for test -OPERATOR_TEST_TAG ?= nolm-controller3 +OPERATOR_TEST_TAG ?= nolm-controller-cleanup # Options for 'bundle-build' ifneq ($(origin CHANNELS), undefined) From 3e360d88c9d3798ccdabefd69d761358d91c8e46 Mon Sep 17 00:00:00 2001 From: Ben Luzarraga Date: Mon, 3 Feb 2025 17:01:31 -0600 Subject: [PATCH 04/11] update controller to watch configmap changes Signed-off-by: Ben Luzarraga --- .../operandrequestnoolm_controller.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/controllers/operandrequestnoolm/operandrequestnoolm_controller.go b/controllers/operandrequestnoolm/operandrequestnoolm_controller.go index 31026802..487a3316 100644 --- a/controllers/operandrequestnoolm/operandrequestnoolm_controller.go +++ b/controllers/operandrequestnoolm/operandrequestnoolm_controller.go @@ -26,7 +26,6 @@ import ( "time" gset "github.com/deckarep/golang-set" - olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" "github.com/pkg/errors" authorizationv1 "k8s.io/api/authorization/v1" corev1 "k8s.io/api/core/v1" @@ -382,14 +381,15 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). WithOptions(options). For(&operatorv1alpha1.OperandRequest{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})). - Watches(&source.Kind{Type: &olmv1alpha1.Subscription{}}, handler.EnqueueRequestsFromMapFunc(r.getSubToRequestMapper()), builder.WithPredicates(predicate.Funcs{ + Watches(&source.Kind{Type: &corev1.ConfigMap{}}, handler.EnqueueRequestsFromMapFunc(r.getReferenceToRequestMapper()), builder.WithPredicates(predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { - oldObject := e.ObjectOld.(*olmv1alpha1.Subscription) - newObject := e.ObjectNew.(*olmv1alpha1.Subscription) + oldObject := e.ObjectOld.(*corev1.ConfigMap) + newObject := e.ObjectNew.(*corev1.ConfigMap) if oldObject.Labels != nil && oldObject.Labels[constant.OpreqLabel] == "true" { - statusToggle := (oldObject.Status.InstalledCSV != "" && newObject.Status.InstalledCSV != "" && oldObject.Status.InstalledCSV != newObject.Status.InstalledCSV) + // statusToggle := (oldObject.Status.InstalledCSV != "" && newObject.Status.InstalledCSV != "" && oldObject.Status.InstalledCSV != newObject.Status.InstalledCSV) metadataToggle := !reflect.DeepEqual(oldObject.Annotations, newObject.Annotations) - return statusToggle || metadataToggle + // return statusToggle || metadataToggle + return metadataToggle } return false }, From d680360b5702f3867a92de3033e3301b39bbf145 Mon Sep 17 00:00:00 2001 From: Ben Luzarraga Date: Mon, 3 Feb 2025 17:10:10 -0600 Subject: [PATCH 05/11] add watched by odlm label Signed-off-by: Ben Luzarraga --- controllers/operandrequestnoolm/reconcile_operator.go | 1 + 1 file changed, 1 insertion(+) diff --git a/controllers/operandrequestnoolm/reconcile_operator.go b/controllers/operandrequestnoolm/reconcile_operator.go index 8e5da485..ef1e95e5 100644 --- a/controllers/operandrequestnoolm/reconcile_operator.go +++ b/controllers/operandrequestnoolm/reconcile_operator.go @@ -211,6 +211,7 @@ func (r *Reconciler) reconcileOpReqCM(ctx context.Context, requestInstance *oper cm.Annotations[registryKey.Namespace+"."+registryKey.Name+"/config"] = "true" cm.Annotations[requestInstance.Namespace+"."+requestInstance.Name+"."+operand.Name+"/request"] = opt.Channel cm.Annotations[requestInstance.Namespace+"."+requestInstance.Name+"."+operand.Name+"/operatorNamespace"] = namespace + cm.Labels["operator.ibm.com/watched-by-odlm"] = "true" if opt.InstallMode == operatorv1alpha1.InstallModeNoop { requestInstance.SetNoSuitableRegistryCondition(registryKey.String(), opt.Name+" is in maintenance status", operatorv1alpha1.ResourceTypeOperandRegistry, corev1.ConditionTrue, &r.Mutex) From 2ffafebb64661eb9b1d933cb92a03fb17cff4104 Mon Sep 17 00:00:00 2001 From: Ben Luzarraga Date: Mon, 3 Feb 2025 17:36:02 -0600 Subject: [PATCH 06/11] add debugging statements Signed-off-by: Ben Luzarraga --- .../operandrequestnoolm/operandrequestnoolm_controller.go | 1 + controllers/operandrequestnoolm/reconcile_operator.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/controllers/operandrequestnoolm/operandrequestnoolm_controller.go b/controllers/operandrequestnoolm/operandrequestnoolm_controller.go index 487a3316..e53309cf 100644 --- a/controllers/operandrequestnoolm/operandrequestnoolm_controller.go +++ b/controllers/operandrequestnoolm/operandrequestnoolm_controller.go @@ -243,6 +243,7 @@ func (r *Reconciler) checkFinalizer(ctx context.Context, requestInstance *operat klog.V(1).Infof("Deleting OperandRequest %s in the namespace %s", requestInstance.Name, requestInstance.Namespace) remainingOperands := gset.NewSet() for _, m := range requestInstance.Status.Members { + klog.V(1).Infof("Operand %s added to deletion list", m.Name) remainingOperands.Add(m.Name) } // Delete all the operands and configmaps that created by current request diff --git a/controllers/operandrequestnoolm/reconcile_operator.go b/controllers/operandrequestnoolm/reconcile_operator.go index ef1e95e5..ea32869e 100644 --- a/controllers/operandrequestnoolm/reconcile_operator.go +++ b/controllers/operandrequestnoolm/reconcile_operator.go @@ -211,6 +211,7 @@ func (r *Reconciler) reconcileOpReqCM(ctx context.Context, requestInstance *oper cm.Annotations[registryKey.Namespace+"."+registryKey.Name+"/config"] = "true" cm.Annotations[requestInstance.Namespace+"."+requestInstance.Name+"."+operand.Name+"/request"] = opt.Channel cm.Annotations[requestInstance.Namespace+"."+requestInstance.Name+"."+operand.Name+"/operatorNamespace"] = namespace + cm.Annotations["packageName"] = opt.PackageName cm.Labels["operator.ibm.com/watched-by-odlm"] = "true" if opt.InstallMode == operatorv1alpha1.InstallModeNoop { @@ -509,7 +510,7 @@ func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInst } func (r *Reconciler) getNeedDeletedOperands(requestInstance *operatorv1alpha1.OperandRequest) gset.Set { - klog.V(3).Info("Getting the operator need to be delete") + klog.V(1).Info("Getting the operator need to be delete") deployedOperands := gset.NewSet() for _, req := range requestInstance.Status.Members { deployedOperands.Add(req.Name) @@ -519,6 +520,7 @@ func (r *Reconciler) getNeedDeletedOperands(requestInstance *operatorv1alpha1.Op if requestInstance.DeletionTimestamp.IsZero() { for _, req := range requestInstance.Spec.Requests { for _, op := range req.Operands { + klog.V(1).Info("Add current operand in getNeedDeletedOperands %s", op.Name) currentOperands.Add(op.Name) } } From 3c3b79fe7ca1b75b72bbde42e6b7d6e6c7cc063b Mon Sep 17 00:00:00 2001 From: Ben Luzarraga Date: Mon, 3 Feb 2025 17:52:16 -0600 Subject: [PATCH 07/11] more debugging logs Signed-off-by: Ben Luzarraga --- controllers/operandrequestnoolm/reconcile_operator.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/controllers/operandrequestnoolm/reconcile_operator.go b/controllers/operandrequestnoolm/reconcile_operator.go index ea32869e..1679d723 100644 --- a/controllers/operandrequestnoolm/reconcile_operator.go +++ b/controllers/operandrequestnoolm/reconcile_operator.go @@ -472,6 +472,7 @@ func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInst go func() { defer wg.Done() op, _ := r.GetOperandFromRegistryNoOLM(ctx, registryInstance, fmt.Sprintf("%v", o)) + klog.V(1).Info("op to check in absentOperatorsandOperands: ", op.Name, " o: ", fmt.Sprintf("%v", o)) if op == nil { klog.Warningf("Operand %s not found", fmt.Sprintf("%v", o)) } @@ -520,7 +521,7 @@ func (r *Reconciler) getNeedDeletedOperands(requestInstance *operatorv1alpha1.Op if requestInstance.DeletionTimestamp.IsZero() { for _, req := range requestInstance.Spec.Requests { for _, op := range req.Operands { - klog.V(1).Info("Add current operand in getNeedDeletedOperands %s", op.Name) + klog.V(1).Info("Add current operand in getNeedDeletedOperands ", op.Name) currentOperands.Add(op.Name) } } From b914f6e3b6e36b7962dfdc0e82bed6c39d2ac6a6 Mon Sep 17 00:00:00 2001 From: Ben Luzarraga Date: Mon, 3 Feb 2025 18:03:05 -0600 Subject: [PATCH 08/11] more debug statements Signed-off-by: Ben Luzarraga --- .../operandrequestnoolm/reconcile_operator.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/controllers/operandrequestnoolm/reconcile_operator.go b/controllers/operandrequestnoolm/reconcile_operator.go index 1679d723..0408a824 100644 --- a/controllers/operandrequestnoolm/reconcile_operator.go +++ b/controllers/operandrequestnoolm/reconcile_operator.go @@ -307,6 +307,7 @@ func (r *Reconciler) updateOpReqCM(ctx context.Context, cr *operatorv1alpha1.Ope func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandName string, requestInstance *operatorv1alpha1.OperandRequest, registryInstance *operatorv1alpha1.OperandRegistry, configInstance *operatorv1alpha1.OperandConfig) error { // No error handling for un-installation step in case Catalog has been deleted op, _ := r.GetOperandFromRegistryNoOLM(ctx, registryInstance, operandName) + klog.V(1).Info("op to check in uninstallOperatorsAndOperands: ", op.Name, " o: ", fmt.Sprintf("%v", operandName)) if op == nil { klog.Warningf("Operand %s not found", operandName) return nil @@ -316,8 +317,9 @@ func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandN //Assuing we can still use op as a parameter, we should be able to get the deployment with ease deploy, err := r.GetDeployment(ctx, operandName, namespace, registryInstance.Namespace, op.PackageName) + klog.V(1).Info("deployment in uninstallOperatorsAndOperands: ", deploy.Name) if deploy == nil && err == nil { - klog.V(3).Infof("There is no Deployment called %s or using package name %s in the namespace %s and %s", operandName, op.PackageName, namespace, registryInstance.Namespace) + klog.V(1).Infof("There is no Deployment called %s or using package name %s in the namespace %s and %s", operandName, op.PackageName, namespace, registryInstance.Namespace) return nil } else if err != nil { klog.Errorf("Failed to get Deployment called %s or using package name %s in the namespace %s and %s", operandName, op.PackageName, namespace, registryInstance.Namespace) @@ -326,13 +328,13 @@ func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandN if deploy.Labels == nil { // Subscription existing and not managed by OperandRequest controller - klog.V(2).Infof("Deployment %s in the namespace %s isn't created by ODLM", deploy.Name, deploy.Namespace) + klog.V(1).Infof("Deployment %s in the namespace %s isn't created by ODLM", deploy.Name, deploy.Namespace) return nil } if _, ok := deploy.Labels[constant.OpreqLabel]; !ok { if !op.UserManaged { - klog.V(2).Infof("Deployment %s in the namespace %s isn't created by ODLM and isn't user managed", deploy.Name, deploy.Namespace) + klog.V(1).Infof("Deployment %s in the namespace %s isn't created by ODLM and isn't user managed", deploy.Name, deploy.Namespace) return nil } } @@ -356,11 +358,11 @@ func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandN } else if deploymentList != nil { klog.Infof("Found %d Deployment for package %s/%s", len(deploymentList), op.Name, namespace) if uninstallOperand { - klog.V(2).Infof("Deleting all the Custom Resources for Deployment, Namespace: %s, Name: %s", deploymentList[0].Namespace, deploymentList[0].Name) + klog.V(1).Infof("Deleting all the Custom Resources for Deployment, Namespace: %s, Name: %s", deploymentList[0].Namespace, deploymentList[0].Name) if err := r.deleteAllCustomResource(ctx, deploymentList[0], requestInstance, configInstance, operandName, configInstance.Namespace); err != nil { return err } - klog.V(2).Infof("Deleting all the k8s Resources for Deployment, Namespace: %s, Name: %s", deploymentList[0].Namespace, deploymentList[0].Name) + klog.V(1).Infof("Deleting all the k8s Resources for Deployment, Namespace: %s, Name: %s", deploymentList[0].Namespace, deploymentList[0].Name) if err := r.deleteAllK8sResource(ctx, configInstance, operandName, configInstance.Namespace); err != nil { return err } @@ -496,6 +498,7 @@ func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInst requestInstance.RemoveServiceStatus(fmt.Sprintf("%v", o), &r.Mutex) (*remainingOperands).Remove(o) remainingOp.Remove(o) + klog.V(1).Info("op removed: ", op.Name, " o: ", fmt.Sprintf("%v", o)) }() } timeout := util.WaitTimeout(&wg, constant.DefaultSubDeleteTimeout) From 5a04795183d2fb998b48967684ab6a1910a3c1ab Mon Sep 17 00:00:00 2001 From: Ben Luzarraga Date: Mon, 3 Feb 2025 18:11:26 -0600 Subject: [PATCH 09/11] remove user managed condition Signed-off-by: Ben Luzarraga --- .../operandrequestnoolm/reconcile_operator.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/controllers/operandrequestnoolm/reconcile_operator.go b/controllers/operandrequestnoolm/reconcile_operator.go index 0408a824..00e827b6 100644 --- a/controllers/operandrequestnoolm/reconcile_operator.go +++ b/controllers/operandrequestnoolm/reconcile_operator.go @@ -332,12 +332,12 @@ func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandN return nil } - if _, ok := deploy.Labels[constant.OpreqLabel]; !ok { - if !op.UserManaged { - klog.V(1).Infof("Deployment %s in the namespace %s isn't created by ODLM and isn't user managed", deploy.Name, deploy.Namespace) - return nil - } - } + // if _, ok := deploy.Labels[constant.OpreqLabel]; !ok { + // if !op.UserManaged { + // klog.V(1).Infof("Deployment %s in the namespace %s isn't created by ODLM and isn't user managed", deploy.Name, deploy.Namespace) + // return nil + // } + // } cm, err := r.GetOpReqCM(ctx, op.Name, deploy.Namespace, registryInstance.Namespace, op.PackageName) if cm != nil && err == nil { From abaabf1cc14094a999bc51da4d98885db3c2bdc9 Mon Sep 17 00:00:00 2001 From: Ben Luzarraga Date: Mon, 3 Feb 2025 18:26:26 -0600 Subject: [PATCH 10/11] debug statements Signed-off-by: Ben Luzarraga --- controllers/operandrequestnoolm/reconcile_operator.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/controllers/operandrequestnoolm/reconcile_operator.go b/controllers/operandrequestnoolm/reconcile_operator.go index 00e827b6..fd4cd29a 100644 --- a/controllers/operandrequestnoolm/reconcile_operator.go +++ b/controllers/operandrequestnoolm/reconcile_operator.go @@ -340,8 +340,10 @@ func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandN // } cm, err := r.GetOpReqCM(ctx, op.Name, deploy.Namespace, registryInstance.Namespace, op.PackageName) + klog.V(1).Info("Configmap tracking operand: ", cm.Name) if cm != nil && err == nil { uninstallOperator, uninstallOperand := checkOpReqCMAnnotationsForUninstall(requestInstance.ObjectMeta.Name, requestInstance.ObjectMeta.Namespace, op.Name, op.InstallMode, cm) + klog.V(1).Info("uinstall operator: ", uninstallOperator, " uninstall operand: ", uninstallOperand) if !uninstallOperand && !uninstallOperator { if err = r.updateOpReqCM(ctx, requestInstance, cm); err != nil { requestInstance.SetMemberStatus(op.Name, operatorv1alpha1.OperatorFailed, "", &r.Mutex) @@ -538,7 +540,8 @@ func (r *Reconciler) generateClusterObjects(o *operatorv1alpha1.Operator, regist klog.V(3).Info("Generating Cluster Objects") co := &clusterObjects{} labels := map[string]string{ - constant.OpreqLabel: "true", + constant.OpreqLabel: "true", + "operator.ibm.com/watched-by-odlm": "true", } klog.V(3).Info("Generating Namespace: ", o.Namespace) @@ -562,6 +565,7 @@ func (r *Reconciler) generateClusterObjects(o *operatorv1alpha1.Operator, regist registryKey.Namespace + "." + registryKey.Name + "/config": "true", requestKey.Namespace + "." + requestKey.Name + "." + o.Name + "/request": o.Channel, requestKey.Namespace + "." + requestKey.Name + "." + o.Name + "/operatorNamespace": namespace, + "packageName": o.PackageName, } //CM object @@ -576,7 +580,7 @@ func (r *Reconciler) generateClusterObjects(o *operatorv1alpha1.Operator, regist } cm.SetGroupVersionKind(schema.GroupVersionKind{Group: corev1.SchemeGroupVersion.Group, Kind: "Configmap", Version: corev1.SchemeGroupVersion.Version}) - klog.V(3).Info("Generating Configmap: ", o.PackageName, " in the Namespace: ", namespace) + klog.V(1).Info("Generating Configmap: ", o.PackageName, " in the Namespace: ", namespace) co.configmap = cm return co } @@ -606,6 +610,7 @@ func checkOpReqCMAnnotationsForUninstall(reqName, reqNs, opName, installMode str uninstallOperator := true uninstallOperand := true + klog.V(1).Info("checking cm for operand: ", opName) delete(cm.Annotations, reqNs+"."+reqName+"."+opName+"/request") delete(cm.Annotations, reqNs+"."+reqName+"."+opName+"/operatorNamespace") From 920800f80dd402955ff08ce57c6efa14c62d7472 Mon Sep 17 00:00:00 2001 From: Ben Luzarraga Date: Mon, 3 Feb 2025 20:39:22 -0600 Subject: [PATCH 11/11] disable, edit debugging statements Signed-off-by: Ben Luzarraga --- .../operandrequestnoolm_controller.go | 2 +- .../operandrequestnoolm/reconcile_operator.go | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/controllers/operandrequestnoolm/operandrequestnoolm_controller.go b/controllers/operandrequestnoolm/operandrequestnoolm_controller.go index e53309cf..99a9c294 100644 --- a/controllers/operandrequestnoolm/operandrequestnoolm_controller.go +++ b/controllers/operandrequestnoolm/operandrequestnoolm_controller.go @@ -243,7 +243,7 @@ func (r *Reconciler) checkFinalizer(ctx context.Context, requestInstance *operat klog.V(1).Infof("Deleting OperandRequest %s in the namespace %s", requestInstance.Name, requestInstance.Namespace) remainingOperands := gset.NewSet() for _, m := range requestInstance.Status.Members { - klog.V(1).Infof("Operand %s added to deletion list", m.Name) + klog.V(3).Infof("Operand %s added to deletion list", m.Name) remainingOperands.Add(m.Name) } // Delete all the operands and configmaps that created by current request diff --git a/controllers/operandrequestnoolm/reconcile_operator.go b/controllers/operandrequestnoolm/reconcile_operator.go index fd4cd29a..6bd6d296 100644 --- a/controllers/operandrequestnoolm/reconcile_operator.go +++ b/controllers/operandrequestnoolm/reconcile_operator.go @@ -307,7 +307,7 @@ func (r *Reconciler) updateOpReqCM(ctx context.Context, cr *operatorv1alpha1.Ope func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandName string, requestInstance *operatorv1alpha1.OperandRequest, registryInstance *operatorv1alpha1.OperandRegistry, configInstance *operatorv1alpha1.OperandConfig) error { // No error handling for un-installation step in case Catalog has been deleted op, _ := r.GetOperandFromRegistryNoOLM(ctx, registryInstance, operandName) - klog.V(1).Info("op to check in uninstallOperatorsAndOperands: ", op.Name, " o: ", fmt.Sprintf("%v", operandName)) + // klog.V(1).Info("op to check in uninstallOperatorsAndOperands: ", op.Name, " o: ", fmt.Sprintf("%v", operandName)) if op == nil { klog.Warningf("Operand %s not found", operandName) return nil @@ -317,9 +317,9 @@ func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandN //Assuing we can still use op as a parameter, we should be able to get the deployment with ease deploy, err := r.GetDeployment(ctx, operandName, namespace, registryInstance.Namespace, op.PackageName) - klog.V(1).Info("deployment in uninstallOperatorsAndOperands: ", deploy.Name) + // klog.V(1).Info("deployment in uninstallOperatorsAndOperands: ", deploy.Name) if deploy == nil && err == nil { - klog.V(1).Infof("There is no Deployment called %s or using package name %s in the namespace %s and %s", operandName, op.PackageName, namespace, registryInstance.Namespace) + klog.V(3).Infof("There is no Deployment called %s or using package name %s in the namespace %s and %s", operandName, op.PackageName, namespace, registryInstance.Namespace) return nil } else if err != nil { klog.Errorf("Failed to get Deployment called %s or using package name %s in the namespace %s and %s", operandName, op.PackageName, namespace, registryInstance.Namespace) @@ -328,22 +328,22 @@ func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandN if deploy.Labels == nil { // Subscription existing and not managed by OperandRequest controller - klog.V(1).Infof("Deployment %s in the namespace %s isn't created by ODLM", deploy.Name, deploy.Namespace) + klog.V(2).Infof("Deployment %s in the namespace %s isn't created by ODLM", deploy.Name, deploy.Namespace) return nil } // if _, ok := deploy.Labels[constant.OpreqLabel]; !ok { // if !op.UserManaged { - // klog.V(1).Infof("Deployment %s in the namespace %s isn't created by ODLM and isn't user managed", deploy.Name, deploy.Namespace) + // klog.V(2).Infof("Deployment %s in the namespace %s isn't created by ODLM and isn't user managed", deploy.Name, deploy.Namespace) // return nil // } // } cm, err := r.GetOpReqCM(ctx, op.Name, deploy.Namespace, registryInstance.Namespace, op.PackageName) - klog.V(1).Info("Configmap tracking operand: ", cm.Name) + // klog.V(1).Info("Configmap tracking operand: ", cm.Name) if cm != nil && err == nil { uninstallOperator, uninstallOperand := checkOpReqCMAnnotationsForUninstall(requestInstance.ObjectMeta.Name, requestInstance.ObjectMeta.Namespace, op.Name, op.InstallMode, cm) - klog.V(1).Info("uinstall operator: ", uninstallOperator, " uninstall operand: ", uninstallOperand) + // klog.V(1).Info("uinstall operator: ", uninstallOperator, " uninstall operand: ", uninstallOperand) if !uninstallOperand && !uninstallOperator { if err = r.updateOpReqCM(ctx, requestInstance, cm); err != nil { requestInstance.SetMemberStatus(op.Name, operatorv1alpha1.OperatorFailed, "", &r.Mutex) @@ -476,7 +476,7 @@ func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInst go func() { defer wg.Done() op, _ := r.GetOperandFromRegistryNoOLM(ctx, registryInstance, fmt.Sprintf("%v", o)) - klog.V(1).Info("op to check in absentOperatorsandOperands: ", op.Name, " o: ", fmt.Sprintf("%v", o)) + // klog.V(1).Info("op to check in absentOperatorsandOperands: ", op.Name, " o: ", fmt.Sprintf("%v", o)) if op == nil { klog.Warningf("Operand %s not found", fmt.Sprintf("%v", o)) } @@ -500,7 +500,7 @@ func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInst requestInstance.RemoveServiceStatus(fmt.Sprintf("%v", o), &r.Mutex) (*remainingOperands).Remove(o) remainingOp.Remove(o) - klog.V(1).Info("op removed: ", op.Name, " o: ", fmt.Sprintf("%v", o)) + // klog.V(1).Info("op removed: ", op.Name, " o: ", fmt.Sprintf("%v", o)) }() } timeout := util.WaitTimeout(&wg, constant.DefaultSubDeleteTimeout) @@ -516,7 +516,7 @@ func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInst } func (r *Reconciler) getNeedDeletedOperands(requestInstance *operatorv1alpha1.OperandRequest) gset.Set { - klog.V(1).Info("Getting the operator need to be delete") + klog.V(3).Info("Getting the operator need to be delete") deployedOperands := gset.NewSet() for _, req := range requestInstance.Status.Members { deployedOperands.Add(req.Name) @@ -526,7 +526,7 @@ func (r *Reconciler) getNeedDeletedOperands(requestInstance *operatorv1alpha1.Op if requestInstance.DeletionTimestamp.IsZero() { for _, req := range requestInstance.Spec.Requests { for _, op := range req.Operands { - klog.V(1).Info("Add current operand in getNeedDeletedOperands ", op.Name) + // klog.V(1).Info("Add current operand in getNeedDeletedOperands ", op.Name) currentOperands.Add(op.Name) } } @@ -580,7 +580,7 @@ func (r *Reconciler) generateClusterObjects(o *operatorv1alpha1.Operator, regist } cm.SetGroupVersionKind(schema.GroupVersionKind{Group: corev1.SchemeGroupVersion.Group, Kind: "Configmap", Version: corev1.SchemeGroupVersion.Version}) - klog.V(1).Info("Generating Configmap: ", o.PackageName, " in the Namespace: ", namespace) + klog.V(2).Info("Generating tracking Configmap: ", o.PackageName, " in the Namespace: ", namespace) co.configmap = cm return co } @@ -610,7 +610,7 @@ func checkOpReqCMAnnotationsForUninstall(reqName, reqNs, opName, installMode str uninstallOperator := true uninstallOperand := true - klog.V(1).Info("checking cm for operand: ", opName) + klog.V(2).Info("Checking tracking configmap for uninstall for operand: ", opName) delete(cm.Annotations, reqNs+"."+reqName+"."+opName+"/request") delete(cm.Annotations, reqNs+"."+reqName+"."+opName+"/operatorNamespace")