Skip to content

Commit

Permalink
add patches for join/init/upgrade to the right place; use `/tmp/kubea…
Browse files Browse the repository at this point in the history
…dm-patches` as the test prepares in this folder

Signed-off-by: Paco Xu <[email protected]>
  • Loading branch information
pacoxu committed Aug 13, 2021
1 parent 9894a3c commit 524a57a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
14 changes: 7 additions & 7 deletions kinder/pkg/cluster/manager/actions/kubeadm-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ func getKubeadmConfig(c *status.Cluster, n *status.Node, data kubeadm.ConfigData
patches = append(patches, automaticCopyCertsPatches...)
}

// add patches directory to the config
patchesDirectoryPatches, err := kubeadm.GetPatchesDirectoryPatches(kubeadmConfigVersion)
// skip if kubeadm config version is not v1beta3
if err == nil {
patches = append(patches, patchesDirectoryPatches...)
}

// if requested to use file discovery and not the first control-plane, add patches for using file discovery
if options.discoveryMode != TokenDiscovery && !(n == c.BootstrapControlPlane()) {
// remove token from config
Expand All @@ -276,13 +283,6 @@ 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)
Expand Down
2 changes: 1 addition & 1 deletion kinder/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const (
DiscoveryFile = "/kinder/discovery.conf"

// PatchesDir defines the path to patches stored on node
PatchesDir = "/kinder/patches"
PatchesDir = "/tmp/kubeadm-patches"
)

// kubernetes releases, used for branching code according to K8s release or kubeadm release version
Expand Down
31 changes: 23 additions & 8 deletions kinder/pkg/kubeadm/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package kubeadm

import (
"fmt"
"os"

"github.com/pkg/errors"

Expand Down Expand Up @@ -93,24 +94,38 @@ discovery:
file:
kubeConfigPath: %s`

// GetPatchesDirectoryPatch returns the kubeadm config patch that will instruct kubeadm
// GetPatchesDirectoryPatches returns the kubeadm config patches that will instruct kubeadm
// to use patches directory.
func GetPatchesDirectoryPatch(kubeadmConfigVersion string) (string, error) {
func GetPatchesDirectoryPatches(kubeadmConfigVersion string) ([]string, error) {
// select the patches for the kubeadm config version
log.Debugf("Preparing patches directory for kubeadm config %s", kubeadmConfigVersion)
if _, err := os.Stat(constants.PatchesDir); os.IsNotExist(err) {
return []string{}, nil
}

var patch string
var patchInit string
var patchJoin string
switch kubeadmConfigVersion {
case "v1beta3":
patch = patchesDirectoryPatchv1beta3
patchInit = patchesDirectoryPatchInitv1beta3
patchJoin = patchesDirectoryPatchJoinv1beta3
default:
return "", errors.Errorf("unknown kubeadm config version: %s", kubeadmConfigVersion)
return []string{}, errors.Errorf("unknown kubeadm config version: %s", kubeadmConfigVersion)
}

return fmt.Sprintf(patch, constants.PatchesDir), nil
return []string{
fmt.Sprintf(patchInit, constants.PatchesDir),
fmt.Sprintf(patchJoin, constants.PatchesDir),
}, nil
}

const patchesDirectoryPatchv1beta3 = `apiVersion: kubeadm.k8s.io/v1beta3
const patchesDirectoryPatchInitv1beta3 = `apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
metadata:
name: config
patches:
directory: %s`

const patchesDirectoryPatchJoinv1beta3 = `apiVersion: kubeadm.k8s.io/v1beta3
kind: JoinConfiguration
metadata:
name: config
Expand Down

0 comments on commit 524a57a

Please sign in to comment.