mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
kubeadm-init: allow overriding the dry-run temp directory
Allow overriding the dry-run temporary directory with an env. variable (KUBEADM_INIT_DRYRUN_DIR). Use the same variable in test/cmd/init_test.go. This allows running integration tests as non-root.
This commit is contained in:
parent
04933f3a94
commit
a18502615e
@ -357,7 +357,10 @@ 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 = kubeadmconstants.CreateTempDirForKubeadm("", "kubeadm-init-dryrun"); err != nil {
|
||||
// the KUBEADM_INIT_DRYRUN_DIR environment variable allows overriding the dry-run temporary
|
||||
// directory from the command line. This makes it possible to run "kubeadm init" integration
|
||||
// tests without root.
|
||||
if dryRunDir, err = kubeadmconstants.CreateTempDirForKubeadm(os.Getenv("KUBEADM_INIT_DRYRUN_DIR"), "kubeadm-init-dryrun"); err != nil {
|
||||
return nil, errors.Wrap(err, "couldn't create a temporary directory")
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
||||
package kubeadm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -30,6 +32,10 @@ import (
|
||||
)
|
||||
|
||||
func runKubeadmInit(args ...string) (string, string, int, error) {
|
||||
const dryRunDir = "KUBEADM_INIT_DRYRUN_DIR"
|
||||
if err := os.Setenv(dryRunDir, os.TempDir()); err != nil {
|
||||
panic(fmt.Sprintf("could not set the %s environment variable", dryRunDir))
|
||||
}
|
||||
kubeadmPath := getKubeadmPath()
|
||||
kubeadmArgs := []string{"init", "--dry-run", "--ignore-preflight-errors=all"}
|
||||
kubeadmArgs = append(kubeadmArgs, args...)
|
||||
|
Loading…
Reference in New Issue
Block a user