Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add annotation and label change predicate
Signed-off-by: YuChen <[email protected]>
  • Loading branch information
YuChen committed Nov 30, 2023
commit a4606c565d9e58b3eb2184cba1c349653a13516b
23 changes: 14 additions & 9 deletions controllers/commonservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,20 @@ func (r *CommonServiceReconciler) Reconcile(ctx context.Context, req ctrl.Reques
klog.Error("Accept license by changing .spec.license.accept to true in the CommonService CR. Operator will not proceed until then")
}

// If the CommonService CR is not paused, continue to reconcile
if !r.reconcilePauseRequest(instance) {
if r.checkNamespace(req.NamespacedName.String()) {
return r.ReconcileMasterCR(ctx, instance)
}
return r.ReconcileGeneralCR(ctx, instance)
} else {
if err := r.updatePhase(ctx, instance, CRPending); err != nil {
klog.Errorf("Fail to reconcile %s/%s: %v", instance.Namespace, instance.Name, err)
return ctrl.Result{}, err
} else {
klog.Infof("%s/%s is in pending status due to pause request", instance.Namespace, instance.Name)
return ctrl.Result{}, nil
}
}
// If the CommonService CR is paused, update the status to pending
if err := r.updatePhase(ctx, instance, CRPending); err != nil {
klog.Errorf("Fail to reconcile %s/%s: %v", instance.Namespace, instance.Name, err)
return ctrl.Result{}, err
}
klog.Infof("%s/%s is in pending status due to pause request", instance.Namespace, instance.Name)
return ctrl.Result{}, nil
}

func (r *CommonServiceReconciler) ReconcileMasterCR(ctx context.Context, instance *apiv3.CommonService) (ctrl.Result, error) {
Expand Down Expand Up @@ -415,7 +415,12 @@ func (r *CommonServiceReconciler) mappingToCsRequest() handler.MapFunc {

func (r *CommonServiceReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&apiv3.CommonService{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
// AnnotationChangedPredicate is intended to be used in conjunction with the GenerationChangedPredicate
For(&apiv3.CommonService{}, builder.WithPredicates(
predicate.Or(
predicate.GenerationChangedPredicate{},
predicate.AnnotationChangedPredicate{},
predicate.LabelChangedPredicate{}))).
Watches(
&source.Kind{Type: &corev1.ConfigMap{}},
handler.EnqueueRequestsFromMapFunc(r.mappingToCsRequest()),
Expand Down
8 changes: 4 additions & 4 deletions controllers/recocile_pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package controllers

import (
apiv3 "github.com/IBM/ibm-common-service-operator/api/v3"
"k8s.io/klog"

apiv3 "github.com/IBM/ibm-common-service-operator/api/v3"
)

const (
Expand All @@ -29,7 +30,7 @@ const (

func (r *CommonServiceReconciler) reconcilePauseRequest(instance *apiv3.CommonService) bool {

klog.Info("Request Stage: reconcilePauseRequest")
klog.Info("Request Stage: ReconcilePauseRequest")

// if the given CommnService CR has not been existing
if instance == nil {
Expand Down Expand Up @@ -66,9 +67,8 @@ func (r *CommonServiceReconciler) pauseRequestExists(instance *apiv3.CommonServi
return instance.ObjectMeta.Annotations[PauseRequestAnnoKey] == PauseRequestValue
} else if selfpauseRequestFound {
return instance.ObjectMeta.Annotations[SelfPauseRequestAnnoKey] == PauseRequestValue
} else {
return false
}
return false
}
return false
}