Skip to content

Conversation

@s3rj1k
Copy link
Contributor

@s3rj1k s3rj1k commented Dec 1, 2025

Adds new flags to improve k0s token management experience for both worker and controller:

--token-env: Allows specifying the join token via an environment variable name instead of passing it via file

Related: #6727

Copy link
Member

@twz123 twz123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mention this somewhere in the docs, too? /cc #5253

return fmt.Errorf("invalid node config: %w", errors.Join(errs...))
}

// Convert --token-env to --token-file
Copy link
Member

@twz123 twz123 Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I think this is a very unintuitive thing to do. By nature, an environment variable is ephemeral and belongs to the current process only. Capturing it in a file is not something I'd want to happen with it. Moreover, this creates a discrepancy between the arguments passed to the install controller/worker command and the arguments passed to controller/worker command, which we have managed to avoid so far. If folks need to persist the token, then they can just use --token-file without surprises.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you fine with keeping temporary bootstrap token inside init system file instead of keeping pointing it to a file?

And no, there are use cases that do not allow just using "--token-file without surprises"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makhov pointed out that there's a straight forward solution which wouldn't require any special-handling at all here: We could simply use k0s install -e K0S_JOIN_TOKEN controller [...] and be done with it. That would store the token somewhere in the init system config, and the behavior would be much more obvious. /cc #6763

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I am working on this RN, ETA PR today

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternative PR #6766

}

func loadKubeconfigFromTokenFile(path string) (*clientcmdapi.Config, error) {
func loadKubeconfigFromToken(path string) (*clientcmdapi.Config, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still reading a token file, so we could keep the old name.

flagset.StringVar(&workerOpts.WorkerProfile, "profile", defaultWorkerProfile, "worker profile to use on the node")
flagset.BoolVar(&workerOpts.CloudProvider, "enable-cloud-provider", false, "Whether or not to enable cloud provider support in kubelet")
flagset.StringVar(&workerOpts.TokenFile, "token-file", "", "Path to the file containing join-token.")
flagset.StringVar(&workerOpts.TokenEnv, "token-env", "", "Environment variable name containing the join-token.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not add an additional flag for this. Instead, I'd simply check for K0S_JOIN_TOKEN if the token isn't provided as an argument or a file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiding flag means, extra document section about secret environ values

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to document that.

@s3rj1k
Copy link
Contributor Author

s3rj1k commented Dec 3, 2025

Turning this to draft, #6766 should supersede this PR

@s3rj1k s3rj1k marked this pull request as draft December 3, 2025 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants