diff --git a/main.go b/main.go index 3836b8b7..6b09e517 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{