Skip to content

Commit d71a092

Browse files
authored
Merge pull request kubernetes#92017 from neolit123/1.19-patches
kubeadm: introduce --experimental-patches and deprecate --experimental-kustomize
2 parents 1b87109 + ceb768c commit d71a092

File tree

30 files changed

+1153
-33
lines changed

30 files changed

+1153
-33
lines changed

cmd/kubeadm/app/apis/kubeadm/validation/validation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ func isAllowedFlag(flagName string) bool {
463463
kubeadmcmdoptions.KubeconfigDir,
464464
kubeadmcmdoptions.UploadCerts,
465465
kubeadmcmdoptions.Kustomize,
466+
kubeadmcmdoptions.Patches,
466467
"print-join-command", "rootfs", "v")
467468
if knownFlags.Has(flagName) {
468469
return true

cmd/kubeadm/app/cmd/init.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type initOptions struct {
9999
uploadCerts bool
100100
skipCertificateKeyPrint bool
101101
kustomizeDir string
102+
patchesDir string
102103
}
103104

104105
// compile-time assert that the local data object satisfies the phases data interface.
@@ -121,6 +122,7 @@ type initData struct {
121122
uploadCerts bool
122123
skipCertificateKeyPrint bool
123124
kustomizeDir string
125+
patchesDir string
124126
}
125127

126128
// NewCmdInit returns "kubeadm init" command.
@@ -277,6 +279,7 @@ func AddInitOtherFlags(flagSet *flag.FlagSet, initOptions *initOptions) {
277279
"Don't print the key used to encrypt the control-plane certificates.",
278280
)
279281
options.AddKustomizePodsFlag(flagSet, &initOptions.kustomizeDir)
282+
options.AddPatchesFlag(flagSet, &initOptions.patchesDir)
280283
}
281284

282285
// 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
413416
uploadCerts: options.uploadCerts,
414417
skipCertificateKeyPrint: options.skipCertificateKeyPrint,
415418
kustomizeDir: options.kustomizeDir,
419+
patchesDir: options.patchesDir,
416420
}, nil
417421
}
418422

@@ -550,6 +554,11 @@ func (d *initData) KustomizeDir() string {
550554
return d.kustomizeDir
551555
}
552556

557+
// PatchesDir returns the folder where patches for components are stored
558+
func (d *initData) PatchesDir() string {
559+
return d.patchesDir
560+
}
561+
553562
func printJoinCommand(out io.Writer, adminKubeConfigPath, token string, i *initData) error {
554563
joinControlPlaneCommand, err := cmdutil.GetJoinControlPlaneCommand(adminKubeConfigPath, token, i.CertificateKey(), i.skipTokenPrint, i.skipCertificateKeyPrint)
555564
if err != nil {

cmd/kubeadm/app/cmd/join.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ type joinOptions struct {
130130
externalcfg *kubeadmapiv1beta2.JoinConfiguration
131131
joinControlPlane *kubeadmapiv1beta2.JoinControlPlane
132132
kustomizeDir string
133+
patchesDir string
133134
}
134135

135136
// compile-time assert that the local data object satisfies the phases data interface.
@@ -145,6 +146,7 @@ type joinData struct {
145146
ignorePreflightErrors sets.String
146147
outputWriter io.Writer
147148
kustomizeDir string
149+
patchesDir string
148150
}
149151

150152
// NewCmdJoin returns "kubeadm join" command.
@@ -286,6 +288,7 @@ func addJoinOtherFlags(flagSet *flag.FlagSet, joinOptions *joinOptions) {
286288
"Create a new control plane instance on this node",
287289
)
288290
options.AddKustomizePodsFlag(flagSet, &joinOptions.kustomizeDir)
291+
options.AddPatchesFlag(flagSet, &joinOptions.patchesDir)
289292
}
290293

291294
// 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
441444
ignorePreflightErrors: ignorePreflightErrorsSet,
442445
outputWriter: out,
443446
kustomizeDir: opt.kustomizeDir,
447+
patchesDir: opt.patchesDir,
444448
}, nil
445449
}
446450

@@ -511,6 +515,11 @@ func (j *joinData) KustomizeDir() string {
511515
return j.kustomizeDir
512516
}
513517

518+
// PatchesDir returns the folder where patches for components are stored
519+
func (j *joinData) PatchesDir() string {
520+
return j.patchesDir
521+
}
522+
514523
// fetchInitConfigurationFromJoinConfiguration retrieves the init configuration from a join configuration, performing the discovery
515524
func fetchInitConfigurationFromJoinConfiguration(cfg *kubeadmapi.JoinConfiguration, tlsBootstrapCfg *clientcmdapi.Config) (*kubeadmapi.InitConfiguration, error) {
516525
// Retrieves the kubeadm configuration

cmd/kubeadm/app/cmd/options/constant.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,7 @@ const (
145145

146146
// Kustomize flag sets the folder where kustomize patches for static pod manifest are stored
147147
Kustomize = "experimental-kustomize"
148+
149+
// Patches flag sets the folder where kubeadm component patches are stored
150+
Patches = "experimental-patches"
148151
)

cmd/kubeadm/app/cmd/options/generic.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package options
1818

1919
import (
20+
"fmt"
2021
"strings"
2122

2223
"github.com/spf13/pflag"
@@ -92,4 +93,17 @@ func AddKubeadmOtherFlags(flagSet *pflag.FlagSet, rootfsPath *string) {
9293
// AddKustomizePodsFlag adds the --kustomize flag to the given flagset
9394
func AddKustomizePodsFlag(fs *pflag.FlagSet, kustomizeDir *string) {
9495
fs.StringVarP(kustomizeDir, Kustomize, "k", *kustomizeDir, "The path where kustomize patches for static pod manifests are stored.")
96+
fs.MarkDeprecated(Kustomize, fmt.Sprintf("This flag is deprecated and will be removed in a future version. Please use %s instead.", Patches))
97+
}
98+
99+
// AddPatchesFlag adds the --patches flag to the given flagset
100+
func AddPatchesFlag(fs *pflag.FlagSet, patchesDir *string) {
101+
fs.StringVar(patchesDir, Patches, *patchesDir, `Path to a directory that contains files named `+
102+
`"target[suffix][+patchtype].extension". For example, `+
103+
`"kube-apiserver0+merge.yaml" or just "etcd.json". `+
104+
`"patchtype" can be one of "strategic", "merge" or "json" and they match the patch formats `+
105+
`supported by kubectl. The default "patchtype" is "strategic". "extension" must be either `+
106+
`"json" or "yaml". "suffix" is an optional string that can be used to determine `+
107+
`which patches are applied first alpha-numerically.`,
108+
)
95109
}

cmd/kubeadm/app/cmd/phases/init/controlplane.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,6 @@ func runControlPlaneSubphase(component string) func(c workflow.RunData) error {
145145
cfg := data.Cfg()
146146

147147
fmt.Printf("[control-plane] Creating static Pod manifest for %q\n", component)
148-
return controlplane.CreateStaticPodFiles(data.ManifestDir(), data.KustomizeDir(), &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, component)
148+
return controlplane.CreateStaticPodFiles(data.ManifestDir(), data.KustomizeDir(), data.PatchesDir(), &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, component)
149149
}
150150
}

cmd/kubeadm/app/cmd/phases/init/data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ type InitData interface {
4646
Client() (clientset.Interface, error)
4747
Tokens() []string
4848
KustomizeDir() string
49+
PatchesDir() string
4950
}

cmd/kubeadm/app/cmd/phases/init/data_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ func (t *testInitData) OutputWriter() io.Writer { return nil }
4949
func (t *testInitData) Client() (clientset.Interface, error) { return nil, nil }
5050
func (t *testInitData) Tokens() []string { return nil }
5151
func (t *testInitData) KustomizeDir() string { return "" }
52+
func (t *testInitData) PatchesDir() string { return "" }

cmd/kubeadm/app/cmd/phases/init/etcd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func getEtcdPhaseFlags() []string {
7070
options.CfgPath,
7171
options.ImageRepository,
7272
options.Kustomize,
73+
options.Patches,
7374
}
7475
return flags
7576
}
@@ -93,7 +94,7 @@ func runEtcdPhaseLocal() func(c workflow.RunData) error {
9394
fmt.Printf("[dryrun] Would ensure that %q directory is present\n", cfg.Etcd.Local.DataDir)
9495
}
9596
fmt.Printf("[etcd] Creating static Pod manifest for local etcd in %q\n", data.ManifestDir())
96-
if err := etcdphase.CreateLocalEtcdStaticPodManifestFile(data.ManifestDir(), data.KustomizeDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
97+
if err := etcdphase.CreateLocalEtcdStaticPodManifestFile(data.ManifestDir(), data.KustomizeDir(), data.PatchesDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
9798
return errors.Wrap(err, "error creating local etcd static pod manifest file")
9899
}
99100
} else {

cmd/kubeadm/app/cmd/phases/join/controlplanejoin.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func getControlPlaneJoinPhaseFlags(name string) []string {
4343
options.NodeName,
4444
}
4545
if name == "etcd" {
46-
flags = append(flags, options.Kustomize)
46+
flags = append(flags, options.Kustomize, options.Patches)
4747
}
4848
if name != "mark-control-plane" {
4949
flags = append(flags, options.APIServerAdvertiseAddress)
@@ -139,8 +139,9 @@ func runEtcdPhase(c workflow.RunData) error {
139139
// From https://coreos.com/etcd/docs/latest/v2/runtime-configuration.html
140140
// "If you add a new member to a 1-node cluster, the cluster cannot make progress before the new member starts
141141
// because it needs two members as majority to agree on the consensus. You will only see this behavior between the time
142-
// etcdctl member add informs the cluster about the new member and the new member successfully establishing a connection to the // existing one."
143-
if err := etcdphase.CreateStackedEtcdStaticPodManifestFile(client, kubeadmconstants.GetStaticPodDirectory(), data.KustomizeDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
142+
// etcdctl member add informs the cluster about the new member and the new member successfully establishing a connection to the
143+
// existing one."
144+
if err := etcdphase.CreateStackedEtcdStaticPodManifestFile(client, kubeadmconstants.GetStaticPodDirectory(), data.KustomizeDir(), data.PatchesDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
144145
return errors.Wrap(err, "error creating local etcd static pod manifest file")
145146
}
146147

0 commit comments

Comments
 (0)