diff --git a/cmd/kubeadm/app/cmd/init.go b/cmd/kubeadm/app/cmd/init.go index b55aa9e87c..5e50cdfbf2 100644 --- a/cmd/kubeadm/app/cmd/init.go +++ b/cmd/kubeadm/app/cmd/init.go @@ -19,7 +19,6 @@ package cmd import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -327,7 +326,7 @@ func newInitData(cmd *cobra.Command, args []string, options *initOptions, out io // if dry running creates a temporary folder for saving kubeadm generated files dryRunDir := "" if options.dryRun { - if dryRunDir, err = ioutil.TempDir("", "kubeadm-init-dryrun"); err != nil { + if dryRunDir, err = kubeadmconstants.CreateTempDirForKubeadm("kubeadm-init-dryrun"); err != nil { return nil, errors.Wrap(err, "couldn't create a temporary directory") } } diff --git a/cmd/kubeadm/app/cmd/upgrade/node.go b/cmd/kubeadm/app/cmd/upgrade/node.go index 3115b00ea6..95af938ec3 100644 --- a/cmd/kubeadm/app/cmd/upgrade/node.go +++ b/cmd/kubeadm/app/cmd/upgrade/node.go @@ -18,7 +18,6 @@ package upgrade import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -162,7 +161,7 @@ func RunUpgradeNodeConfig(flags *nodeUpgradeFlags) error { } // Set up the kubelet directory to use. If dry-running, use a fake directory - kubeletDir, err := getKubeletDir(flags.dryRun) + kubeletDir, err := upgrade.GetKubeletDir(flags.dryRun) if err != nil { return err } @@ -192,18 +191,6 @@ func RunUpgradeNodeConfig(flags *nodeUpgradeFlags) error { return nil } -// getKubeletDir gets the kubelet directory based on whether the user is dry-running this command or not. -func getKubeletDir(dryRun bool) (string, error) { - if dryRun { - dryRunDir, err := ioutil.TempDir("", "kubeadm-init-dryrun") - if err != nil { - return "", errors.Wrap(err, "couldn't create a temporary directory") - } - return dryRunDir, nil - } - return constants.KubeletRunDirectory, nil -} - // printFilesIfDryRunning prints the Static Pod manifests to stdout and informs about the temporary directory to go and lookup func printFilesIfDryRunning(dryRun bool, kubeletDir string) error { if !dryRun { diff --git a/cmd/kubeadm/app/phases/upgrade/postupgrade.go b/cmd/kubeadm/app/phases/upgrade/postupgrade.go index 4ac31dd0a7..cfc62bc751 100644 --- a/cmd/kubeadm/app/phases/upgrade/postupgrade.go +++ b/cmd/kubeadm/app/phases/upgrade/postupgrade.go @@ -18,7 +18,6 @@ package upgrade import ( "fmt" - "io/ioutil" "os" "path/filepath" "time" @@ -185,7 +184,7 @@ func BackupAPIServerCertIfNeeded(cfg *kubeadmapi.InitConfiguration, dryRun bool) } func writeKubeletConfigFiles(client clientset.Interface, cfg *kubeadmapi.InitConfiguration, newK8sVer *version.Version, dryRun bool) error { - kubeletDir, err := getKubeletDir(dryRun) + kubeletDir, err := GetKubeletDir(dryRun) if err != nil { // The error here should never occur in reality, would only be thrown if /tmp doesn't exist on the machine. return err @@ -221,11 +220,10 @@ func writeKubeletConfigFiles(client clientset.Interface, cfg *kubeadmapi.InitCon return errorsutil.NewAggregate(errs) } -// getKubeletDir gets the kubelet directory based on whether the user is dry-running this command or not. -// TODO: Consolidate this with similar funcs? -func getKubeletDir(dryRun bool) (string, error) { +// GetKubeletDir gets the kubelet directory based on whether the user is dry-running this command or not. +func GetKubeletDir(dryRun bool) (string, error) { if dryRun { - return ioutil.TempDir("", "kubeadm-upgrade-dryrun") + return kubeadmconstants.CreateTempDirForKubeadm("kubeadm-upgrade-dryrun") } return kubeadmconstants.KubeletRunDirectory, nil }