From 56e2e70f3f5835183698de60d647fe7607ea3b5c Mon Sep 17 00:00:00 2001 From: mprahl Date: Wed, 6 Dec 2023 17:09:01 -0500 Subject: [PATCH] Stop getting the K8s version of target cluster in uninstall mode The target Kubernetes cluster may not be up and running at the time of uninstall, so don't bother getting cluster version information. This also stops nsSelMgr.Start from being called when being uninstalled. Relates: https://issues.redhat.com/browse/ACM-8826 Signed-off-by: mprahl --- main.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index 3836b8b7..b2db9a0b 100644 --- a/main.go +++ b/main.go @@ -357,6 +357,7 @@ func main() { instanceName, _ := os.Hostname() // on an error, instanceName will be empty, which is ok var nsSelReconciler common.NamespaceSelectorReconciler + var dryRunSupported bool if !beingUninstalled { nsSelReconciler = common.NamespaceSelectorReconciler{ @@ -366,24 +367,24 @@ func main() { log.Error(err, "Unable to create controller", "controller", "NamespaceSelector") os.Exit(1) } - } - discoveryClient := discovery.NewDiscoveryClientForConfigOrDie(targetK8sConfig) + discoveryClient := discovery.NewDiscoveryClientForConfigOrDie(targetK8sConfig) - serverVersion, err := discoveryClient.ServerVersion() - if err != nil { - log.Error(err, "unable to detect the managed cluster's Kubernetes version") - os.Exit(1) - } + serverVersion, err := discoveryClient.ServerVersion() + if err != nil { + log.Error(err, "unable to detect the managed cluster's Kubernetes version") + os.Exit(1) + } - dryRunSupported := semver.Compare(serverVersion.GitVersion, "v1.18.0") >= 0 - if dryRunSupported { - log.Info("The managed cluster supports dry run API requests") - } else { - log.Info( - "The managed cluster does not support dry run API requests. Will assume that empty values are equal to " + - "not being set.", - ) + dryRunSupported = semver.Compare(serverVersion.GitVersion, "v1.18.0") >= 0 + if dryRunSupported { + log.Info("The managed cluster supports dry run API requests") + } else { + log.Info( + "The managed cluster does not support dry run API requests. Will assume that empty values are equal " + + "to not being set.", + ) + } } reconciler := controllers.ConfigurationPolicyReconciler{ @@ -500,7 +501,7 @@ func main() { wg.Done() }() - if opts.targetKubeConfig != "" { // "hosted mode" + if !beingUninstalled && opts.targetKubeConfig != "" { // "hosted mode" wg.Add(1) go func() {