Skip to content

Commit 7478252

Browse files
authored
reserve the status for operators which are still in deletion stage (#867)
* reserve the status for operators which are still in deletion stage Signed-off-by: Daniel Fan <[email protected]> * reserve the status for operators which are still in deletion stage Signed-off-by: Daniel Fan <[email protected]> Signed-off-by: Daniel Fan <[email protected]>
1 parent 4ffa6ee commit 7478252

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

api/v1alpha1/operandrequest_types.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"sync"
2222
"time"
2323

24+
gset "github.com/deckarep/golang-set"
2425
corev1 "k8s.io/api/core/v1"
2526
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
runtime "k8s.io/apimachinery/pkg/runtime"
@@ -388,10 +389,10 @@ func (r *OperandRequest) setOperandReadyCondition(operandPhase ServicePhase, nam
388389
}
389390

390391
// FreshMemberStatus cleanup Member status from the Member status list.
391-
func (r *OperandRequest) FreshMemberStatus() {
392+
func (r *OperandRequest) FreshMemberStatus(failedDeletedOperands *gset.Set) {
392393
newMembers := []MemberStatus{}
393394
for index, m := range r.Status.Members {
394-
if foundOperand(r.Spec.Requests, m.Name) {
395+
if foundOperand(r.Spec.Requests, m.Name) || (*failedDeletedOperands).Contains(m.Name) {
395396
newMembers = append(newMembers, r.Status.Members[index])
396397
}
397398
}
@@ -458,6 +459,8 @@ func (r *OperandRequest) UpdateClusterPhase() {
458459
clusterStatusStat.runningNum++
459460
case OperatorInstalling:
460461
clusterStatusStat.installingNum++
462+
case OperatorUpdating:
463+
clusterStatusStat.installingNum++
461464
default:
462465
}
463466

controllers/operandrequest/operandrequest_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"sync"
2626
"time"
2727

28+
gset "github.com/deckarep/golang-set"
2829
olmv1 "github.com/operator-framework/api/pkg/operators/v1"
2930
olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
3031
"github.com/pkg/errors"
@@ -207,6 +208,7 @@ func (r *Reconciler) addFinalizer(ctx context.Context, cr *operatorv1alpha1.Oper
207208

208209
func (r *Reconciler) checkFinalizer(ctx context.Context, requestInstance *operatorv1alpha1.OperandRequest) error {
209210
klog.V(1).Infof("Deleting OperandRequest %s in the namespace %s", requestInstance.Name, requestInstance.Namespace)
211+
failedDeletedOperands := gset.NewSet()
210212
existingSub := &olmv1alpha1.SubscriptionList{}
211213

212214
opts := []client.ListOption{
@@ -220,7 +222,7 @@ func (r *Reconciler) checkFinalizer(ctx context.Context, requestInstance *operat
220222
return nil
221223
}
222224
// Delete all the subscriptions that created by current request
223-
if err := r.absentOperatorsAndOperands(ctx, requestInstance); err != nil {
225+
if err := r.absentOperatorsAndOperands(ctx, requestInstance, &failedDeletedOperands); err != nil {
224226
return err
225227
}
226228
return nil

controllers/operandrequest/reconcile_operand.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,6 @@ func (r *Reconciler) reconcileOperand(ctx context.Context, requestInstance *oper
100100
klog.Warningf("Subscription %s in the namespace %s isn't created by ODLM", sub.Name, sub.Namespace)
101101
}
102102

103-
// check config annotation in subscription, identify the first ODLM has the priority to reconcile
104-
var firstMatch string
105-
reg, _ := regexp.Compile(`^(.*)\.(.*)\/config`)
106-
for anno := range sub.Annotations {
107-
if reg.MatchString(anno) {
108-
firstMatch = anno
109-
break
110-
}
111-
}
112-
113-
if firstMatch != "" && firstMatch != regNs+"."+regName+"/config" {
114-
klog.V(2).Infof("Subscription %s in the namespace %s is currently managed by %s", sub.Name, sub.Namespace, firstMatch)
115-
continue
116-
}
117-
118103
// It the installplan is not created yet, ODLM will try later
119104
if sub.Status.Install == nil || sub.Status.InstallPlanRef.Name == "" {
120105
klog.Warningf("The Installplan for Subscription %s is not ready. Will check it again", sub.Name)
@@ -158,6 +143,22 @@ func (r *Reconciler) reconcileOperand(ctx context.Context, requestInstance *oper
158143
klog.V(3).Info("Generating customresource base on ClusterServiceVersion: ", csv.GetName())
159144
requestInstance.SetMemberStatus(operand.Name, operatorv1alpha1.OperatorRunning, "", &r.Mutex)
160145

146+
// check config annotation in subscription, identify the first ODLM has the priority to reconcile
147+
var firstMatch string
148+
reg, _ := regexp.Compile(`^(.*)\.(.*)\/config`)
149+
for anno := range sub.Annotations {
150+
if reg.MatchString(anno) {
151+
firstMatch = anno
152+
break
153+
}
154+
}
155+
156+
if firstMatch != "" && firstMatch != regNs+"."+regName+"/config" {
157+
klog.V(2).Infof("Subscription %s in the namespace %s is currently managed by %s, Skip creating CR for it", sub.Name, sub.Namespace, firstMatch)
158+
requestInstance.SetMemberStatus(operand.Name, "", operatorv1alpha1.ServiceRunning, &r.Mutex)
159+
continue
160+
}
161+
161162
// Merge and Generate CR
162163
if operand.Kind == "" {
163164
configInstance, err := r.GetOperandConfig(ctx, registryKey)

controllers/operandrequest/reconcile_operator.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ import (
4646

4747
func (r *Reconciler) reconcileOperator(ctx context.Context, requestInstance *operatorv1alpha1.OperandRequest) error {
4848
klog.V(1).Infof("Reconciling Operators for OperandRequest: %s/%s", requestInstance.GetNamespace(), requestInstance.GetName())
49-
49+
// It is important to NOT pass the set directly into defer functions.
50+
// The arguments to the deferred function are evaluated when the defer executes
51+
failedDeletedOperands := gset.NewSet()
5052
// Update request status
5153
defer func() {
52-
requestInstance.FreshMemberStatus()
54+
requestInstance.FreshMemberStatus(&failedDeletedOperands)
5355
requestInstance.UpdateClusterPhase()
5456
}()
5557

@@ -112,8 +114,17 @@ func (r *Reconciler) reconcileOperator(ctx context.Context, requestInstance *ope
112114
}
113115
wg.Wait()
114116
}
117+
118+
if len(merr.Errors) != 0 {
119+
return merr
120+
}
115121
}
116122

123+
// TODO: update OperandRequest status before patching. Otherwise, the status will be lost.
124+
// It is really corner case which would not cause any issue so far since the Status will finally be Running.
125+
// Need to consider a more elegant way to preserve status instead of calling Client API like below
126+
// requestInstance.FreshMemberStatus(&failedDeletedOperands)
127+
117128
mergePatch, _ := json.Marshal(map[string]interface{}{
118129
"metadata": map[string]interface{}{
119130
"annotations": map[string]interface{}{
@@ -126,7 +137,7 @@ func (r *Reconciler) reconcileOperator(ctx context.Context, requestInstance *ope
126137
}
127138

128139
// Delete specific operators
129-
if err := r.absentOperatorsAndOperands(ctx, requestInstance); err != nil {
140+
if err := r.absentOperatorsAndOperands(ctx, requestInstance, &failedDeletedOperands); err != nil {
130141
return err
131142
}
132143
klog.V(1).Infof("Finished reconciling Operators for OperandRequest: %s/%s", requestInstance.GetNamespace(), requestInstance.GetName())
@@ -359,7 +370,7 @@ func (r *Reconciler) deleteSubscription(ctx context.Context, operandName string,
359370
return nil
360371
}
361372

362-
func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInstance *operatorv1alpha1.OperandRequest) error {
373+
func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInstance *operatorv1alpha1.OperandRequest, failedDeletedOperands *gset.Set) error {
363374
needDeletedOperands, err := r.getNeedDeletedOperands(ctx, requestInstance)
364375
if err != nil {
365376
return err
@@ -396,6 +407,7 @@ func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInst
396407
r.Mutex.Lock()
397408
defer r.Mutex.Unlock()
398409
merr.Add(err)
410+
(*failedDeletedOperands).Add(o)
399411
}
400412
remainingOp.Remove(o)
401413
}()

0 commit comments

Comments
 (0)