Skip to content

Commit d54c516

Browse files
authored
Merge pull request kubernetes#81458 from fabriziopandini/kubeadm-kustomize-ux
kubeadm: kustomize-ux
2 parents 8dea331 + a92e797 commit d54c516

File tree

21 files changed

+109
-55
lines changed

21 files changed

+109
-55
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ func isAllowedFlag(flagName string) bool {
462462
kubeadmcmdoptions.NodeCRISocket,
463463
kubeadmcmdoptions.KubeconfigDir,
464464
kubeadmcmdoptions.UploadCerts,
465+
kubeadmcmdoptions.Kustomize,
465466
"print-join-command", "rootfs", "v")
466467
if knownFlags.Has(flagName) {
467468
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
externalClusterCfg *kubeadmapiv1beta2.ClusterConfiguration
100100
uploadCerts bool
101101
skipCertificateKeyPrint bool
102+
kustomizeDir string
102103
}
103104

104105
// compile-time assert that the local data object satisfies the phases data interface.
@@ -120,6 +121,7 @@ type initData struct {
120121
outputWriter io.Writer
121122
uploadCerts bool
122123
skipCertificateKeyPrint bool
124+
kustomizeDir string
123125
}
124126

125127
// NewCmdInit returns "kubeadm init" command.
@@ -272,6 +274,7 @@ func AddInitOtherFlags(flagSet *flag.FlagSet, initOptions *initOptions) {
272274
&initOptions.skipCertificateKeyPrint, options.SkipCertificateKeyPrint, initOptions.skipCertificateKeyPrint,
273275
"Don't print the key used to encrypt the control-plane certificates.",
274276
)
277+
options.AddKustomizePodsFlag(flagSet, &initOptions.kustomizeDir)
275278
}
276279

277280
// newInitOptions returns a struct ready for being used for creating cmd init flags.
@@ -404,6 +407,7 @@ func newInitData(cmd *cobra.Command, args []string, options *initOptions, out io
404407
outputWriter: out,
405408
uploadCerts: options.uploadCerts,
406409
skipCertificateKeyPrint: options.skipCertificateKeyPrint,
410+
kustomizeDir: options.kustomizeDir,
407411
}, nil
408412
}
409413

@@ -532,6 +536,11 @@ func (d *initData) Tokens() []string {
532536
return tokens
533537
}
534538

539+
// KustomizeDir returns the folder where kustomize patches for static pod manifest are stored
540+
func (d *initData) KustomizeDir() string {
541+
return d.kustomizeDir
542+
}
543+
535544
func printJoinCommand(out io.Writer, adminKubeConfigPath, token string, i *initData) error {
536545
joinControlPlaneCommand, err := cmdutil.GetJoinControlPlaneCommand(adminKubeConfigPath, token, i.CertificateKey(), i.skipTokenPrint, i.skipCertificateKeyPrint)
537546
if err != nil {

cmd/kubeadm/app/cmd/join.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ type joinOptions struct {
128128
controlPlane bool
129129
ignorePreflightErrors []string
130130
externalcfg *kubeadmapiv1beta2.JoinConfiguration
131+
kustomizeDir string
131132
}
132133

133134
// compile-time assert that the local data object satisfies the phases data interface.
@@ -142,6 +143,7 @@ type joinData struct {
142143
clientSet *clientset.Clientset
143144
ignorePreflightErrors sets.String
144145
outputWriter io.Writer
146+
kustomizeDir string
145147
}
146148

147149
// NewCmdJoin returns "kubeadm join" command.
@@ -276,6 +278,7 @@ func addJoinOtherFlags(flagSet *flag.FlagSet, joinOptions *joinOptions) {
276278
&joinOptions.controlPlane, options.ControlPlane, joinOptions.controlPlane,
277279
"Create a new control plane instance on this node",
278280
)
281+
options.AddKustomizePodsFlag(flagSet, &joinOptions.kustomizeDir)
279282
}
280283

281284
// newJoinOptions returns a struct ready for being used for creating cmd join flags.
@@ -405,6 +408,7 @@ func newJoinData(cmd *cobra.Command, args []string, opt *joinOptions, out io.Wri
405408
tlsBootstrapCfg: tlsBootstrapCfg,
406409
ignorePreflightErrors: ignorePreflightErrorsSet,
407410
outputWriter: out,
411+
kustomizeDir: opt.kustomizeDir,
408412
}, nil
409413
}
410414

@@ -470,6 +474,11 @@ func (j *joinData) OutputWriter() io.Writer {
470474
return j.outputWriter
471475
}
472476

477+
// KustomizeDir returns the folder where kustomize patches for static pod manifest are stored
478+
func (j *joinData) KustomizeDir() string {
479+
return j.kustomizeDir
480+
}
481+
473482
// fetchInitConfigurationFromJoinConfiguration retrieves the init configuration from a join configuration, performing the discovery
474483
func fetchInitConfigurationFromJoinConfiguration(cfg *kubeadmapi.JoinConfiguration, tlsBootstrapCfg *clientcmdapi.Config) (*kubeadmapi.InitConfiguration, error) {
475484
// 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
@@ -142,4 +142,7 @@ const (
142142

143143
// EtcdUpgrade flag instruct kubeadm to execute etcd upgrade during upgrades
144144
EtcdUpgrade = "etcd-upgrade"
145+
146+
// Kustomize flag sets the folder where kustomize patches for static pod manifest are stored
147+
Kustomize = "experimental-kustomize"
145148
)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,8 @@ func AddKubeadmOtherFlags(flagSet *pflag.FlagSet, rootfsPath *string) {
8888
"[EXPERIMENTAL] The path to the 'real' host root filesystem.",
8989
)
9090
}
91+
92+
// AddKustomizePodsFlag adds the --kustomize flag to the given flagset
93+
func AddKustomizePodsFlag(fs *pflag.FlagSet, kustomizeDir *string) {
94+
fs.StringVarP(kustomizeDir, Kustomize, "k", *kustomizeDir, "The path where kustomize patches for static pod manifests are stored.")
95+
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func getControlPlanePhaseFlags(name string) []string {
100100
options.CertificatesDir,
101101
options.KubernetesVersion,
102102
options.ImageRepository,
103+
options.Kustomize,
103104
}
104105
if name == "all" || name == kubeadmconstants.KubeAPIServer {
105106
flags = append(flags,
@@ -144,10 +145,6 @@ func runControlPlaneSubphase(component string) func(c workflow.RunData) error {
144145
cfg := data.Cfg()
145146

146147
fmt.Printf("[control-plane] Creating static Pod manifest for %q\n", component)
147-
148-
// TODO: this should be replaced by a value from a flag in subsequent PR. see the POC https://github.com/kubernetes/kubernetes/pull/80580
149-
kustomizeDir := ""
150-
151-
return controlplane.CreateStaticPodFiles(data.ManifestDir(), kustomizeDir, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, component)
148+
return controlplane.CreateStaticPodFiles(data.ManifestDir(), data.KustomizeDir(), &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, component)
152149
}
153150
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ type InitData interface {
4545
OutputWriter() io.Writer
4646
Client() (clientset.Interface, error)
4747
Tokens() []string
48+
KustomizeDir() string
4849
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ func (t *testInitData) ExternalCA() bool { return false }
4848
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 }
51+
func (t *testInitData) KustomizeDir() string { return "" }

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func getEtcdPhaseFlags() []string {
6969
options.CertificatesDir,
7070
options.CfgPath,
7171
options.ImageRepository,
72+
options.Kustomize,
7273
}
7374
return flags
7475
}
@@ -92,11 +93,7 @@ func runEtcdPhaseLocal() func(c workflow.RunData) error {
9293
fmt.Printf("[dryrun] Would ensure that %q directory is present\n", cfg.Etcd.Local.DataDir)
9394
}
9495
fmt.Printf("[etcd] Creating static Pod manifest for local etcd in %q\n", data.ManifestDir())
95-
96-
// TODO: this should be replaced by a value from a flag in subsequent PR. see the POC https://github.com/kubernetes/kubernetes/pull/80580
97-
kustomizeDir := ""
98-
99-
if err := etcdphase.CreateLocalEtcdStaticPodManifestFile(data.ManifestDir(), kustomizeDir, cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
96+
if err := etcdphase.CreateLocalEtcdStaticPodManifestFile(data.ManifestDir(), data.KustomizeDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
10097
return errors.Wrap(err, "error creating local etcd static pod manifest file")
10198
}
10299
} else {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func getControlPlaneJoinPhaseFlags(name string) []string {
4242
options.ControlPlane,
4343
options.NodeName,
4444
}
45+
if name == "etcd" {
46+
flags = append(flags, options.Kustomize)
47+
}
4548
if name != "mark-control-plane" {
4649
flags = append(flags, options.APIServerAdvertiseAddress)
4750
}
@@ -137,7 +140,7 @@ func runEtcdPhase(c workflow.RunData) error {
137140
// "If you add a new member to a 1-node cluster, the cluster cannot make progress before the new member starts
138141
// because it needs two members as majority to agree on the consensus. You will only see this behavior between the time
139142
// etcdctl member add informs the cluster about the new member and the new member successfully establishing a connection to the // existing one."
140-
if err := etcdphase.CreateStackedEtcdStaticPodManifestFile(client, kubeadmconstants.GetStaticPodDirectory(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
143+
if err := etcdphase.CreateStackedEtcdStaticPodManifestFile(client, kubeadmconstants.GetStaticPodDirectory(), data.KustomizeDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
141144
return errors.Wrap(err, "error creating local etcd static pod manifest file")
142145
}
143146

0 commit comments

Comments
 (0)