@@ -238,6 +238,7 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, requestInstance
238
238
239
239
// check if sub.Spec.Channel and opt.Channel are valid semantic version
240
240
// set annotation channel back to previous one if sub.Spec.Channel is lower than opt.Channel
241
+ // To avoid upgrade from one maintenance version to another maintenance version like from v3 to v3.23
241
242
subChanel := util .FindSemantic (sub .Spec .Channel )
242
243
optChannel := util .FindSemantic (opt .Channel )
243
244
if semver .IsValid (subChanel ) && semver .IsValid (optChannel ) && semver .Compare (subChanel , optChannel ) < 0 {
@@ -249,11 +250,11 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, requestInstance
249
250
} else {
250
251
requestInstance .SetNotFoundOperatorFromRegistryCondition (operand .Name , operatorv1alpha1 .ResourceTypeSub , corev1 .ConditionFalse , mu )
251
252
252
- if minChannel := util .FindMinSemver (sub .Annotations , sub .Spec .Channel ); minChannel != "" {
253
+ if minChannel := util .FindMinSemverFromAnnotations (sub .Annotations , sub .Spec .Channel ); minChannel != "" {
253
254
sub .Spec .Channel = minChannel
254
255
}
255
256
256
- // update the spec iff channel in sub matches channel in opreg
257
+ // update the spec iff channel in sub matches channel
257
258
if sub .Spec .Channel == opt .Channel {
258
259
isMatchedChannel = true
259
260
sub .Spec .CatalogSource = opt .SourceName
@@ -422,7 +423,7 @@ func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandN
422
423
}
423
424
}
424
425
425
- uninstallOperator , uninstallOperand := checkSubAnnotationsForUninstall (requestInstance .ObjectMeta .Name , requestInstance .ObjectMeta .Namespace , op .Name , sub )
426
+ uninstallOperator , uninstallOperand := checkSubAnnotationsForUninstall (requestInstance .ObjectMeta .Name , requestInstance .ObjectMeta .Namespace , op .Name , op . InstallMode , sub )
426
427
if ! uninstallOperand && ! uninstallOperator {
427
428
if err = r .updateSubscription (ctx , requestInstance , sub ); err != nil {
428
429
requestInstance .SetMemberStatus (op .Name , operatorv1alpha1 .OperatorFailed , "" , & r .Mutex )
@@ -731,21 +732,15 @@ func CheckSingletonServices(operator string) bool {
731
732
// It returns two boolean values: uninstallOperator and uninstallOperand.
732
733
// If uninstallOperator is true, it means the operator should be uninstalled.
733
734
// If uninstallOperand is true, it means the operand should be uninstalled.
734
- func checkSubAnnotationsForUninstall (reqName , reqNs , opName string , sub * olmv1alpha1.Subscription ) (bool , bool ) {
735
+ func checkSubAnnotationsForUninstall (reqName , reqNs , opName , installMode string , sub * olmv1alpha1.Subscription ) (bool , bool ) {
735
736
uninstallOperator := true
736
737
uninstallOperand := true
737
738
738
- var curChannel string
739
- if sub .GetAnnotations () != nil {
740
- curChannel = sub .Annotations [reqNs + "." + reqName + "." + opName + "/request" ]
741
- }
742
-
743
739
delete (sub .Annotations , reqNs + "." + reqName + "." + opName + "/request" )
744
740
delete (sub .Annotations , reqNs + "." + reqName + "." + opName + "/operatorNamespace" )
745
741
746
742
var opreqNsSlice []string
747
743
var operatorNameSlice []string
748
- var channelSlice []string
749
744
namespaceReg , _ := regexp .Compile (`^(.*)\.(.*)\.(.*)\/operatorNamespace` )
750
745
channelReg , _ := regexp .Compile (`^(.*)\.(.*)\.(.*)\/request` )
751
746
@@ -755,7 +750,6 @@ func checkSubAnnotationsForUninstall(reqName, reqNs, opName string, sub *olmv1al
755
750
}
756
751
757
752
if channelReg .MatchString (key ) {
758
- channelSlice = append (channelSlice , value )
759
753
// Extract the operator name from the key
760
754
keyParts := strings .Split (key , "/" )
761
755
annoPrefix := strings .Split (keyParts [0 ], "." )
@@ -773,10 +767,11 @@ func checkSubAnnotationsForUninstall(reqName, reqNs, opName string, sub *olmv1al
773
767
uninstallOperator = false
774
768
}
775
769
776
- // If the removed/uninstalled <prefix>/request annotation's value is NOT the same as all other <prefix>/request annotation's values.
777
- // or the operator namespace in one of remaining annotation is the same as the operator name in removed/uninstalled <prefix>/request
778
- // the operand should NOT be uninstalled.
779
- if util .Differs (channelSlice , curChannel ) || util .Contains (operatorNameSlice , opName ) {
770
+ // When one of following conditions are met, the operand will NOT be uninstalled:
771
+ // 1. operator is not uninstalled AND intallMode is no-op.
772
+ // 2. operator is uninstalled AND at least one other <prefix>/operatorNamespace annotation exists.
773
+ // 2. remaining <prefix>/request annotation's values contain the same operator name
774
+ if (! uninstallOperator && installMode == operatorv1alpha1 .InstallModeNoop ) || (uninstallOperator && len (opreqNsSlice ) != 0 ) || util .Contains (operatorNameSlice , opName ) {
780
775
uninstallOperand = false
781
776
}
782
777
0 commit comments