Merge pull request #74719 from vaamarnath/refactor-dir-create-for-dry-runs

kubeadm: refactored directory fetch code
This commit is contained in:
Kubernetes Prow Robot 2019-03-19 20:15:20 -07:00 committed by GitHub
commit c7e56c7ea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 22 deletions

View File

@ -19,7 +19,6 @@ package cmd
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -341,7 +340,7 @@ func newInitData(cmd *cobra.Command, args []string, options *initOptions, out io
// if dry running creates a temporary folder for saving kubeadm generated files // if dry running creates a temporary folder for saving kubeadm generated files
dryRunDir := "" dryRunDir := ""
if options.dryRun { 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") return nil, errors.Wrap(err, "couldn't create a temporary directory")
} }
} }

View File

@ -18,7 +18,6 @@ package upgrade
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "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 // 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 { if err != nil {
return err return err
} }
@ -192,18 +191,6 @@ func RunUpgradeNodeConfig(flags *nodeUpgradeFlags) error {
return nil 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 // 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 { func printFilesIfDryRunning(dryRun bool, kubeletDir string) error {
if !dryRun { if !dryRun {

View File

@ -18,7 +18,6 @@ package upgrade
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"time" "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 { 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 { if err != nil {
// The error here should never occur in reality, would only be thrown if /tmp doesn't exist on the machine. // The error here should never occur in reality, would only be thrown if /tmp doesn't exist on the machine.
return err return err
@ -221,11 +220,10 @@ func writeKubeletConfigFiles(client clientset.Interface, cfg *kubeadmapi.InitCon
return errorsutil.NewAggregate(errs) return errorsutil.NewAggregate(errs)
} }
// getKubeletDir gets the kubelet directory based on whether the user is dry-running this command or not. // 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) {
func getKubeletDir(dryRun bool) (string, error) {
if dryRun { if dryRun {
return ioutil.TempDir("", "kubeadm-upgrade-dryrun") return kubeadmconstants.CreateTempDirForKubeadm("kubeadm-upgrade-dryrun")
} }
return kubeadmconstants.KubeletRunDirectory, nil return kubeadmconstants.KubeletRunDirectory, nil
} }