Skip to content

Commit 61c9c7b

Browse files
authored
Merge pull request #4341 from twz123/empty-join-token-file
More helpful error message for empty/absent token files
2 parents e5c7adf + 3b87fab commit 61c9c7b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/component/worker/utils.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package worker
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"os"
2324
"path"
@@ -75,10 +76,22 @@ func BootstrapKubeletKubeconfig(ctx context.Context, k0sVars *config.CfgVars, wo
7576
if workerOpts.TokenArg != "" {
7677
tokenData = workerOpts.TokenArg
7778
} else {
79+
var problem string
7880
data, err := os.ReadFile(workerOpts.TokenFile)
79-
if err != nil {
81+
if errors.Is(err, os.ErrNotExist) {
82+
problem = "not found"
83+
} else if err != nil {
8084
return fmt.Errorf("failed to read token file: %w", err)
85+
} else if len(data) == 0 {
86+
problem = "is empty"
8187
}
88+
if problem != "" {
89+
return fmt.Errorf("token file %q %s"+
90+
`: obtain a new token via "k0s token create ..." and store it in the file`+
91+
` or reinstall this node via "k0s install --force ..." or "k0sctl apply --force ..."`,
92+
workerOpts.TokenFile, problem)
93+
}
94+
8295
tokenData = string(data)
8396
}
8497

0 commit comments

Comments
 (0)