From 23fe19faaafd2619fe5fb5a8a2effb7a0a42530a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 20 Feb 2024 15:37:52 -0500 Subject: [PATCH] fix: bypass deletion error if k3s is the configured scheduler and it isn't installed --- plugins/scheduler-k3s/functions.go | 7 +++++++ plugins/scheduler-k3s/triggers.go | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugins/scheduler-k3s/functions.go b/plugins/scheduler-k3s/functions.go index ad9e775ad..02648d068 100644 --- a/plugins/scheduler-k3s/functions.go +++ b/plugins/scheduler-k3s/functions.go @@ -1142,6 +1142,7 @@ func installHelm(ctx context.Context) error { return nil } +// isKubernetesAvailable returns an error if kubernetes api is not available func isKubernetesAvailable() error { client, err := NewKubernetesClient() if err != nil { @@ -1155,6 +1156,7 @@ func isKubernetesAvailable() error { return nil } +// isK3sInstalled returns an error if k3s is not installed func isK3sInstalled() error { if !common.FileExists("/usr/local/bin/k3s") { return fmt.Errorf("k3s binary is not available") @@ -1167,6 +1169,11 @@ func isK3sInstalled() error { return nil } +// isK3sKubernetes returns true if the current kubernetes cluster is configured to be k3s +func isK3sKubernetes() bool { + return getKubeconfigPath() == KubeConfigPath +} + func isPodReady(ctx context.Context, clientset KubernetesClient, podName, namespace string) wait.ConditionWithContextFunc { return func(ctx context.Context) (bool, error) { fmt.Printf(".") diff --git a/plugins/scheduler-k3s/triggers.go b/plugins/scheduler-k3s/triggers.go index 589d73c61..2ab9aeab8 100644 --- a/plugins/scheduler-k3s/triggers.go +++ b/plugins/scheduler-k3s/triggers.go @@ -1159,6 +1159,24 @@ func TriggerSchedulerPostDelete(scheduler string, appName string) error { return nil } + dataErr := common.RemoveAppDataDirectory("logs", appName) + propertyErr := common.PropertyDestroy("logs", appName) + + if dataErr != nil { + return dataErr + } + + if propertyErr != nil { + return propertyErr + } + + if isK3sKubernetes() { + if err := isK3sInstalled(); err != nil { + common.LogWarn("k3s is not installed, skipping") + return nil + } + } + if err := isKubernetesAvailable(); err != nil { return fmt.Errorf("kubernetes api not available: %w", err) }