Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add patches for join/init/upgrade to the right place #2545

Merged
merged 1 commit into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
63 changes: 63 additions & 0 deletions kinder/pkg/kubeadm/componentpatches.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2021 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package kubeadm

import (
"fmt"
"os"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"k8s.io/kubeadm/kinder/pkg/constants"
)

// GetPatchesDirectoryPatches returns the kubeadm config patches that will instruct kubeadm
// to use patches directory.
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 patchInit, patchJoin string
switch kubeadmConfigVersion {
case "v1beta3":
patchInit = patchesDirectoryPatchInitv1beta3
patchJoin = patchesDirectoryPatchJoinv1beta3
default:
return []string{}, errors.Errorf("unknown kubeadm config version: %s", kubeadmConfigVersion)
}
return []string{
fmt.Sprintf(patchInit, constants.PatchesDir),
fmt.Sprintf(patchJoin, constants.PatchesDir),
}, nil
}

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
patches:
directory: %s`
24 changes: 0 additions & 24 deletions kinder/pkg/kubeadm/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,6 @@ 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
Expand Down