@@ -53,6 +53,7 @@ func (r *Reconciler) reconcileOperator(ctx context.Context, requestInstance *ope
53
53
for _ , m := range requestInstance .Status .Members {
54
54
remainingOperands .Add (m .Name )
55
55
}
56
+
56
57
// Update request status
57
58
defer func () {
58
59
requestInstance .FreshMemberStatus (& remainingOperands )
@@ -230,6 +231,12 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, requestInstance
230
231
sub .Annotations [registryKey .Namespace + "." + registryKey .Name + "/config" ] = "true"
231
232
sub .Annotations [requestInstance .Namespace + "." + requestInstance .Name + "." + operand .Name + "/request" ] = opt .Channel
232
233
sub .Annotations [requestInstance .Namespace + "." + requestInstance .Name + "." + operand .Name + "/operatorNamespace" ] = namespace
234
+ // Only add the config annotation if ConfigName is not empty
235
+ if opt .ConfigName != "" {
236
+ sub .Annotations [requestInstance .Namespace + "." + requestInstance .Name + "." + operand .Name + "/config" ] = opt .ConfigName
237
+ } else {
238
+ sub .Annotations [requestInstance .Namespace + "." + requestInstance .Name + "." + operand .Name + "/config" ] = opt .Name
239
+ }
233
240
234
241
if opt .InstallMode == operatorv1alpha1 .InstallModeNoop {
235
242
isMatchedChannel = true
@@ -445,11 +452,11 @@ func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandN
445
452
klog .Infof ("Found %d ClusterServiceVersions for Subscription %s/%s" , len (csvList ), sub .Namespace , sub .Name )
446
453
if uninstallOperand {
447
454
klog .V (2 ).Infof ("Deleting all the Custom Resources for CSV, Namespace: %s, Name: %s" , csvList [0 ].Namespace , csvList [0 ].Name )
448
- if err := r .deleteAllCustomResource (ctx , csvList [0 ], requestInstance , configInstance , operandName , configInstance .Namespace ); err != nil {
455
+ if err := r .deleteAllCustomResource (ctx , csvList [0 ], requestInstance , configInstance , op . ConfigName , operandName , configInstance .Namespace ); err != nil {
449
456
return err
450
457
}
451
458
klog .V (2 ).Infof ("Deleting all the k8s Resources for CSV, Namespace: %s, Name: %s" , csvList [0 ].Namespace , csvList [0 ].Name )
452
- if err := r .deleteAllK8sResource (ctx , configInstance , operandName , configInstance .Namespace ); err != nil {
459
+ if err := r .deleteAllK8sResource (ctx , configInstance , op . ConfigName , operandName , configInstance .Namespace ); err != nil {
453
460
return err
454
461
}
455
462
}
@@ -533,11 +540,11 @@ func (r *Reconciler) uninstallOperands(ctx context.Context, operandName string,
533
540
klog .Infof ("Found %d ClusterServiceVersions for package %s/%s" , len (csvList ), op .Name , namespace )
534
541
if uninstallOperand {
535
542
klog .V (2 ).Infof ("Deleting all the Custom Resources for CSV, Namespace: %s, Name: %s" , csvList [0 ].Namespace , csvList [0 ].Name )
536
- if err := r .deleteAllCustomResource (ctx , csvList [0 ], requestInstance , configInstance , operandName , configInstance .Namespace ); err != nil {
543
+ if err := r .deleteAllCustomResource (ctx , csvList [0 ], requestInstance , configInstance , op . ConfigName , operandName , configInstance .Namespace ); err != nil {
537
544
return err
538
545
}
539
546
klog .V (2 ).Infof ("Deleting all the k8s Resources for CSV, Namespace: %s, Name: %s" , csvList [0 ].Namespace , csvList [0 ].Name )
540
- if err := r .deleteAllK8sResource (ctx , configInstance , operandName , configInstance .Namespace ); err != nil {
547
+ if err := r .deleteAllK8sResource (ctx , configInstance , op . ConfigName , operandName , configInstance .Namespace ); err != nil {
541
548
return err
542
549
}
543
550
}
@@ -613,7 +620,6 @@ func (r *Reconciler) absentOperatorsAndOperands(ctx context.Context, requestInst
613
620
}
614
621
615
622
func (r * Reconciler ) getNeedDeletedOperands (requestInstance * operatorv1alpha1.OperandRequest ) gset.Set {
616
- klog .V (3 ).Info ("Getting the operator need to be delete" )
617
623
deployedOperands := gset .NewSet ()
618
624
for _ , req := range requestInstance .Status .Members {
619
625
deployedOperands .Add (req .Name )
@@ -739,13 +745,24 @@ func checkSubAnnotationsForUninstall(reqName, reqNs, opName, installMode string,
739
745
uninstallOperator := true
740
746
uninstallOperand := true
741
747
748
+ // Store the current operator's config name before removing its annotations
749
+ var currentConfigName string
750
+ configKey := reqNs + "." + reqName + "." + opName + "/config"
751
+ if configVal , exists := sub .Annotations [configKey ]; exists {
752
+ currentConfigName = configVal
753
+ }
754
+
742
755
delete (sub .Annotations , reqNs + "." + reqName + "." + opName + "/request" )
743
756
delete (sub .Annotations , reqNs + "." + reqName + "." + opName + "/operatorNamespace" )
757
+ delete (sub .Annotations , configKey )
744
758
745
759
var opreqNsSlice []string
746
760
var operatorNameSlice []string
761
+ var configNameSlice []string // Track all remaining config names
762
+
747
763
namespaceReg , _ := regexp .Compile (`^(.*)\.(.*)\.(.*)\/operatorNamespace` )
748
764
channelReg , _ := regexp .Compile (`^(.*)\.(.*)\.(.*)\/request` )
765
+ configReg , _ := regexp .Compile (`^(.*)\.(.*)\.(.*)\/config` )
749
766
750
767
for key , value := range sub .Annotations {
751
768
if namespaceReg .MatchString (key ) {
@@ -758,6 +775,10 @@ func checkSubAnnotationsForUninstall(reqName, reqNs, opName, installMode string,
758
775
annoPrefix := strings .Split (keyParts [0 ], "." )
759
776
operatorNameSlice = append (operatorNameSlice , annoPrefix [len (annoPrefix )- 1 ])
760
777
}
778
+ if configReg .MatchString (key ) {
779
+ // Add config name to the list
780
+ configNameSlice = append (configNameSlice , value )
781
+ }
761
782
}
762
783
763
784
// If one of remaining <prefix>/operatorNamespace annotations' values is the same as subscription's namespace,
@@ -773,8 +794,12 @@ func checkSubAnnotationsForUninstall(reqName, reqNs, opName, installMode string,
773
794
// When one of following conditions are met, the operand will NOT be uninstalled:
774
795
// 1. operator is not uninstalled AND intallMode is no-op.
775
796
// 2. operator is uninstalled AND at least one other <prefix>/operatorNamespace annotation exists.
776
- // 2. remaining <prefix>/request annotation's values contain the same operator name
777
- if (! uninstallOperator && installMode == operatorv1alpha1 .InstallModeNoop ) || (uninstallOperator && len (opreqNsSlice ) != 0 ) || util .Contains (operatorNameSlice , opName ) {
797
+ // 3. remaining <prefix>/request annotation's values contain the same operator name
798
+ // 4. remaining <prefix>/config annotation's values contain the same configName as this operator
799
+ if (! uninstallOperator && installMode == operatorv1alpha1 .InstallModeNoop ) ||
800
+ (uninstallOperator && len (opreqNsSlice ) != 0 ) ||
801
+ util .Contains (operatorNameSlice , opName ) ||
802
+ (currentConfigName != "" && util .Contains (configNameSlice , currentConfigName )) {
778
803
uninstallOperand = false
779
804
}
780
805
0 commit comments