Repository: submariner-io/submariner-operator
Pull request #1857 (2022-02-20 19:38:16)

Fix return value of uninstall.IsSupportedForVersion
Signed-off-by: Sridhar Gaddam <sgaddam@redhat.com>

<!--  Thanks for sending a pull request!  Here are some tips for you:

1. If this is your first time, please read our developer guide: https://submariner.io/development/
2. Ensure you have added the appropriate tests for your PR: https://submariner.io/development/code-review/#test-new-functionality
3. Read the code review guide to ease the review process: https://submariner.io/development/code-review/
4. If the PR is unfinished, mark it as a draft: https://submariner.io/development/code-review/#mark-work-in-progress-prs-as-drafts
5. If you are using CI to debug, use your private fork: https://submariner.io/development/code-review/#use-private-forks-for-debugging-prs-by-running-ci
6. Add labels to the PR as appropriate.

This template is based on the K8s/K8s template:

https://github.com/kubernetes/kubernetes/blob/master/.github/PULL_REQUEST_TEMPLATE.md
-->


submariner-bot: 🤖 Created branch: z_pr1857/sridhargaddam/fix-naming 
🚀 Full E2E won't run until the "ready-to-test" label is applied. I will add it automatically once the PR has 2 approvals, or you can add it manually.

Patch:
diff --git a/controllers/servicediscovery/cleanup.go b/controllers/servicediscovery/cleanup.go
index 339510aa..04afb773 100644
--- a/controllers/servicediscovery/cleanup.go
+++ b/controllers/servicediscovery/cleanup.go
@@ -40,7 +40,7 @@ import (
 )
 
 func (r *Reconciler) doCleanup(ctx context.Context, instance *operatorv1alpha1.ServiceDiscovery) (reconcile.Result, error) {
-	if uninstall.IsSupportedForVersion(instance.Spec.Version) {
+	if !uninstall.IsSupportedForVersion(instance.Spec.Version) {
 		log.Info("Deleting ServiceDiscovery version does not support uninstall", "version", instance.Spec.Version)
 		return reconcile.Result{}, r.removeFinalizer(ctx, instance)
 	}
diff --git a/controllers/submariner/cleanup.go b/controllers/submariner/cleanup.go
index 3fc94ff7..6a694e2c 100644
--- a/controllers/submariner/cleanup.go
+++ b/controllers/submariner/cleanup.go
@@ -34,7 +34,7 @@ import (
 )
 
 func (r *Reconciler) runComponentCleanup(ctx context.Context, instance *operatorv1alpha1.Submariner) (reconcile.Result, error) {
-	if uninstall.IsSupportedForVersion(instance.Spec.Version) {
+	if !uninstall.IsSupportedForVersion(instance.Spec.Version) {
 		log.Info("Deleting Submariner version does not support uninstall", "version", instance.Spec.Version)
 		return reconcile.Result{}, r.removeFinalizer(ctx, instance)
 	}
diff --git a/controllers/uninstall/uninstall.go b/controllers/uninstall/uninstall.go
index de16a3bc..9c8d6543 100644
--- a/controllers/uninstall/uninstall.go
+++ b/controllers/uninstall/uninstall.go
@@ -325,5 +325,5 @@ func findPodsBySelector(ctx context.Context, clnt client.Reader, namespace strin
 
 func IsSupportedForVersion(version string) bool {
 	semVersion, _ := semver.NewVersion(version)
-	return !(semVersion != nil && !semVersion.LessThan(*minComponentUninstallVersion))
+	return semVersion == nil || !semVersion.LessThan(*minComponentUninstallVersion)
 }


Test patch:
diff --git a/controllers/submariner/submariner_controller_test.go b/controllers/submariner/submariner_controller_test.go
index 1d52926d..13998de0 100644
--- a/controllers/submariner/submariner_controller_test.go
+++ b/controllers/submariner/submariner_controller_test.go
@@ -317,6 +317,7 @@ func testDeletion() {
 	Context("and some components aren't installed", func() {
 		BeforeEach(func() {
 			t.submariner.Spec.GlobalCIDR = ""
+			t.submariner.Spec.Version = "devel"
 
 			t.InitClientObjs = append(t.InitClientObjs,
 				t.NewDaemonSet(names.GatewayComponent),