Skip to content

Commit

Permalink
Stop getting the K8s version of target cluster in uninstall mode
Browse files Browse the repository at this point in the history
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 <mprahl@users.noreply.github.com>
  • Loading branch information
mprahl authored and openshift-merge-bot[bot] committed Dec 7, 2023
1 parent 2476d97 commit 56e2e70
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -500,7 +501,7 @@ func main() {
wg.Done()
}()

if opts.targetKubeConfig != "" { // "hosted mode"
if !beingUninstalled && opts.targetKubeConfig != "" { // "hosted mode"
wg.Add(1)

go func() {
Expand Down

0 comments on commit 56e2e70

Please sign in to comment.