mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-29 05:22:37 +00:00
kubeadm: plumb the patches option trough init/join/upgrade
This changes adds the "patches" option in all places where the "kustomize" option is already present.
This commit is contained in:
parent
5506049b87
commit
144778db83
@ -463,6 +463,7 @@ func isAllowedFlag(flagName string) bool {
|
||||
kubeadmcmdoptions.KubeconfigDir,
|
||||
kubeadmcmdoptions.UploadCerts,
|
||||
kubeadmcmdoptions.Kustomize,
|
||||
kubeadmcmdoptions.Patches,
|
||||
"print-join-command", "rootfs", "v")
|
||||
if knownFlags.Has(flagName) {
|
||||
return true
|
||||
|
@ -99,6 +99,7 @@ type initOptions struct {
|
||||
uploadCerts bool
|
||||
skipCertificateKeyPrint bool
|
||||
kustomizeDir string
|
||||
patchesDir string
|
||||
}
|
||||
|
||||
// compile-time assert that the local data object satisfies the phases data interface.
|
||||
@ -121,6 +122,7 @@ type initData struct {
|
||||
uploadCerts bool
|
||||
skipCertificateKeyPrint bool
|
||||
kustomizeDir string
|
||||
patchesDir string
|
||||
}
|
||||
|
||||
// NewCmdInit returns "kubeadm init" command.
|
||||
@ -277,6 +279,7 @@ func AddInitOtherFlags(flagSet *flag.FlagSet, initOptions *initOptions) {
|
||||
"Don't print the key used to encrypt the control-plane certificates.",
|
||||
)
|
||||
options.AddKustomizePodsFlag(flagSet, &initOptions.kustomizeDir)
|
||||
options.AddPatchesFlag(flagSet, &initOptions.patchesDir)
|
||||
}
|
||||
|
||||
// newInitOptions returns a struct ready for being used for creating cmd init flags.
|
||||
@ -413,6 +416,7 @@ func newInitData(cmd *cobra.Command, args []string, options *initOptions, out io
|
||||
uploadCerts: options.uploadCerts,
|
||||
skipCertificateKeyPrint: options.skipCertificateKeyPrint,
|
||||
kustomizeDir: options.kustomizeDir,
|
||||
patchesDir: options.patchesDir,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -550,6 +554,11 @@ func (d *initData) KustomizeDir() string {
|
||||
return d.kustomizeDir
|
||||
}
|
||||
|
||||
// PatchesDir returns the folder where patches for components are stored
|
||||
func (d *initData) PatchesDir() string {
|
||||
return d.patchesDir
|
||||
}
|
||||
|
||||
func printJoinCommand(out io.Writer, adminKubeConfigPath, token string, i *initData) error {
|
||||
joinControlPlaneCommand, err := cmdutil.GetJoinControlPlaneCommand(adminKubeConfigPath, token, i.CertificateKey(), i.skipTokenPrint, i.skipCertificateKeyPrint)
|
||||
if err != nil {
|
||||
|
@ -130,6 +130,7 @@ type joinOptions struct {
|
||||
externalcfg *kubeadmapiv1beta2.JoinConfiguration
|
||||
joinControlPlane *kubeadmapiv1beta2.JoinControlPlane
|
||||
kustomizeDir string
|
||||
patchesDir string
|
||||
}
|
||||
|
||||
// compile-time assert that the local data object satisfies the phases data interface.
|
||||
@ -145,6 +146,7 @@ type joinData struct {
|
||||
ignorePreflightErrors sets.String
|
||||
outputWriter io.Writer
|
||||
kustomizeDir string
|
||||
patchesDir string
|
||||
}
|
||||
|
||||
// NewCmdJoin returns "kubeadm join" command.
|
||||
@ -286,6 +288,7 @@ func addJoinOtherFlags(flagSet *flag.FlagSet, joinOptions *joinOptions) {
|
||||
"Create a new control plane instance on this node",
|
||||
)
|
||||
options.AddKustomizePodsFlag(flagSet, &joinOptions.kustomizeDir)
|
||||
options.AddPatchesFlag(flagSet, &joinOptions.patchesDir)
|
||||
}
|
||||
|
||||
// newJoinOptions returns a struct ready for being used for creating cmd join flags.
|
||||
@ -441,6 +444,7 @@ func newJoinData(cmd *cobra.Command, args []string, opt *joinOptions, out io.Wri
|
||||
ignorePreflightErrors: ignorePreflightErrorsSet,
|
||||
outputWriter: out,
|
||||
kustomizeDir: opt.kustomizeDir,
|
||||
patchesDir: opt.patchesDir,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -511,6 +515,11 @@ func (j *joinData) KustomizeDir() string {
|
||||
return j.kustomizeDir
|
||||
}
|
||||
|
||||
// PatchesDir returns the folder where patches for components are stored
|
||||
func (j *joinData) PatchesDir() string {
|
||||
return j.patchesDir
|
||||
}
|
||||
|
||||
// fetchInitConfigurationFromJoinConfiguration retrieves the init configuration from a join configuration, performing the discovery
|
||||
func fetchInitConfigurationFromJoinConfiguration(cfg *kubeadmapi.JoinConfiguration, tlsBootstrapCfg *clientcmdapi.Config) (*kubeadmapi.InitConfiguration, error) {
|
||||
// Retrieves the kubeadm configuration
|
||||
|
@ -145,6 +145,6 @@ func runControlPlaneSubphase(component string) func(c workflow.RunData) error {
|
||||
cfg := data.Cfg()
|
||||
|
||||
fmt.Printf("[control-plane] Creating static Pod manifest for %q\n", component)
|
||||
return controlplane.CreateStaticPodFiles(data.ManifestDir(), data.KustomizeDir(), &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, component)
|
||||
return controlplane.CreateStaticPodFiles(data.ManifestDir(), data.KustomizeDir(), data.PatchesDir(), &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, component)
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,5 @@ type InitData interface {
|
||||
Client() (clientset.Interface, error)
|
||||
Tokens() []string
|
||||
KustomizeDir() string
|
||||
PatchesDir() string
|
||||
}
|
||||
|
@ -49,3 +49,4 @@ func (t *testInitData) OutputWriter() io.Writer { return nil }
|
||||
func (t *testInitData) Client() (clientset.Interface, error) { return nil, nil }
|
||||
func (t *testInitData) Tokens() []string { return nil }
|
||||
func (t *testInitData) KustomizeDir() string { return "" }
|
||||
func (t *testInitData) PatchesDir() string { return "" }
|
||||
|
@ -70,6 +70,7 @@ func getEtcdPhaseFlags() []string {
|
||||
options.CfgPath,
|
||||
options.ImageRepository,
|
||||
options.Kustomize,
|
||||
options.Patches,
|
||||
}
|
||||
return flags
|
||||
}
|
||||
@ -93,7 +94,7 @@ func runEtcdPhaseLocal() func(c workflow.RunData) error {
|
||||
fmt.Printf("[dryrun] Would ensure that %q directory is present\n", cfg.Etcd.Local.DataDir)
|
||||
}
|
||||
fmt.Printf("[etcd] Creating static Pod manifest for local etcd in %q\n", data.ManifestDir())
|
||||
if err := etcdphase.CreateLocalEtcdStaticPodManifestFile(data.ManifestDir(), data.KustomizeDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
|
||||
if err := etcdphase.CreateLocalEtcdStaticPodManifestFile(data.ManifestDir(), data.KustomizeDir(), data.PatchesDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
|
||||
return errors.Wrap(err, "error creating local etcd static pod manifest file")
|
||||
}
|
||||
} else {
|
||||
|
@ -43,7 +43,7 @@ func getControlPlaneJoinPhaseFlags(name string) []string {
|
||||
options.NodeName,
|
||||
}
|
||||
if name == "etcd" {
|
||||
flags = append(flags, options.Kustomize)
|
||||
flags = append(flags, options.Kustomize, options.Patches)
|
||||
}
|
||||
if name != "mark-control-plane" {
|
||||
flags = append(flags, options.APIServerAdvertiseAddress)
|
||||
@ -139,8 +139,9 @@ func runEtcdPhase(c workflow.RunData) error {
|
||||
// From https://coreos.com/etcd/docs/latest/v2/runtime-configuration.html
|
||||
// "If you add a new member to a 1-node cluster, the cluster cannot make progress before the new member starts
|
||||
// because it needs two members as majority to agree on the consensus. You will only see this behavior between the time
|
||||
// etcdctl member add informs the cluster about the new member and the new member successfully establishing a connection to the // existing one."
|
||||
if err := etcdphase.CreateStackedEtcdStaticPodManifestFile(client, kubeadmconstants.GetStaticPodDirectory(), data.KustomizeDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
|
||||
// etcdctl member add informs the cluster about the new member and the new member successfully establishing a connection to the
|
||||
// existing one."
|
||||
if err := etcdphase.CreateStackedEtcdStaticPodManifestFile(client, kubeadmconstants.GetStaticPodDirectory(), data.KustomizeDir(), data.PatchesDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
|
||||
return errors.Wrap(err, "error creating local etcd static pod manifest file")
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,7 @@ func getControlPlanePreparePhaseFlags(name string) []string {
|
||||
options.TokenStr,
|
||||
options.CertificateKey,
|
||||
options.Kustomize,
|
||||
options.Patches,
|
||||
}
|
||||
case "download-certs":
|
||||
flags = []string{
|
||||
@ -124,6 +125,7 @@ func getControlPlanePreparePhaseFlags(name string) []string {
|
||||
options.CfgPath,
|
||||
options.ControlPlane,
|
||||
options.Kustomize,
|
||||
options.Patches,
|
||||
}
|
||||
default:
|
||||
flags = []string{}
|
||||
@ -190,6 +192,7 @@ func runControlPlanePrepareControlPlaneSubphase(c workflow.RunData) error {
|
||||
err := controlplane.CreateStaticPodFiles(
|
||||
kubeadmconstants.GetStaticPodDirectory(),
|
||||
data.KustomizeDir(),
|
||||
data.PatchesDir(),
|
||||
&cfg.ClusterConfiguration,
|
||||
&cfg.LocalAPIEndpoint,
|
||||
component,
|
||||
|
@ -36,4 +36,5 @@ type JoinData interface {
|
||||
IgnorePreflightErrors() sets.String
|
||||
OutputWriter() io.Writer
|
||||
KustomizeDir() string
|
||||
PatchesDir() string
|
||||
}
|
||||
|
@ -39,3 +39,4 @@ func (j *testJoinData) ClientSet() (*clientset.Clientset, error) { return
|
||||
func (j *testJoinData) IgnorePreflightErrors() sets.String { return nil }
|
||||
func (j *testJoinData) OutputWriter() io.Writer { return nil }
|
||||
func (j *testJoinData) KustomizeDir() string { return "" }
|
||||
func (j *testJoinData) PatchesDir() string { return "" }
|
||||
|
@ -40,6 +40,7 @@ func NewControlPlane() workflow.Phase {
|
||||
options.CertificateRenewal,
|
||||
options.EtcdUpgrade,
|
||||
options.Kustomize,
|
||||
options.Patches,
|
||||
},
|
||||
}
|
||||
return phase
|
||||
@ -65,16 +66,17 @@ func runControlPlane() func(c workflow.RunData) error {
|
||||
etcdUpgrade := data.EtcdUpgrade()
|
||||
renewCerts := data.RenewCerts()
|
||||
kustomizeDir := data.KustomizeDir()
|
||||
patchesDir := data.PatchesDir()
|
||||
|
||||
// Upgrade the control plane and etcd if installed on this node
|
||||
fmt.Printf("[upgrade] Upgrading your Static Pod-hosted control plane instance to version %q...\n", cfg.KubernetesVersion)
|
||||
if dryRun {
|
||||
return upgrade.DryRunStaticPodUpgrade(kustomizeDir, cfg)
|
||||
return upgrade.DryRunStaticPodUpgrade(kustomizeDir, patchesDir, cfg)
|
||||
}
|
||||
|
||||
waiter := apiclient.NewKubeWaiter(data.Client(), upgrade.UpgradeManifestTimeout, os.Stdout)
|
||||
|
||||
if err := upgrade.PerformStaticPodUpgrade(client, waiter, cfg, etcdUpgrade, renewCerts, kustomizeDir); err != nil {
|
||||
if err := upgrade.PerformStaticPodUpgrade(client, waiter, cfg, etcdUpgrade, renewCerts, kustomizeDir, patchesDir); err != nil {
|
||||
return errors.Wrap(err, "couldn't complete the static pod upgrade")
|
||||
}
|
||||
|
||||
|
@ -34,4 +34,5 @@ type Data interface {
|
||||
Client() clientset.Interface
|
||||
IgnorePreflightErrors() sets.String
|
||||
KustomizeDir() string
|
||||
PatchesDir() string
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ type applyFlags struct {
|
||||
renewCerts bool
|
||||
imagePullTimeout time.Duration
|
||||
kustomizeDir string
|
||||
patchesDir string
|
||||
}
|
||||
|
||||
// sessionIsInteractive returns true if the session is of an interactive type (the default, can be opted out of with -y, -f or --dry-run)
|
||||
@ -94,6 +95,7 @@ func NewCmdApply(apf *applyPlanFlags) *cobra.Command {
|
||||
// TODO: The flag was deprecated in 1.19; remove the flag following a GA deprecation policy of 12 months or 2 releases (whichever is longer)
|
||||
cmd.Flags().MarkDeprecated("image-pull-timeout", "This flag is deprecated and will be removed in a future version.")
|
||||
options.AddKustomizePodsFlag(cmd.Flags(), &flags.kustomizeDir)
|
||||
options.AddPatchesFlag(cmd.Flags(), &flags.patchesDir)
|
||||
|
||||
return cmd
|
||||
}
|
||||
@ -220,8 +222,8 @@ func PerformControlPlaneUpgrade(flags *applyFlags, client clientset.Interface, w
|
||||
fmt.Printf("[upgrade/apply] Upgrading your Static Pod-hosted control plane to version %q...\n", internalcfg.KubernetesVersion)
|
||||
|
||||
if flags.dryRun {
|
||||
return upgrade.DryRunStaticPodUpgrade(flags.kustomizeDir, internalcfg)
|
||||
return upgrade.DryRunStaticPodUpgrade(flags.kustomizeDir, flags.patchesDir, internalcfg)
|
||||
}
|
||||
|
||||
return upgrade.PerformStaticPodUpgrade(client, waiter, internalcfg, flags.etcdUpgrade, flags.renewCerts, flags.kustomizeDir)
|
||||
return upgrade.PerformStaticPodUpgrade(client, waiter, internalcfg, flags.etcdUpgrade, flags.renewCerts, flags.kustomizeDir, flags.patchesDir)
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ type nodeOptions struct {
|
||||
renewCerts bool
|
||||
dryRun bool
|
||||
kustomizeDir string
|
||||
patchesDir string
|
||||
ignorePreflightErrors []string
|
||||
}
|
||||
|
||||
@ -61,6 +62,7 @@ type nodeData struct {
|
||||
isControlPlaneNode bool
|
||||
client clientset.Interface
|
||||
kustomizeDir string
|
||||
patchesDir string
|
||||
ignorePreflightErrors sets.String
|
||||
}
|
||||
|
||||
@ -82,6 +84,7 @@ func NewCmdNode() *cobra.Command {
|
||||
// flags could be eventually inherited by the sub-commands automatically generated for phases
|
||||
addUpgradeNodeFlags(cmd.Flags(), nodeOptions)
|
||||
options.AddKustomizePodsFlag(cmd.Flags(), &nodeOptions.kustomizeDir)
|
||||
options.AddPatchesFlag(cmd.Flags(), &nodeOptions.patchesDir)
|
||||
|
||||
// initialize the workflow runner with the list of phases
|
||||
nodeRunner.AppendPhase(phases.NewPreflightPhase())
|
||||
@ -162,6 +165,7 @@ func newNodeData(cmd *cobra.Command, args []string, options *nodeOptions) (*node
|
||||
client: client,
|
||||
isControlPlaneNode: isControlPlaneNode,
|
||||
kustomizeDir: options.kustomizeDir,
|
||||
patchesDir: options.patchesDir,
|
||||
ignorePreflightErrors: ignorePreflightErrorsSet,
|
||||
}, nil
|
||||
}
|
||||
@ -206,6 +210,11 @@ func (d *nodeData) KustomizeDir() string {
|
||||
return d.kustomizeDir
|
||||
}
|
||||
|
||||
// PatchesDir returns the folder where patches for components are stored
|
||||
func (d *nodeData) PatchesDir() string {
|
||||
return d.patchesDir
|
||||
}
|
||||
|
||||
// IgnorePreflightErrors returns the list of preflight errors to ignore.
|
||||
func (d *nodeData) IgnorePreflightErrors() sets.String {
|
||||
return d.ignorePreflightErrors
|
||||
|
@ -37,9 +37,9 @@ import (
|
||||
)
|
||||
|
||||
// CreateInitStaticPodManifestFiles will write all static pod manifest files needed to bring up the control plane.
|
||||
func CreateInitStaticPodManifestFiles(manifestDir, kustomizeDir string, cfg *kubeadmapi.InitConfiguration) error {
|
||||
func CreateInitStaticPodManifestFiles(manifestDir, kustomizeDir, patchesDir string, cfg *kubeadmapi.InitConfiguration) error {
|
||||
klog.V(1).Infoln("[control-plane] creating static Pod files")
|
||||
return CreateStaticPodFiles(manifestDir, kustomizeDir, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, kubeadmconstants.KubeAPIServer, kubeadmconstants.KubeControllerManager, kubeadmconstants.KubeScheduler)
|
||||
return CreateStaticPodFiles(manifestDir, kustomizeDir, patchesDir, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, kubeadmconstants.KubeAPIServer, kubeadmconstants.KubeControllerManager, kubeadmconstants.KubeScheduler)
|
||||
}
|
||||
|
||||
// GetStaticPodSpecs returns all staticPodSpecs actualized to the context of the current configuration
|
||||
@ -90,7 +90,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmap
|
||||
}
|
||||
|
||||
// CreateStaticPodFiles creates all the requested static pod files.
|
||||
func CreateStaticPodFiles(manifestDir, kustomizeDir string, cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmapi.APIEndpoint, componentNames ...string) error {
|
||||
func CreateStaticPodFiles(manifestDir, kustomizeDir, patchesDir string, cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmapi.APIEndpoint, componentNames ...string) error {
|
||||
// gets the StaticPodSpecs, actualized for the current ClusterConfiguration
|
||||
klog.V(1).Infoln("[control-plane] getting StaticPodSpecs")
|
||||
specs := GetStaticPodSpecs(cfg, endpoint)
|
||||
|
@ -125,7 +125,7 @@ func TestCreateStaticPodFilesAndWrappers(t *testing.T) {
|
||||
|
||||
// Execute createStaticPodFunction
|
||||
manifestPath := filepath.Join(tmpdir, kubeadmconstants.ManifestsSubDirName)
|
||||
err := CreateStaticPodFiles(manifestPath, "", cfg, &kubeadmapi.APIEndpoint{}, test.components...)
|
||||
err := CreateStaticPodFiles(manifestPath, "", "", cfg, &kubeadmapi.APIEndpoint{}, test.components...)
|
||||
if err != nil {
|
||||
t.Errorf("Error executing createStaticPodFunction: %v", err)
|
||||
return
|
||||
@ -174,7 +174,7 @@ func TestCreateStaticPodFilesKustomize(t *testing.T) {
|
||||
|
||||
// Execute createStaticPodFunction with kustomizations
|
||||
manifestPath := filepath.Join(tmpdir, kubeadmconstants.ManifestsSubDirName)
|
||||
err = CreateStaticPodFiles(manifestPath, kustomizePath, cfg, &kubeadmapi.APIEndpoint{}, kubeadmconstants.KubeAPIServer)
|
||||
err = CreateStaticPodFiles(manifestPath, kustomizePath, "", cfg, &kubeadmapi.APIEndpoint{}, kubeadmconstants.KubeAPIServer)
|
||||
if err != nil {
|
||||
t.Errorf("Error executing createStaticPodFunction: %v", err)
|
||||
return
|
||||
|
@ -48,7 +48,7 @@ const (
|
||||
// CreateLocalEtcdStaticPodManifestFile will write local etcd static pod manifest file.
|
||||
// This function is used by init - when the etcd cluster is empty - or by kubeadm
|
||||
// upgrade - when the etcd cluster is already up and running (and the --initial-cluster flag have no impact)
|
||||
func CreateLocalEtcdStaticPodManifestFile(manifestDir, kustomizeDir string, nodeName string, cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmapi.APIEndpoint) error {
|
||||
func CreateLocalEtcdStaticPodManifestFile(manifestDir, kustomizeDir, patchesDir string, nodeName string, cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmapi.APIEndpoint) error {
|
||||
if cfg.Etcd.External != nil {
|
||||
return errors.New("etcd static pod manifest cannot be generated for cluster using external etcd")
|
||||
}
|
||||
@ -141,7 +141,7 @@ func RemoveStackedEtcdMemberFromCluster(client clientset.Interface, cfg *kubeadm
|
||||
// CreateStackedEtcdStaticPodManifestFile will write local etcd static pod manifest file
|
||||
// for an additional etcd member that is joining an existing local/stacked etcd cluster.
|
||||
// Other members of the etcd cluster will be notified of the joining node in beforehand as well.
|
||||
func CreateStackedEtcdStaticPodManifestFile(client clientset.Interface, manifestDir, kustomizeDir string, nodeName string, cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmapi.APIEndpoint) error {
|
||||
func CreateStackedEtcdStaticPodManifestFile(client clientset.Interface, manifestDir, kustomizeDir, patchesDir string, nodeName string, cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmapi.APIEndpoint) error {
|
||||
// creates an etcd client that connects to all the local/stacked etcd members
|
||||
klog.V(1).Info("creating etcd client that connects to etcd pods")
|
||||
etcdClient, err := etcdutil.NewFromCluster(client, cfg.CertificatesDir)
|
||||
|
@ -96,7 +96,7 @@ func TestCreateLocalEtcdStaticPodManifestFile(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
// Execute createStaticPodFunction
|
||||
manifestPath := filepath.Join(tmpdir, kubeadmconstants.ManifestsSubDirName)
|
||||
err := CreateLocalEtcdStaticPodManifestFile(manifestPath, "", "", test.cfg, &kubeadmapi.APIEndpoint{})
|
||||
err := CreateLocalEtcdStaticPodManifestFile(manifestPath, "", "", "", test.cfg, &kubeadmapi.APIEndpoint{})
|
||||
|
||||
if !test.expectedError {
|
||||
if err != nil {
|
||||
@ -149,7 +149,7 @@ func TestCreateLocalEtcdStaticPodManifestFileKustomize(t *testing.T) {
|
||||
|
||||
// Execute createStaticPodFunction with kustomizations
|
||||
manifestPath := filepath.Join(tmpdir, kubeadmconstants.ManifestsSubDirName)
|
||||
err = CreateLocalEtcdStaticPodManifestFile(manifestPath, kustomizePath, "", cfg, &kubeadmapi.APIEndpoint{})
|
||||
err = CreateLocalEtcdStaticPodManifestFile(manifestPath, kustomizePath, "", "", cfg, &kubeadmapi.APIEndpoint{})
|
||||
if err != nil {
|
||||
t.Errorf("Error executing createStaticPodFunction: %v", err)
|
||||
return
|
||||
|
@ -55,6 +55,8 @@ type StaticPodPathManager interface {
|
||||
KubernetesDir() string
|
||||
// KustomizeDir should point to the folder where kustomize patches for static pod manifest are stored
|
||||
KustomizeDir() string
|
||||
// PatchesDir should point to the folder where patches for components are stored
|
||||
PatchesDir() string
|
||||
// RealManifestPath gets the file path for the component in the "real" static pod manifest directory used by the kubelet
|
||||
RealManifestPath(component string) string
|
||||
// RealManifestDir should point to the static pod manifest directory used by the kubelet
|
||||
@ -77,6 +79,7 @@ type StaticPodPathManager interface {
|
||||
type KubeStaticPodPathManager struct {
|
||||
kubernetesDir string
|
||||
kustomizeDir string
|
||||
patchesDir string
|
||||
realManifestDir string
|
||||
tempManifestDir string
|
||||
backupManifestDir string
|
||||
@ -87,10 +90,11 @@ type KubeStaticPodPathManager struct {
|
||||
}
|
||||
|
||||
// NewKubeStaticPodPathManager creates a new instance of KubeStaticPodPathManager
|
||||
func NewKubeStaticPodPathManager(kubernetesDir, kustomizeDir, tempDir, backupDir, backupEtcdDir string, keepManifestDir, keepEtcdDir bool) StaticPodPathManager {
|
||||
func NewKubeStaticPodPathManager(kubernetesDir, kustomizeDir, patchesDir, tempDir, backupDir, backupEtcdDir string, keepManifestDir, keepEtcdDir bool) StaticPodPathManager {
|
||||
return &KubeStaticPodPathManager{
|
||||
kubernetesDir: kubernetesDir,
|
||||
kustomizeDir: kustomizeDir,
|
||||
patchesDir: patchesDir,
|
||||
realManifestDir: filepath.Join(kubernetesDir, constants.ManifestsSubDirName),
|
||||
tempManifestDir: tempDir,
|
||||
backupManifestDir: backupDir,
|
||||
@ -101,7 +105,7 @@ func NewKubeStaticPodPathManager(kubernetesDir, kustomizeDir, tempDir, backupDir
|
||||
}
|
||||
|
||||
// NewKubeStaticPodPathManagerUsingTempDirs creates a new instance of KubeStaticPodPathManager with temporary directories backing it
|
||||
func NewKubeStaticPodPathManagerUsingTempDirs(kubernetesDir, kustomizeDir string, saveManifestsDir, saveEtcdDir bool) (StaticPodPathManager, error) {
|
||||
func NewKubeStaticPodPathManagerUsingTempDirs(kubernetesDir, kustomizeDir, patchesDir string, saveManifestsDir, saveEtcdDir bool) (StaticPodPathManager, error) {
|
||||
|
||||
upgradedManifestsDir, err := constants.CreateTempDirForKubeadm(kubernetesDir, "kubeadm-upgraded-manifests")
|
||||
if err != nil {
|
||||
@ -116,7 +120,7 @@ func NewKubeStaticPodPathManagerUsingTempDirs(kubernetesDir, kustomizeDir string
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewKubeStaticPodPathManager(kubernetesDir, kustomizeDir, upgradedManifestsDir, backupManifestsDir, backupEtcdDir, saveManifestsDir, saveEtcdDir), nil
|
||||
return NewKubeStaticPodPathManager(kubernetesDir, kustomizeDir, patchesDir, upgradedManifestsDir, backupManifestsDir, backupEtcdDir, saveManifestsDir, saveEtcdDir), nil
|
||||
}
|
||||
|
||||
// MoveFile should move a file from oldPath to newPath
|
||||
@ -134,6 +138,11 @@ func (spm *KubeStaticPodPathManager) KustomizeDir() string {
|
||||
return spm.kustomizeDir
|
||||
}
|
||||
|
||||
// PatchesDir should point to the folder where patches for components are stored
|
||||
func (spm *KubeStaticPodPathManager) PatchesDir() string {
|
||||
return spm.patchesDir
|
||||
}
|
||||
|
||||
// RealManifestPath gets the file path for the component in the "real" static pod manifest directory used by the kubelet
|
||||
func (spm *KubeStaticPodPathManager) RealManifestPath(component string) string {
|
||||
return constants.GetStaticPodFilepath(component, spm.realManifestDir)
|
||||
@ -323,7 +332,7 @@ func performEtcdStaticPodUpgrade(certsRenewMgr *renewal.Manager, client clientse
|
||||
|
||||
// Write the updated etcd static Pod manifest into the temporary directory, at this point no etcd change
|
||||
// has occurred in any aspects.
|
||||
if err := etcdphase.CreateLocalEtcdStaticPodManifestFile(pathMgr.TempManifestDir(), pathMgr.KustomizeDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
|
||||
if err := etcdphase.CreateLocalEtcdStaticPodManifestFile(pathMgr.TempManifestDir(), pathMgr.KustomizeDir(), pathMgr.PatchesDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
|
||||
return true, errors.Wrap(err, "error creating local etcd static pod manifest file")
|
||||
}
|
||||
|
||||
@ -469,7 +478,7 @@ func StaticPodControlPlane(client clientset.Interface, waiter apiclient.Waiter,
|
||||
|
||||
// Write the updated static Pod manifests into the temporary directory
|
||||
fmt.Printf("[upgrade/staticpods] Writing new Static Pod manifests to %q\n", pathMgr.TempManifestDir())
|
||||
err = controlplane.CreateInitStaticPodManifestFiles(pathMgr.TempManifestDir(), pathMgr.KustomizeDir(), cfg)
|
||||
err = controlplane.CreateInitStaticPodManifestFiles(pathMgr.TempManifestDir(), pathMgr.KustomizeDir(), pathMgr.PatchesDir(), cfg)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating init static pod manifest files")
|
||||
}
|
||||
@ -596,14 +605,14 @@ func renewCertsByComponent(cfg *kubeadmapi.InitConfiguration, component string,
|
||||
}
|
||||
|
||||
// GetPathManagerForUpgrade returns a path manager properly configured for the given InitConfiguration.
|
||||
func GetPathManagerForUpgrade(kubernetesDir, kustomizeDir string, internalcfg *kubeadmapi.InitConfiguration, etcdUpgrade bool) (StaticPodPathManager, error) {
|
||||
func GetPathManagerForUpgrade(kubernetesDir, kustomizeDir, patchesDir string, internalcfg *kubeadmapi.InitConfiguration, etcdUpgrade bool) (StaticPodPathManager, error) {
|
||||
isExternalEtcd := internalcfg.Etcd.External != nil
|
||||
return NewKubeStaticPodPathManagerUsingTempDirs(kubernetesDir, kustomizeDir, true, etcdUpgrade && !isExternalEtcd)
|
||||
return NewKubeStaticPodPathManagerUsingTempDirs(kubernetesDir, kustomizeDir, patchesDir, true, etcdUpgrade && !isExternalEtcd)
|
||||
}
|
||||
|
||||
// PerformStaticPodUpgrade performs the upgrade of the control plane components for a static pod hosted cluster
|
||||
func PerformStaticPodUpgrade(client clientset.Interface, waiter apiclient.Waiter, internalcfg *kubeadmapi.InitConfiguration, etcdUpgrade, renewCerts bool, kustomizeDir string) error {
|
||||
pathManager, err := GetPathManagerForUpgrade(constants.KubernetesDir, kustomizeDir, internalcfg, etcdUpgrade)
|
||||
func PerformStaticPodUpgrade(client clientset.Interface, waiter apiclient.Waiter, internalcfg *kubeadmapi.InitConfiguration, etcdUpgrade, renewCerts bool, kustomizeDir, patchesDir string) error {
|
||||
pathManager, err := GetPathManagerForUpgrade(constants.KubernetesDir, kustomizeDir, patchesDir, internalcfg, etcdUpgrade)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -613,14 +622,14 @@ func PerformStaticPodUpgrade(client clientset.Interface, waiter apiclient.Waiter
|
||||
}
|
||||
|
||||
// DryRunStaticPodUpgrade fakes an upgrade of the control plane
|
||||
func DryRunStaticPodUpgrade(kustomizeDir string, internalcfg *kubeadmapi.InitConfiguration) error {
|
||||
func DryRunStaticPodUpgrade(kustomizeDir, patchesDir string, internalcfg *kubeadmapi.InitConfiguration) error {
|
||||
|
||||
dryRunManifestDir, err := constants.CreateTempDirForKubeadm("", "kubeadm-upgrade-dryrun")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(dryRunManifestDir)
|
||||
if err := controlplane.CreateInitStaticPodManifestFiles(dryRunManifestDir, kustomizeDir, internalcfg); err != nil {
|
||||
if err := controlplane.CreateInitStaticPodManifestFiles(dryRunManifestDir, kustomizeDir, patchesDir, internalcfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -144,6 +144,7 @@ func (w *fakeWaiter) WaitForKubeletAndFunc(f func() error) error {
|
||||
type fakeStaticPodPathManager struct {
|
||||
kubernetesDir string
|
||||
kustomizeDir string
|
||||
patchesDir string
|
||||
realManifestDir string
|
||||
tempManifestDir string
|
||||
backupManifestDir string
|
||||
@ -199,6 +200,10 @@ func (spm *fakeStaticPodPathManager) KustomizeDir() string {
|
||||
return spm.kustomizeDir
|
||||
}
|
||||
|
||||
func (spm *fakeStaticPodPathManager) PatchesDir() string {
|
||||
return spm.patchesDir
|
||||
}
|
||||
|
||||
func (spm *fakeStaticPodPathManager) RealManifestPath(component string) string {
|
||||
return constants.GetStaticPodFilepath(component, spm.realManifestDir)
|
||||
}
|
||||
@ -488,11 +493,11 @@ func TestStaticPodControlPlane(t *testing.T) {
|
||||
}
|
||||
|
||||
// Initialize the directory with v1.7 manifests; should then be upgraded to v1.8 using the method
|
||||
err = controlplanephase.CreateInitStaticPodManifestFiles(pathMgr.RealManifestDir(), pathMgr.KustomizeDir(), oldcfg)
|
||||
err = controlplanephase.CreateInitStaticPodManifestFiles(pathMgr.RealManifestDir(), pathMgr.KustomizeDir(), pathMgr.PatchesDir(), oldcfg)
|
||||
if err != nil {
|
||||
t.Fatalf("couldn't run CreateInitStaticPodManifestFiles: %v", err)
|
||||
}
|
||||
err = etcdphase.CreateLocalEtcdStaticPodManifestFile(pathMgr.RealManifestDir(), pathMgr.KustomizeDir(), oldcfg.NodeRegistration.Name, &oldcfg.ClusterConfiguration, &oldcfg.LocalAPIEndpoint)
|
||||
err = etcdphase.CreateLocalEtcdStaticPodManifestFile(pathMgr.RealManifestDir(), pathMgr.KustomizeDir(), pathMgr.PatchesDir(), oldcfg.NodeRegistration.Name, &oldcfg.ClusterConfiguration, &oldcfg.LocalAPIEndpoint)
|
||||
if err != nil {
|
||||
t.Fatalf("couldn't run CreateLocalEtcdStaticPodManifestFile: %v", err)
|
||||
}
|
||||
@ -628,7 +633,7 @@ func TestCleanupDirs(t *testing.T) {
|
||||
backupEtcdDir, cleanup := getTempDir(t, "backupEtcdDir")
|
||||
defer cleanup()
|
||||
|
||||
mgr := NewKubeStaticPodPathManager(realKubernetesDir, "", tempManifestDir, backupManifestDir, backupEtcdDir, test.keepManifest, test.keepEtcd)
|
||||
mgr := NewKubeStaticPodPathManager(realKubernetesDir, "", "", tempManifestDir, backupManifestDir, backupEtcdDir, test.keepManifest, test.keepEtcd)
|
||||
err := mgr.CleanupDirs()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error cleaning up: %v", err)
|
||||
@ -943,7 +948,7 @@ func TestGetPathManagerForUpgrade(t *testing.T) {
|
||||
os.RemoveAll(tmpdir)
|
||||
}()
|
||||
|
||||
pathmgr, err := GetPathManagerForUpgrade(tmpdir, "", test.cfg, test.etcdUpgrade)
|
||||
pathmgr, err := GetPathManagerForUpgrade(tmpdir, "", "", test.cfg, test.etcdUpgrade)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error creating path manager: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user