diff --git a/install/helm.go b/install/helm.go index 66cc95e185..c308a80f8d 100644 --- a/install/helm.go +++ b/install/helm.go @@ -169,23 +169,21 @@ func (k *K8sInstaller) getHelmValues() (map[string]interface{}, error) { } } + // Set nodeinit enabled option + if needsNodeInit(k.flavor.Kind, k.chartVersion) { + helmMapOpts["nodeinit.enabled"] = "true" + } + // Set Helm options specific to the detected Kubernetes cluster type switch k.flavor.Kind { case k8s.KindKind: helmMapOpts["ipam.mode"] = ipamKubernetes - case k8s.KindEKS: - helmMapOpts["nodeinit.enabled"] = "true" - case k8s.KindGKE: - helmMapOpts["nodeinit.enabled"] = "true" helmMapOpts["nodeinit.removeCbrBridge"] = "true" helmMapOpts["nodeinit.reconfigureKubelet"] = "true" helmMapOpts["cni.binPath"] = "/home/kubernetes/bin" - case k8s.KindAKS: - helmMapOpts["nodeinit.enabled"] = "true" - case k8s.KindMicrok8s: helmMapOpts["cni.binPath"] = Microk8sSnapPath + "/opt/cni/bin" helmMapOpts["cni.confPath"] = Microk8sSnapPath + "/args/cni-network" diff --git a/install/install.go b/install/install.go index f1416f91ce..752f507804 100644 --- a/install/install.go +++ b/install/install.go @@ -917,7 +917,7 @@ func (k *K8sInstaller) Install(ctx context.Context) error { }) // Create the node-init daemonset if one is required for the current kind. - if needsNodeInit(k.flavor.Kind) { + if needsNodeInit(k.flavor.Kind, k.chartVersion) { k.Log("🚀 Creating %s Node Init DaemonSet...", k.flavor.Kind.String()) ds := k.generateNodeInitDaemonSet(k.flavor.Kind) if _, err := k.client.CreateDaemonSet(ctx, k.params.Namespace, ds, metav1.CreateOptions{}); err != nil { diff --git a/install/node_init.go b/install/node_init.go index 038af49b9b..c8ca8a2c83 100644 --- a/install/node_init.go +++ b/install/node_init.go @@ -4,17 +4,24 @@ package install import ( - "github.com/cilium/cilium/pkg/versioncheck" + "github.com/blang/semver/v4" appsv1 "k8s.io/api/apps/v1" + "github.com/cilium/cilium/pkg/versioncheck" + "github.com/cilium/cilium-cli/internal/utils" "github.com/cilium/cilium-cli/k8s" ) -func needsNodeInit(k k8s.Kind) bool { +func needsNodeInit(k k8s.Kind, version semver.Version) bool { switch k { - case k8s.KindAKS, k8s.KindEKS, k8s.KindGKE: + + case k8s.KindAKS, k8s.KindGKE: return true + case k8s.KindEKS: + if versioncheck.MustCompile("<=1.13.1")(version) { + return true + } } return false } diff --git a/install/uninstall.go b/install/uninstall.go index 8faaa11b2c..4949256feb 100644 --- a/install/uninstall.go +++ b/install/uninstall.go @@ -10,6 +10,7 @@ import ( "strings" "time" + "github.com/blang/semver/v4" "github.com/cilium/workerpool" "helm.sh/helm/v3/pkg/action" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -34,16 +35,28 @@ type UninstallParameters struct { } type K8sUninstaller struct { - client k8sInstallerImplementation - params UninstallParameters - flavor k8s.Flavor + client k8sInstallerImplementation + params UninstallParameters + flavor k8s.Flavor + version semver.Version } func NewK8sUninstaller(client k8sInstallerImplementation, p UninstallParameters) *K8sUninstaller { - return &K8sUninstaller{ + uninstaller := &K8sUninstaller{ client: client, params: p, } + ciliumVersion, err := client.GetRunningCiliumVersion(context.Background(), p.Namespace) + if err != nil { + uninstaller.Log("Error getting Cilium Version: %s", err) + } + version, err := semver.Parse(ciliumVersion) + if err != nil { + uninstaller.Log("Error parsing Cilium Version: %s", err) + } else { + uninstaller.version = version + } + return uninstaller } func (k *K8sUninstaller) Log(format string, a ...interface{}) { @@ -133,7 +146,7 @@ func (k *K8sUninstaller) Uninstall(ctx context.Context) error { k.client.DeleteResourceQuota(ctx, k.params.Namespace, defaults.OperatorResourceQuota, metav1.DeleteOptions{}) } - if needsNodeInit(k.flavor.Kind) { + if needsNodeInit(k.flavor.Kind, k.version) { k.Log("🔥 Deleting node init daemonset...") k.client.DeleteDaemonSet(ctx, k.params.Namespace, defaults.NodeInitDaemonSetName, metav1.DeleteOptions{}) }