Unverified Commit 81fa823a authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #54133 from shun-miyoshi-com/add_output_option

Automatic merge from submit-queue (batch tested with PRs 55594, 47849, 54692, 55478, 54133). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. add kubeadm alpha phase kubeconfig option(--output) **What this PR does / why we need it**: This PR will add --output option to `kubeadm alpha phase kubeconfig [command]` This option can change output directory of kubeconfig. Prev: kubeadm alpha phase kubeconfig admin we can get admin.conf in /etc/kubernetes/ . This PR: kubeadm alpha phase kubeconfig admin --output /root we can get admin.conf in /root/ . Of course, --output is optional.(default directory is /etc/kubernetes) Note) I have no confidence about my test code. Thank you. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note ```
parents 52e71291 88327631
...@@ -124,6 +124,7 @@ func getKubeConfigSubCommands(out io.Writer, outDir, defaultKubernetesVersion st ...@@ -124,6 +124,7 @@ func getKubeConfigSubCommands(out io.Writer, outDir, defaultKubernetesVersion st
cmd.Flags().StringVar(&cfg.CertificatesDir, "cert-dir", cfg.CertificatesDir, "The path where certificates are stored.") cmd.Flags().StringVar(&cfg.CertificatesDir, "cert-dir", cfg.CertificatesDir, "The path where certificates are stored.")
cmd.Flags().StringVar(&cfg.API.AdvertiseAddress, "apiserver-advertise-address", cfg.API.AdvertiseAddress, "The IP address or DNS name the API Server is accessible on.") cmd.Flags().StringVar(&cfg.API.AdvertiseAddress, "apiserver-advertise-address", cfg.API.AdvertiseAddress, "The IP address or DNS name the API Server is accessible on.")
cmd.Flags().Int32Var(&cfg.API.BindPort, "apiserver-bind-port", cfg.API.BindPort, "The port the API Server is accessible on.") cmd.Flags().Int32Var(&cfg.API.BindPort, "apiserver-bind-port", cfg.API.BindPort, "The port the API Server is accessible on.")
cmd.Flags().StringVar(&outDir, "kubeconfig-dir", outDir, "The path where to save and store the kubeconfig file.")
if properties.use == "all" || properties.use == "kubelet" { if properties.use == "all" || properties.use == "kubelet" {
cmd.Flags().StringVar(&cfg.NodeName, "node-name", cfg.NodeName, `The node name that the kubelet client cert should use.`) cmd.Flags().StringVar(&cfg.NodeName, "node-name", cfg.NodeName, `The node name that the kubelet client cert should use.`)
} }
......
...@@ -44,6 +44,7 @@ func TestKubeConfigCSubCommandsHasFlags(t *testing.T) { ...@@ -44,6 +44,7 @@ func TestKubeConfigCSubCommandsHasFlags(t *testing.T) {
"cert-dir", "cert-dir",
"apiserver-advertise-address", "apiserver-advertise-address",
"apiserver-bind-port", "apiserver-bind-port",
"kubeconfig-dir",
} }
var tests = []struct { var tests = []struct {
...@@ -167,6 +168,8 @@ func TestKubeConfigSubCommandsThatCreateFilesWithFlags(t *testing.T) { ...@@ -167,6 +168,8 @@ func TestKubeConfigSubCommandsThatCreateFilesWithFlags(t *testing.T) {
// Adds a pki folder with a ca certs to the temp folder // Adds a pki folder with a ca certs to the temp folder
pkidir := testutil.SetupPkiDirWithCertificateAuthorithy(t, tmpdir) pkidir := testutil.SetupPkiDirWithCertificateAuthorithy(t, tmpdir)
outputdir := tmpdir
// Retrives ca cert for assertions // Retrives ca cert for assertions
caCert, _, err := pkiutil.TryLoadCertAndKeyFromDisk(pkidir, kubeadmconstants.CACertAndKeyBaseName) caCert, _, err := pkiutil.TryLoadCertAndKeyFromDisk(pkidir, kubeadmconstants.CACertAndKeyBaseName)
if err != nil { if err != nil {
...@@ -178,7 +181,9 @@ func TestKubeConfigSubCommandsThatCreateFilesWithFlags(t *testing.T) { ...@@ -178,7 +181,9 @@ func TestKubeConfigSubCommandsThatCreateFilesWithFlags(t *testing.T) {
// Execute the subcommand // Execute the subcommand
certDirFlag := fmt.Sprintf("--cert-dir=%s", pkidir) certDirFlag := fmt.Sprintf("--cert-dir=%s", pkidir)
outputDirFlag := fmt.Sprintf("--kubeconfig-dir=%s", outputdir)
allFlags := append(commonFlags, certDirFlag) allFlags := append(commonFlags, certDirFlag)
allFlags = append(allFlags, outputDirFlag)
allFlags = append(allFlags, test.additionalFlags...) allFlags = append(allFlags, test.additionalFlags...)
cmdtestutil.RunSubCommand(t, subCmds, test.command, allFlags...) cmdtestutil.RunSubCommand(t, subCmds, test.command, allFlags...)
...@@ -320,6 +325,8 @@ func TestKubeConfigSubCommandsThatWritesToOut(t *testing.T) { ...@@ -320,6 +325,8 @@ func TestKubeConfigSubCommandsThatWritesToOut(t *testing.T) {
// Adds a pki folder with a ca cert to the temp folder // Adds a pki folder with a ca cert to the temp folder
pkidir := testutil.SetupPkiDirWithCertificateAuthorithy(t, tmpdir) pkidir := testutil.SetupPkiDirWithCertificateAuthorithy(t, tmpdir)
outputdir := tmpdir
// Retrives ca cert for assertions // Retrives ca cert for assertions
caCert, _, err := pkiutil.TryLoadCertAndKeyFromDisk(pkidir, kubeadmconstants.CACertAndKeyBaseName) caCert, _, err := pkiutil.TryLoadCertAndKeyFromDisk(pkidir, kubeadmconstants.CACertAndKeyBaseName)
if err != nil { if err != nil {
...@@ -331,6 +338,7 @@ func TestKubeConfigSubCommandsThatWritesToOut(t *testing.T) { ...@@ -331,6 +338,7 @@ func TestKubeConfigSubCommandsThatWritesToOut(t *testing.T) {
"--apiserver-bind-port=1234", "--apiserver-bind-port=1234",
"--client-name=myUser", "--client-name=myUser",
fmt.Sprintf("--cert-dir=%s", pkidir), fmt.Sprintf("--cert-dir=%s", pkidir),
fmt.Sprintf("--kubeconfig-dir=%s", outputdir),
} }
var tests = []struct { var tests = []struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment