@@ -238,6 +238,7 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, requestInstance
238238
239239 // check if sub.Spec.Channel and opt.Channel are valid semantic version
240240 // 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
241242 subChanel := util .FindSemantic (sub .Spec .Channel )
242243 optChannel := util .FindSemantic (opt .Channel )
243244 if semver .IsValid (subChanel ) && semver .IsValid (optChannel ) && semver .Compare (subChanel , optChannel ) < 0 {
@@ -249,11 +250,11 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, requestInstance
249250 } else {
250251 requestInstance .SetNotFoundOperatorFromRegistryCondition (operand .Name , operatorv1alpha1 .ResourceTypeSub , corev1 .ConditionFalse , mu )
251252
252- if minChannel := util .FindMinSemver (sub .Annotations , sub .Spec .Channel ); minChannel != "" {
253+ if minChannel := util .FindMinSemverFromAnnotations (sub .Annotations , sub .Spec .Channel ); minChannel != "" {
253254 sub .Spec .Channel = minChannel
254255 }
255256
256- // update the spec iff channel in sub matches channel in opreg
257+ // update the spec iff channel in sub matches channel
257258 if sub .Spec .Channel == opt .Channel {
258259 isMatchedChannel = true
259260 sub .Spec .CatalogSource = opt .SourceName
@@ -422,7 +423,7 @@ func (r *Reconciler) uninstallOperatorsAndOperands(ctx context.Context, operandN
422423 }
423424 }
424425
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 )
426427 if ! uninstallOperand && ! uninstallOperator {
427428 if err = r .updateSubscription (ctx , requestInstance , sub ); err != nil {
428429 requestInstance .SetMemberStatus (op .Name , operatorv1alpha1 .OperatorFailed , "" , & r .Mutex )
@@ -731,21 +732,15 @@ func CheckSingletonServices(operator string) bool {
731732// It returns two boolean values: uninstallOperator and uninstallOperand.
732733// If uninstallOperator is true, it means the operator should be uninstalled.
733734// 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 ) {
735736 uninstallOperator := true
736737 uninstallOperand := true
737738
738- var curChannel string
739- if sub .GetAnnotations () != nil {
740- curChannel = sub .Annotations [reqNs + "." + reqName + "." + opName + "/request" ]
741- }
742-
743739 delete (sub .Annotations , reqNs + "." + reqName + "." + opName + "/request" )
744740 delete (sub .Annotations , reqNs + "." + reqName + "." + opName + "/operatorNamespace" )
745741
746742 var opreqNsSlice []string
747743 var operatorNameSlice []string
748- var channelSlice []string
749744 namespaceReg , _ := regexp .Compile (`^(.*)\.(.*)\.(.*)\/operatorNamespace` )
750745 channelReg , _ := regexp .Compile (`^(.*)\.(.*)\.(.*)\/request` )
751746
@@ -755,7 +750,6 @@ func checkSubAnnotationsForUninstall(reqName, reqNs, opName string, sub *olmv1al
755750 }
756751
757752 if channelReg .MatchString (key ) {
758- channelSlice = append (channelSlice , value )
759753 // Extract the operator name from the key
760754 keyParts := strings .Split (key , "/" )
761755 annoPrefix := strings .Split (keyParts [0 ], "." )
@@ -773,10 +767,11 @@ func checkSubAnnotationsForUninstall(reqName, reqNs, opName string, sub *olmv1al
773767 uninstallOperator = false
774768 }
775769
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 ) {
780775 uninstallOperand = false
781776 }
782777
0 commit comments