Skip to content

Commit 144778d

Browse files
committed
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.
1 parent 5506049 commit 144778d

File tree

21 files changed

+89
-33
lines changed

21 files changed

+89
-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/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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func getControlPlanePreparePhaseFlags(name string) []string {
7979
options.TokenStr,
8080
options.CertificateKey,
8181
options.Kustomize,
82+
options.Patches,
8283
}
8384
case "download-certs":
8485
flags = []string{
@@ -124,6 +125,7 @@ func getControlPlanePreparePhaseFlags(name string) []string {
124125
options.CfgPath,
125126
options.ControlPlane,
126127
options.Kustomize,
128+
options.Patches,
127129
}
128130
default:
129131
flags = []string{}
@@ -190,6 +192,7 @@ func runControlPlanePrepareControlPlaneSubphase(c workflow.RunData) error {
190192
err := controlplane.CreateStaticPodFiles(
191193
kubeadmconstants.GetStaticPodDirectory(),
192194
data.KustomizeDir(),
195+
data.PatchesDir(),
193196
&cfg.ClusterConfiguration,
194197
&cfg.LocalAPIEndpoint,
195198
component,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ type JoinData interface {
3636
IgnorePreflightErrors() sets.String
3737
OutputWriter() io.Writer
3838
KustomizeDir() string
39+
PatchesDir() string
3940
}

0 commit comments

Comments
 (0)