Skip to content

Commit

Permalink
use patches to patch patchesDirectory for upgrade; experimental-patch…
Browse files Browse the repository at this point in the history
…es for 1.20-1.21

Signed-off-by: Paco Xu <[email protected]>
Co-authored-by: Lubomir I. Ivanov <[email protected]>
  • Loading branch information
pacoxu and neolit123 committed Aug 3, 2021
1 parent 11626e7 commit 2dad6ff
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 deletions.
7 changes: 7 additions & 0 deletions kinder/pkg/cluster/manager/actions/kubeadm-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetPatchesDirectory(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)
Expand Down
21 changes: 21 additions & 0 deletions kinder/pkg/cluster/manager/actions/kubeadm-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ func kubeadmInit(cp1 *status.Node, copyCertsMode CopyCertsMode, patchesDir, igno
)
}

if patchesDir != "" {
if cp1.MustKubeadmVersion().LessThan(constants.V1_21) {
initArgs = append(initArgs, "--experimental-patches", constants.PatchesDir)
}
if err := copyPatchesToNode(cp1, patchesDir); err != nil {
return err
}
}

if err := cp1.Command(
"kubeadm", initArgs...,
).RunWithEcho(); err != nil {
Expand Down Expand Up @@ -140,6 +149,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_21) {
controlplaneArgs = append(controlplaneArgs, "--experimental-patches", constants.PatchesDir)
}
}

if err := cp1.Command(
"kubeadm", controlplaneArgs...,
).RunWithEcho(); err != nil {
Expand All @@ -149,6 +165,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_21) {
etcdArgs = append(etcdArgs, "--experimental-patches", constants.PatchesDir)
}
}
if err := cp1.Command(
"kubeadm", etcdArgs...,
).RunWithEcho(); err != nil {
Expand Down
16 changes: 15 additions & 1 deletion kinder/pkg/cluster/manager/actions/kubeadm-join.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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 {
Expand Down Expand Up @@ -136,6 +140,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) {
prepareArgs = append(prepareArgs, "--experimental-patches", constants.PatchesDir)
}
}

if err := cp.Command(
"kubeadm", prepareArgs...,
Expand All @@ -158,6 +167,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...,
Expand Down
2 changes: 2 additions & 0 deletions kinder/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ const (
var (
// V1.19 minor version
V1_19 = K8sVersion.MustParseSemantic("v1.19.0-0")
// V1.21 minor version
V1_21 = K8sVersion.MustParseSemantic("v1.21.0-0")
)

// other constants
Expand Down
4 changes: 0 additions & 4 deletions kinder/pkg/kubeadm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -196,8 +194,6 @@ discovery:
apiServerEndpoint: "{{ .ControlPlaneEndpoint }}"
token: "{{ .Token }}"
unsafeSkipCAVerification: true
patches:
directory: "/kinder/patches"
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
Expand Down
24 changes: 24 additions & 0 deletions kinder/pkg/kubeadm/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ discovery:
file:
kubeConfigPath: %s`

// GetPatchesDirectory 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
Expand Down

0 comments on commit 2dad6ff

Please sign in to comment.