Skip to content

Commit

Permalink
kinder: remove the handling of 1.25 and older versions of k8s
Browse files Browse the repository at this point in the history
- Remove the repository replace from k8s.gcr.io -> registry.k8s.io
- Remove "kubelet-config-x.yy" handling, use "kubelet-config"
- Stop untainting "master" taints, only untaint control-plane taints
- Stop handling --experimental-patches, use --patches
  • Loading branch information
neolit123 committed Dec 11, 2023
1 parent 206bff7 commit 6213a3e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 112 deletions.
5 changes: 0 additions & 5 deletions kinder/pkg/build/alter/alter.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,11 @@ func (c *Context) Alter() (err error) {
// initialize bits installers
var bitsInstallers []bits.Installer

// TODO: remove the KubeadmBinaryVer workaround once we no longer test the kubeadm 1.25 / k8s 1.24 skew.
// See pkg/cri/host/archive.go.

host.KubeadmBinaryVer = c.initArtifactsSrc
if c.initArtifactsSrc != "" {
bitsInstallers = append(bitsInstallers, bits.NewInitBits(c.initArtifactsSrc))
}

if c.kubeadmSrc != "" {
host.KubeadmBinaryVer = c.kubeadmSrc
bitsInstallers = append(bitsInstallers, bits.NewBinaryBits(c.kubeadmSrc, "kubeadm"))
}
if c.kubeletSrc != "" {
Expand Down
36 changes: 7 additions & 29 deletions kinder/pkg/cluster/manager/actions/kubeadm-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (

"github.com/pkg/errors"

"k8s.io/apimachinery/pkg/util/version"

"k8s.io/kubeadm/kinder/pkg/cluster/manager/actions/assets"
"k8s.io/kubeadm/kinder/pkg/cluster/status"
"k8s.io/kubeadm/kinder/pkg/constants"
Expand Down Expand Up @@ -67,9 +65,9 @@ func KubeadmInit(c *status.Cluster, usePhases bool, copyCertsMode CopyCertsMode,

// execs the kubeadm init workflow
if usePhases {
err = kubeadmInitWithPhases(cp1, copyCertsMode, patchesDir, ignorePreflightErrors, vLevel)
err = kubeadmInitWithPhases(cp1, copyCertsMode, ignorePreflightErrors, vLevel)
} else {
err = kubeadmInit(cp1, copyCertsMode, patchesDir, ignorePreflightErrors, vLevel)
err = kubeadmInit(cp1, copyCertsMode, ignorePreflightErrors, vLevel)
}
if err != nil {
return err
Expand All @@ -83,7 +81,7 @@ func KubeadmInit(c *status.Cluster, usePhases bool, copyCertsMode CopyCertsMode,
return nil
}

func kubeadmInit(cp1 *status.Node, copyCertsMode CopyCertsMode, patchesDir, ignorePreflightErrors string, vLevel int) error {
func kubeadmInit(cp1 *status.Node, copyCertsMode CopyCertsMode, ignorePreflightErrors string, vLevel int) error {
initArgs := []string{
"init",
fmt.Sprintf("--ignore-preflight-errors=%s", ignorePreflightErrors),
Expand All @@ -96,11 +94,6 @@ func kubeadmInit(cp1 *status.Node, copyCertsMode CopyCertsMode, patchesDir, igno
// NB. certificate key is passed via the config file)
)
}
if patchesDir != "" {
if cp1.MustKubeadmVersion().LessThan(constants.V1_22) {
initArgs = append(initArgs, "--experimental-patches", constants.PatchesDir)
}
}

if err := cp1.Command(
"kubeadm", initArgs...,
Expand All @@ -111,7 +104,7 @@ func kubeadmInit(cp1 *status.Node, copyCertsMode CopyCertsMode, patchesDir, igno
return nil
}

func kubeadmInitWithPhases(cp1 *status.Node, copyCertsMode CopyCertsMode, patchesDir, ignorePreflightErrors string, vLevel int) error {
func kubeadmInitWithPhases(cp1 *status.Node, copyCertsMode CopyCertsMode, ignorePreflightErrors string, vLevel int) error {
if err := cp1.Command(
"kubeadm", "init", "phase", "preflight", fmt.Sprintf("--config=%s", constants.KubeadmConfigPath), fmt.Sprintf("--v=%d", vLevel),
fmt.Sprintf("--ignore-preflight-errors=%s", ignorePreflightErrors),
Expand Down Expand Up @@ -140,11 +133,6 @@ 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 {
Expand All @@ -154,11 +142,6 @@ 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 {
Expand Down Expand Up @@ -229,15 +212,10 @@ func postInit(c *status.Cluster, wait time.Duration) error {
}

if len(c.Workers()) == 0 {
// TODO: Once kubeadm 1.23 is no longer supported remove the <1.24 handling.
// TODO: Remove only the "control-plane" taint for kubeadm >= 1.25.
// https://github.com/kubernetes/kubeadm/issues/2200
taints := []string{"node-role.kubernetes.io/control-plane-", "node-role.kubernetes.io/master-"}
if cp1.MustKubeadmVersion().LessThan(version.MustParseSemantic("v1.24.0")) {
taints = []string{"node-role.kubernetes.io/master-"}
taintArgs := []string{
"--kubeconfig=/etc/kubernetes/admin.conf", "taint", "nodes", "--all",
"node-role.kubernetes.io/control-plane-",
}
taintArgs := []string{"--kubeconfig=/etc/kubernetes/admin.conf", "taint", "nodes", "--all"}
taintArgs = append(taintArgs, taints...)
if err := cp1.Command(
"kubectl", taintArgs...,
).RunWithEcho(); err != nil {
Expand Down
24 changes: 4 additions & 20 deletions kinder/pkg/cluster/manager/actions/kubeadm-join.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func joinControlPlanes(c *status.Cluster, usePhases bool, copyCertsMode CopyCert

// executes the kubeadm join control-plane workflow
if usePhases {
err = kubeadmJoinControlPlaneWithPhases(cp2, patchesDir, ignorePreflightErrors, vLevel)
err = kubeadmJoinControlPlaneWithPhases(cp2, ignorePreflightErrors, vLevel)
} else {
err = kubeadmJoinControlPlane(cp2, patchesDir, ignorePreflightErrors, vLevel)
err = kubeadmJoinControlPlane(cp2, ignorePreflightErrors, vLevel)
}
if err != nil {
return err
Expand All @@ -90,18 +90,13 @@ func joinControlPlanes(c *status.Cluster, usePhases bool, copyCertsMode CopyCert
return nil
}

func kubeadmJoinControlPlane(cp *status.Node, patchesDir, ignorePreflightErrors string, vLevel int) (err error) {
func kubeadmJoinControlPlane(cp *status.Node, ignorePreflightErrors string, vLevel int) (err error) {
joinArgs := []string{
"join",
fmt.Sprintf("--config=%s", constants.KubeadmConfigPath),
fmt.Sprintf("--ignore-preflight-errors=%s", ignorePreflightErrors),
fmt.Sprintf("--v=%d", vLevel),
}
if patchesDir != "" {
if cp.MustKubeadmVersion().LessThan(constants.V1_22) {
joinArgs = append(joinArgs, "--experimental-patches", constants.PatchesDir)
}
}

if err := cp.Command(
"kubeadm", joinArgs...,
Expand All @@ -112,7 +107,7 @@ func kubeadmJoinControlPlane(cp *status.Node, patchesDir, ignorePreflightErrors
return nil
}

func kubeadmJoinControlPlaneWithPhases(cp *status.Node, patchesDir, ignorePreflightErrors string, vLevel int) (err error) {
func kubeadmJoinControlPlaneWithPhases(cp *status.Node, ignorePreflightErrors string, vLevel int) (err error) {
// kubeadm join phase preflight
preflightArgs := []string{
"join", "phase", "preflight",
Expand All @@ -134,12 +129,6 @@ func kubeadmJoinControlPlaneWithPhases(cp *status.Node, patchesDir, ignorePrefli
fmt.Sprintf("--v=%d", vLevel),
}

if patchesDir != "" {
if cp.MustKubeadmVersion().LessThan(constants.V1_22) {
prepareArgs = append(prepareArgs, "--experimental-patches", constants.PatchesDir)
}
}

if err := cp.Command(
"kubeadm", prepareArgs...,
).RunWithEcho(); err != nil {
Expand All @@ -161,11 +150,6 @@ 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_22) {
controlPlaneArgs = append(controlPlaneArgs, "--experimental-patches", constants.PatchesDir)
}
}

if err := cp.Command(
"kubeadm", controlPlaneArgs...,
Expand Down
12 changes: 2 additions & 10 deletions kinder/pkg/cluster/manager/actions/kubeadm-upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ 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 != "" {
if cp1.MustKubeadmVersion().LessThan(constants.V1_22) {
applyArgs = append(applyArgs, "--experimental-patches", constants.PatchesDir)
} else {
applyArgs = append(applyArgs, "--patches", constants.PatchesDir)
}
applyArgs = append(applyArgs, "--patches", constants.PatchesDir)
}
if len(featureGate) > 0 {
applyArgs = append(applyArgs, fmt.Sprintf("--feature-gates=%s", featureGate))
Expand Down Expand Up @@ -160,11 +156,7 @@ func kubeadmUpgradeNode(c *status.Cluster, n *status.Node, upgradeVersion *K8sVe
"upgrade", "node", fmt.Sprintf("--v=%d", vLevel),
}
if patchesDir != "" {
if n.MustKubeadmVersion().LessThan(constants.V1_22) {
nodeArgs = append(nodeArgs, fmt.Sprintf("--experimental-patches=%s", constants.PatchesDir))
} else {
nodeArgs = append(nodeArgs, fmt.Sprintf("--patches=%s", constants.PatchesDir))
}
nodeArgs = append(nodeArgs, fmt.Sprintf("--patches=%s", constants.PatchesDir))
}
if err := n.Command(
"kubeadm", nodeArgs...,
Expand Down
16 changes: 0 additions & 16 deletions kinder/pkg/cluster/manager/actions/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,6 @@ func staticPodHasVersion(pod, version string) func(c *status.Cluster, n *status.
func kubeletHasRBAC(major, minor uint) func(c *status.Cluster, n *status.Node) bool {
return func(c *status.Cluster, n *status.Node) bool {
for i := 0; i < 5; i++ {
// Try the new kubelet config naming scheme and fallback to the old one.
//
// TODO: remove handling of the old CM once kinder no longer
// manages clusters with the legacy kubelet ConfigMap -
// i.e. when 1.24 is out of support.
// https://github.com/kubernetes/kubeadm/issues/1582
output1 := kubectlOutput(n,
"auth",
"can-i",
Expand All @@ -343,16 +337,6 @@ func kubeletHasRBAC(major, minor uint) func(c *status.Cluster, n *status.Node) b
"--namespace=kube-system",
"configmaps/kubelet-config",
)
if output1 != "yes" {
output1 = kubectlOutput(n,
"auth",
"can-i",
"get",
"--kubeconfig=/etc/kubernetes/kubelet.conf",
"--namespace=kube-system",
fmt.Sprintf("configmaps/kubelet-config-%d.%d", major, minor),
)
}
output2 := kubectlOutput(n,
"auth",
"can-i",
Expand Down
10 changes: 0 additions & 10 deletions kinder/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ limitations under the License.

package constants

import (
K8sVersion "k8s.io/apimachinery/pkg/util/version"
)

// constants inherited from kind.
// those values are replicated here with the goal to keep under strict control kind dependencies
const (
Expand Down Expand Up @@ -116,12 +112,6 @@ const (
PatchesDir = "/kinder/patches"
)

// kubernetes releases, used for branching code according to K8s release or kubeadm release version
var (
// V1.22 minor version
V1_22 = K8sVersion.MustParseSemantic("v1.22.0-0")
)

// other constants
const (
// KinderVersion is the kinder CLI version
Expand Down
22 changes: 0 additions & 22 deletions kinder/pkg/cri/host/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"io"
"os"
"strings"

"k8s.io/apimachinery/pkg/util/version"
)

// TODO: investigate if we can get rid of this or simplify it.
Expand Down Expand Up @@ -79,24 +77,6 @@ func GetArchiveTags(path string) ([]string, error) {
return res, nil
}

// Temporary workaround to allow detecting the transition to registry.k8s.io in kubeadm 1.22~1.25.
// TODO: remove KubeadmVer and replaceKubeadm125Repository() once we no longer test the
// kubeadm 1.25 / k8s 1.24 skew

// KubeadmBinaryVer tracks the version of the kubeadm binary
var KubeadmBinaryVer string

func replaceKubeadm125Repository(repository string) string {
if len(KubeadmBinaryVer) == 0 {
return repository
}
v := version.MustParseSemantic(KubeadmBinaryVer)
if v.AtLeast(version.MustParseSemantic("v1.22.0-0")) && strings.HasPrefix(repository, "k8s.gcr.io") {
return strings.Replace(repository, "k8s.gcr.io", "registry.k8s.io", -1)
}
return repository
}

// EditArchiveRepositories applies edit to reader's image repositories,
// IE the repository part of repository:tag in image tags
// This supports v1 / v1.1 / v1.2 Docker Image Archives
Expand Down Expand Up @@ -168,7 +148,6 @@ func editRepositoriesFile(raw []byte, editRepositories func(string) string) ([]b

fixed := make(archiveRepositories)
for repository, tagsToRefs := range tags {
repository = replaceKubeadm125Repository(repository)
fixed[editRepositories(repository)] = tagsToRefs
}

Expand Down Expand Up @@ -197,7 +176,6 @@ func editManifestRepositories(raw []byte, editRepositories func(string) string)
return nil, fmt.Errorf("invalid repotag: %s", entry)
}
parts[0] = editRepositories(parts[0])
parts[0] = replaceKubeadm125Repository(parts[0])
fixed[i] = strings.Join(parts, ":")
}

Expand Down

0 comments on commit 6213a3e

Please sign in to comment.