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

kubeadm: refactored directory fetch code
k3s-v1.15.3
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 (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"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
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")
}
}

View File

@ -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 {

View File

@ -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
}