diff --git a/cmd/kubeadm/app/apis/kubeadm/validation/validation.go b/cmd/kubeadm/app/apis/kubeadm/validation/validation.go index cfa5663ce0d..06e8605704e 100644 --- a/cmd/kubeadm/app/apis/kubeadm/validation/validation.go +++ b/cmd/kubeadm/app/apis/kubeadm/validation/validation.go @@ -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 diff --git a/cmd/kubeadm/app/cmd/init.go b/cmd/kubeadm/app/cmd/init.go index 6994c127489..76f2299e0d4 100644 --- a/cmd/kubeadm/app/cmd/init.go +++ b/cmd/kubeadm/app/cmd/init.go @@ -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 { diff --git a/cmd/kubeadm/app/cmd/join.go b/cmd/kubeadm/app/cmd/join.go index bb3dd2893f0..05b1da962c1 100644 --- a/cmd/kubeadm/app/cmd/join.go +++ b/cmd/kubeadm/app/cmd/join.go @@ -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 diff --git a/cmd/kubeadm/app/cmd/phases/init/controlplane.go b/cmd/kubeadm/app/cmd/phases/init/controlplane.go index 69c8642906d..aa35d8b8bca 100644 --- a/cmd/kubeadm/app/cmd/phases/init/controlplane.go +++ b/cmd/kubeadm/app/cmd/phases/init/controlplane.go @@ -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) } } diff --git a/cmd/kubeadm/app/cmd/phases/init/data.go b/cmd/kubeadm/app/cmd/phases/init/data.go index e251f9379d9..90e7d1befd1 100644 --- a/cmd/kubeadm/app/cmd/phases/init/data.go +++ b/cmd/kubeadm/app/cmd/phases/init/data.go @@ -46,4 +46,5 @@ type InitData interface { Client() (clientset.Interface, error) Tokens() []string KustomizeDir() string + PatchesDir() string } diff --git a/cmd/kubeadm/app/cmd/phases/init/data_test.go b/cmd/kubeadm/app/cmd/phases/init/data_test.go index 8b2730c79be..838867839e2 100644 --- a/cmd/kubeadm/app/cmd/phases/init/data_test.go +++ b/cmd/kubeadm/app/cmd/phases/init/data_test.go @@ -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 "" } diff --git a/cmd/kubeadm/app/cmd/phases/init/etcd.go b/cmd/kubeadm/app/cmd/phases/init/etcd.go index ae090b7b9bf..b67a6023da9 100644 --- a/cmd/kubeadm/app/cmd/phases/init/etcd.go +++ b/cmd/kubeadm/app/cmd/phases/init/etcd.go @@ -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 { diff --git a/cmd/kubeadm/app/cmd/phases/join/controlplanejoin.go b/cmd/kubeadm/app/cmd/phases/join/controlplanejoin.go index fbdec4041a5..4b947ebe183 100644 --- a/cmd/kubeadm/app/cmd/phases/join/controlplanejoin.go +++ b/cmd/kubeadm/app/cmd/phases/join/controlplanejoin.go @@ -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") } diff --git a/cmd/kubeadm/app/cmd/phases/join/controlplaneprepare.go b/cmd/kubeadm/app/cmd/phases/join/controlplaneprepare.go index 07f38959790..0c757623d4a 100644 --- a/cmd/kubeadm/app/cmd/phases/join/controlplaneprepare.go +++ b/cmd/kubeadm/app/cmd/phases/join/controlplaneprepare.go @@ -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, diff --git a/cmd/kubeadm/app/cmd/phases/join/data.go b/cmd/kubeadm/app/cmd/phases/join/data.go index 9b833f6ea87..879ce3ce3fd 100644 --- a/cmd/kubeadm/app/cmd/phases/join/data.go +++ b/cmd/kubeadm/app/cmd/phases/join/data.go @@ -36,4 +36,5 @@ type JoinData interface { IgnorePreflightErrors() sets.String OutputWriter() io.Writer KustomizeDir() string + PatchesDir() string } diff --git a/cmd/kubeadm/app/cmd/phases/join/data_test.go b/cmd/kubeadm/app/cmd/phases/join/data_test.go index a5f38b12251..d0f980432e8 100644 --- a/cmd/kubeadm/app/cmd/phases/join/data_test.go +++ b/cmd/kubeadm/app/cmd/phases/join/data_test.go @@ -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 "" } diff --git a/cmd/kubeadm/app/cmd/phases/upgrade/node/controlplane.go b/cmd/kubeadm/app/cmd/phases/upgrade/node/controlplane.go index d7749fb648d..d2628aa3cda 100644 --- a/cmd/kubeadm/app/cmd/phases/upgrade/node/controlplane.go +++ b/cmd/kubeadm/app/cmd/phases/upgrade/node/controlplane.go @@ -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") } diff --git a/cmd/kubeadm/app/cmd/phases/upgrade/node/data.go b/cmd/kubeadm/app/cmd/phases/upgrade/node/data.go index 27878ad4308..91339d9aec2 100644 --- a/cmd/kubeadm/app/cmd/phases/upgrade/node/data.go +++ b/cmd/kubeadm/app/cmd/phases/upgrade/node/data.go @@ -34,4 +34,5 @@ type Data interface { Client() clientset.Interface IgnorePreflightErrors() sets.String KustomizeDir() string + PatchesDir() string } diff --git a/cmd/kubeadm/app/cmd/upgrade/apply.go b/cmd/kubeadm/app/cmd/upgrade/apply.go index 9ca4f5c515e..236a60921de 100644 --- a/cmd/kubeadm/app/cmd/upgrade/apply.go +++ b/cmd/kubeadm/app/cmd/upgrade/apply.go @@ -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) } diff --git a/cmd/kubeadm/app/cmd/upgrade/node.go b/cmd/kubeadm/app/cmd/upgrade/node.go index ee404130ad9..7a63c2b3ee3 100644 --- a/cmd/kubeadm/app/cmd/upgrade/node.go +++ b/cmd/kubeadm/app/cmd/upgrade/node.go @@ -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 diff --git a/cmd/kubeadm/app/phases/controlplane/manifests.go b/cmd/kubeadm/app/phases/controlplane/manifests.go index 55dd08ae450..2af82bf6cb8 100644 --- a/cmd/kubeadm/app/phases/controlplane/manifests.go +++ b/cmd/kubeadm/app/phases/controlplane/manifests.go @@ -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) diff --git a/cmd/kubeadm/app/phases/controlplane/manifests_test.go b/cmd/kubeadm/app/phases/controlplane/manifests_test.go index d7592bec07c..2d7085c5d4d 100644 --- a/cmd/kubeadm/app/phases/controlplane/manifests_test.go +++ b/cmd/kubeadm/app/phases/controlplane/manifests_test.go @@ -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 diff --git a/cmd/kubeadm/app/phases/etcd/local.go b/cmd/kubeadm/app/phases/etcd/local.go index 343a8df2d1e..3c474512157 100644 --- a/cmd/kubeadm/app/phases/etcd/local.go +++ b/cmd/kubeadm/app/phases/etcd/local.go @@ -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) diff --git a/cmd/kubeadm/app/phases/etcd/local_test.go b/cmd/kubeadm/app/phases/etcd/local_test.go index b2c0dd0ccdc..ea0f8549396 100644 --- a/cmd/kubeadm/app/phases/etcd/local_test.go +++ b/cmd/kubeadm/app/phases/etcd/local_test.go @@ -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 diff --git a/cmd/kubeadm/app/phases/upgrade/staticpods.go b/cmd/kubeadm/app/phases/upgrade/staticpods.go index 309272f711d..64d13abb310 100644 --- a/cmd/kubeadm/app/phases/upgrade/staticpods.go +++ b/cmd/kubeadm/app/phases/upgrade/staticpods.go @@ -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 } diff --git a/cmd/kubeadm/app/phases/upgrade/staticpods_test.go b/cmd/kubeadm/app/phases/upgrade/staticpods_test.go index e97c80e9a83..d206672dd71 100644 --- a/cmd/kubeadm/app/phases/upgrade/staticpods_test.go +++ b/cmd/kubeadm/app/phases/upgrade/staticpods_test.go @@ -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) }