Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when old cluster config file exists #7748

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions cmd/eksctl-anywhere/cmd/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,8 @@

validations.CheckDockerAllocatedMemory(ctx, docker)

kubeconfigPath := kubeconfig.FromClusterName(clusterConfig.Name)
if validations.FileExistsAndIsNotEmpty(kubeconfigPath) {
return fmt.Errorf(
"old cluster config file exists under %s, please use a different clusterName to proceed",
clusterConfig.Name,
)
if err := kubeconfig.ValidateKubeconfigPath(clusterConfig.Name); err != nil {
return err

Check warning on line 140 in cmd/eksctl-anywhere/cmd/createcluster.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/createcluster.go#L139-L140

Added lines #L139 - L140 were not covered by tests
}

clusterSpec, err := newClusterSpec(cc.clusterOptions)
Expand Down
6 changes: 3 additions & 3 deletions docs/content/en/docs/troubleshooting/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ Error: loading config file "cluster.yaml": error unmarshaling JSON: while decodi
```
Use `eksctl anywhere create cluster -f cluster.yaml` instead of `eksctl create cluster -f cluster.yaml` to create an EKS Anywhere cluster.

### Error: old cluster config file exists under my-cluster, please use a different clusterName to proceed
### Error: old cluster config file already exists under the "my-cluster" folder, please use a different cluster name or remove the existing "my-cluster" folder to proceed

```
Error: old cluster config file exists under my-cluster, please use a different clusterName to proceed
Error: old cluster config file already exists under the "my-cluster" folder, please use a different cluster name or remove the existing "my-cluster" folder to proceed
```
The `my-cluster` directory already exists in the current directory.
Either use a different cluster name or move the directory.
Either use a different cluster name or remove the existing directory.

### At least one WorkerNodeGroupConfiguration must not have NoExecute and/or NoSchedule taints

Expand Down
5 changes: 3 additions & 2 deletions pkg/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
return nil
}

// ValidateKubeconfigPath validates that the cluster config file of the clusterName under the parentFolders does not exist.
func ValidateKubeconfigPath(clusterName string, parentFolders ...string) error {
kubeconfigPath := FromClusterName(clusterName)
for _, folder := range parentFolders {
Expand All @@ -127,8 +128,8 @@
info, err := os.Stat(kubeconfigPath)
if err == nil && info.Size() > 0 {
return fmt.Errorf(
"old cluster config file exists under %s, please use a different clusterName to proceed",
clusterName,
"old cluster config file already exists under the %q folder, please use a different cluster name or remove the existing %q folder to proceed",
clusterName, clusterName,

Check warning on line 132 in pkg/kubeconfig/kubeconfig.go

View check run for this annotation

Codecov / codecov/patch

pkg/kubeconfig/kubeconfig.go#L131-L132

Added lines #L131 - L132 were not covered by tests
)
}
return nil
Expand Down
6 changes: 6 additions & 0 deletions pkg/kubeconfig/kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,9 @@ func TestResolveAndValidateFilename(t *testing.T) {
assert.Error(t, err)
})
}

func TestValidateKubeconfigPath(t *testing.T) {
t.Run("returns nil when valid", func(t *testing.T) {
assert.NoError(t, kubeconfig.ValidateKubeconfigPath("test-cluster"))
})
}
Loading