Skip to content

Commit

Permalink
Merge pull request #4341 from twz123/empty-join-token-file
Browse files Browse the repository at this point in the history
More helpful error message for empty/absent token files
  • Loading branch information
twz123 authored Apr 28, 2024
2 parents e5c7adf + 3b87fab commit 61c9c7b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/component/worker/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package worker

import (
"context"
"errors"
"fmt"
"os"
"path"
Expand Down Expand Up @@ -75,10 +76,22 @@ func BootstrapKubeletKubeconfig(ctx context.Context, k0sVars *config.CfgVars, wo
if workerOpts.TokenArg != "" {
tokenData = workerOpts.TokenArg
} else {
var problem string
data, err := os.ReadFile(workerOpts.TokenFile)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
problem = "not found"
} else if err != nil {
return fmt.Errorf("failed to read token file: %w", err)
} else if len(data) == 0 {
problem = "is empty"
}
if problem != "" {
return fmt.Errorf("token file %q %s"+
`: obtain a new token via "k0s token create ..." and store it in the file`+
` or reinstall this node via "k0s install --force ..." or "k0sctl apply --force ..."`,
workerOpts.TokenFile, problem)
}

tokenData = string(data)
}

Expand Down

0 comments on commit 61c9c7b

Please sign in to comment.