diff --git a/kinder/pkg/cluster/manager/actions/kubeadm-config.go b/kinder/pkg/cluster/manager/actions/kubeadm-config.go index 5fef9708..b59015ba 100644 --- a/kinder/pkg/cluster/manager/actions/kubeadm-config.go +++ b/kinder/pkg/cluster/manager/actions/kubeadm-config.go @@ -276,6 +276,13 @@ func getKubeadmConfig(c *status.Cluster, n *status.Node, data kubeadm.ConfigData } patches = append(patches, fileDiscoveryPatch) + // add patches directory to the config + patchesDirectoryPatch, err := kubeadm.GetPatchesDirectoryPatch(kubeadmConfigVersion) + if err != nil { + return "", err + } + patches = append(patches, patchesDirectoryPatch) + // if the file discovery does not contains the authorization credentials, add tls discovery token if options.discoveryMode == FileDiscoveryWithoutCredentials { tlsBootstrapPatch, err := kubeadm.GetTLSBootstrapPatch(kubeadmConfigVersion) diff --git a/kinder/pkg/cluster/manager/actions/kubeadm-init.go b/kinder/pkg/cluster/manager/actions/kubeadm-init.go index 7164901a..60185379 100644 --- a/kinder/pkg/cluster/manager/actions/kubeadm-init.go +++ b/kinder/pkg/cluster/manager/actions/kubeadm-init.go @@ -42,9 +42,6 @@ func KubeadmInit(c *status.Cluster, usePhases bool, copyCertsMode CopyCertsMode, // if patcheDir is defined, copy the patches to the node if patchesDir != "" { - if cp1.MustKubeadmVersion().LessThan(constants.V1_19) { - return errors.New("--patches can't be used with kubeadm older than v1.19") - } if err := copyPatchesToNode(cp1, patchesDir); err != nil { return err } @@ -102,6 +99,12 @@ func kubeadmInit(cp1 *status.Node, copyCertsMode CopyCertsMode, patchesDir, igno ) } + if patchesDir != "" { + if cp1.MustKubeadmVersion().LessThan(constants.V1_22) { + initArgs = append(initArgs, "--experimental-patches", constants.PatchesDir) + } + } + if err := cp1.Command( "kubeadm", initArgs..., ).RunWithEcho(); err != nil { @@ -140,6 +143,13 @@ func kubeadmInitWithPhases(cp1 *status.Node, copyCertsMode CopyCertsMode, patche controlplaneArgs := []string{ "init", "phase", "control-plane", "all", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel), } + + if patchesDir != "" { + if cp1.MustKubeadmVersion().LessThan(constants.V1_22) { + controlplaneArgs = append(controlplaneArgs, "--experimental-patches", constants.PatchesDir) + } + } + if err := cp1.Command( "kubeadm", controlplaneArgs..., ).RunWithEcho(); err != nil { @@ -149,6 +159,11 @@ func kubeadmInitWithPhases(cp1 *status.Node, copyCertsMode CopyCertsMode, patche etcdArgs := []string{ "init", "phase", "etcd", "local", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel), } + if patchesDir != "" { + if cp1.MustKubeadmVersion().LessThan(constants.V1_22) { + etcdArgs = append(etcdArgs, "--experimental-patches", constants.PatchesDir) + } + } if err := cp1.Command( "kubeadm", etcdArgs..., ).RunWithEcho(); err != nil { diff --git a/kinder/pkg/cluster/manager/actions/kubeadm-join.go b/kinder/pkg/cluster/manager/actions/kubeadm-join.go index b1684361..347cf7c3 100644 --- a/kinder/pkg/cluster/manager/actions/kubeadm-join.go +++ b/kinder/pkg/cluster/manager/actions/kubeadm-join.go @@ -20,8 +20,6 @@ import ( "fmt" "time" - "github.com/pkg/errors" - "k8s.io/kubeadm/kinder/pkg/cluster/status" "k8s.io/kubeadm/kinder/pkg/constants" ) @@ -45,9 +43,6 @@ func joinControlPlanes(c *status.Cluster, usePhases bool, copyCertsMode CopyCert for _, cp2 := range c.SecondaryControlPlanes().EligibleForActions() { // if patcheDir is defined, copy the patches to the node if patchesDir != "" { - if cp2.MustKubeadmVersion().LessThan(constants.V1_19) { - return errors.New("--patches can't be used with kubeadm older than v1.19") - } if err := copyPatchesToNode(cp2, patchesDir); err != nil { return err } @@ -105,7 +100,11 @@ func kubeadmJoinControlPlane(cp *status.Node, patchesDir, ignorePreflightErrors fmt.Sprintf("--ignore-preflight-errors=%s", ignorePreflightErrors), fmt.Sprintf("--v=%d", vLevel), } - + if patchesDir != "" { + if cp.MustKubeadmVersion().LessThan(constants.V1_21) { + joinArgs = append(joinArgs, "--experimental-patches", constants.PatchesDir) + } + } if err := cp.Command( "kubeadm", joinArgs..., ).RunWithEcho(); err != nil { @@ -137,6 +136,12 @@ func kubeadmJoinControlPlaneWithPhases(cp *status.Node, patchesDir, ignorePrefli fmt.Sprintf("--v=%d", vLevel), } + if patchesDir != "" { + if cp.MustKubeadmVersion().LessThan(constants.V1_21) { + prepareArgs = append(prepareArgs, "--experimental-patches", constants.PatchesDir) + } + } + if err := cp.Command( "kubeadm", prepareArgs..., ).RunWithEcho(); err != nil { @@ -158,6 +163,11 @@ func kubeadmJoinControlPlaneWithPhases(cp *status.Node, patchesDir, ignorePrefli fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel), } + if patchesDir != "" { + if cp.MustKubeadmVersion().LessThan(constants.V1_21) { + controlPlaneArgs = append(controlPlaneArgs, "--experimental-patches", constants.PatchesDir) + } + } if err := cp.Command( "kubeadm", controlPlaneArgs..., diff --git a/kinder/pkg/cluster/manager/actions/kubeadm-upgrade.go b/kinder/pkg/cluster/manager/actions/kubeadm-upgrade.go index f9f9d76c..0e79e072 100644 --- a/kinder/pkg/cluster/manager/actions/kubeadm-upgrade.go +++ b/kinder/pkg/cluster/manager/actions/kubeadm-upgrade.go @@ -46,9 +46,6 @@ func KubeadmUpgrade(c *status.Cluster, upgradeVersion *K8sVersion.Version, patch for _, n := range nodeList { // if patcheDir is defined, copy the patches to the node if patchesDir != "" { - if n.MustKubeadmVersion().LessThan(constants.V1_19) { - return errors.New("--patches can't be used with kubeadm older than v1.19") - } if err := copyPatchesToNode(n, patchesDir); err != nil { return err } @@ -131,7 +128,9 @@ func kubeadmUpgradeApply(c *status.Cluster, cp1 *status.Node, upgradeVersion *K8 "upgrade", "apply", "-f", fmt.Sprintf("v%s", upgradeVersion), fmt.Sprintf("--v=%d", vLevel), } if patchesDir != "" { - applyArgs = append(applyArgs, "--patches", constants.PatchesDir) + if cp1.MustKubeadmVersion().LessThan(constants.V1_22) { + applyArgs = append(applyArgs, "--patches", constants.PatchesDir) + } } if err := cp1.Command( "kubeadm", applyArgs..., diff --git a/kinder/pkg/constants/constants.go b/kinder/pkg/constants/constants.go index 809f54f7..24e60fd8 100644 --- a/kinder/pkg/constants/constants.go +++ b/kinder/pkg/constants/constants.go @@ -118,8 +118,8 @@ const ( // kubernetes releases, used for branching code according to K8s release or kubeadm release version var ( - // V1.19 minor version - V1_19 = K8sVersion.MustParseSemantic("v1.19.0-0") + // V1.22 minor version + V1_22 = K8sVersion.MustParseSemantic("v1.22.0-0") ) // other constants diff --git a/kinder/pkg/kubeadm/config.go b/kinder/pkg/kubeadm/config.go index 0b82ddd1..79c69dec 100644 --- a/kinder/pkg/kubeadm/config.go +++ b/kinder/pkg/kubeadm/config.go @@ -173,8 +173,6 @@ nodeRegistration: criSocket: "/run/containerd/containerd.sock" kubeletExtraArgs: node-ip: "{{ .NodeAddress }}" -patches: - directory: "/kinder/patches" --- # no-op entry that exists solely so it can be patched apiVersion: kubeadm.k8s.io/v1beta2 @@ -196,8 +194,6 @@ discovery: apiServerEndpoint: "{{ .ControlPlaneEndpoint }}" token: "{{ .Token }}" unsafeSkipCAVerification: true -patches: - directory: "/kinder/patches" --- apiVersion: kubelet.config.k8s.io/v1beta1 kind: KubeletConfiguration diff --git a/kinder/pkg/kubeadm/discovery.go b/kinder/pkg/kubeadm/discovery.go index eac556f5..dc0fb058 100644 --- a/kinder/pkg/kubeadm/discovery.go +++ b/kinder/pkg/kubeadm/discovery.go @@ -93,6 +93,30 @@ discovery: file: kubeConfigPath: %s` +// GetPatchesDirectoryPatch returns the kubeadm config patch that will instruct kubeadm +// to use patches directory. +func GetPatchesDirectoryPatch(kubeadmConfigVersion string) (string, error) { + // select the patches for the kubeadm config version + log.Debugf("Preparing patches directory for kubeadm config %s", kubeadmConfigVersion) + + var patch string + switch kubeadmConfigVersion { + case "v1beta3": + patch = patchesDirectoryPatchv1beta3 + default: + return "", errors.Errorf("unknown kubeadm config version: %s", kubeadmConfigVersion) + } + + return fmt.Sprintf(patch, constants.PatchesDir), nil +} + +const patchesDirectoryPatchv1beta3 = `apiVersion: kubeadm.k8s.io/v1beta3 +kind: JoinConfiguration +metadata: + name: config +patches: + directory: %s` + // GetTLSBootstrapPatch returns the kubeadm config patch that will instruct kubeadm // to use a TLSBootstrap token. // NB. for sake of semplicity, we are using the same Token already used for Token discovery