fix: set default work_dir is "./kubekey". (#2354)

Signed-off-by: joyceliu <joyceliu@yunify.com>
Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
II 2024-08-12 11:26:06 +08:00 committed by GitHub
parent 1aa519d295
commit 647ae222bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 2 deletions

View File

@ -73,7 +73,7 @@ func newCommonOptions() CommonOptions {
klog.ErrorS(err, "get current dir error")
o.WorkDir = "/tmp/kubekey"
} else {
o.WorkDir = wd
o.WorkDir = filepath.Join(wd, "kubekey")
}
return o
}

View File

@ -47,7 +47,7 @@ func (c *kubernetesConnector) Init(ctx context.Context) error {
return nil
}
// set rootDir
c.rootDir = filepath.Join(_const.GetWorkDir(), "kubernetes", c.clusterName)
c.rootDir = filepath.Join(_const.GetWorkDir(), _const.KubernetesDir, c.clusterName)
if _, err := os.Stat(c.rootDir); err != nil && os.IsNotExist(err) {
if err := os.MkdirAll(c.rootDir, os.ModePerm); err != nil {
klog.V(4).ErrorS(err, "Failed to create local dir", "cluster", c.clusterName)

View File

@ -52,6 +52,9 @@ workdir/
| | | | |-- inventory.yaml
|
|-- kubekey/
|
|-- kubernetes/
*/
// workDir is the user-specified working directory. By default, it is the same as the directory where the kubekey command is executed.
@ -117,3 +120,6 @@ const RuntimePipelineVariableDir = "variable"
// "kubekey" is the default directory name under the working directory. It is used to store
// files required when executing the kubekey command (such as: docker, etcd, image packages, etc.).
// These files will be downloaded locally and distributed to remote nodes.
// KubernetesDir represents the remote host directory for each kubernetes connection
const KubernetesDir = "kubernetes"