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

[Enhancement] Refactoring: normalize label flags (k3s node & runtime) (#598, @ejose19) #598

Merged
merged 6 commits into from
May 19, 2021

Conversation

ejose19
Copy link
Contributor

@ejose19 ejose19 commented May 10, 2021

What

This PR aims to normalize label flags brought by #378 & #584, both in naming and availability of methods (so both flags can be used in k3d clusters create & k3d node create)

Why

Besides the individual usefulness of having these flags, also being consistent in naming and availability of commands is something users will appreciate

Implications

As labels property (and its cli shorthand -l) is being replaced by --runtime-label to avoid ambiguity (as determined in #584 (comment)), this is a breaking change.

@ejose19 ejose19 changed the title refactor: normalize flags (k3s node & runtime) refactor: normalize label flags (k3s node & runtime) May 10, 2021
@iwilltry42 iwilltry42 added this to the v4.6.0 milestone May 11, 2021
@@ -22,7 +22,12 @@ env:
- envVar: bar=baz,bob
nodeFilters:
- all
labels:
k3sNodeLabels:
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to rather have this under

options:
  k3s:
    nodeLabels: []

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that looks better, wonder if there should be runtime as well under options so only main properties are k3d specific.

Copy link
Member

Choose a reason for hiding this comment

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

Guess that would make sense.. config file is still alpha, so we could do a revamp for the first beta to make things more clean/consistent.

cmd/cluster/clusterCreate.go Show resolved Hide resolved
@iwilltry42
Copy link
Member

Thanks for your efforts here @ejose19 !
This introduces a breaking change, so we need to double check this before releasing, so it doesn't break existing workflows.
This whole propagation of flags from k3s up to k3d feels a bit odd to me.
I wonder if it wouldn't just be easier to add node filters to the k3s-server-arg and k3s-agent-arg and simplify the syntax a bit so they're more convenient to use.
Otherwise, we may end up kind of obliged to catch up with all the flags k3s provides.
What's your take on this?

@iwilltry42 iwilltry42 added breaking change enhancement New feature or request scope/cli Issue concerns the CLI (cmd/) scope/package pkg/ labels May 11, 2021
@ejose19
Copy link
Contributor Author

ejose19 commented May 11, 2021

@iwilltry42 Yes, actually I was going to do another PR after this one to add nodeFilter to k3s-server-arg & k3s-agent-arg, that way we cover all k3s flags. However I would still like to proceed with this PR to be api consistent (as k3s-node-label was just added to k3d node create). If you want I can leave the --label flag as it so it's not a breaking change, and we change the naming in next major release.

@iwilltry42
Copy link
Member

@ejose19

I was going to do another PR after this one to add nodeFilter to k3s-server-arg & k3s-agent-arg

Thanks for the initiative! I'm already on it though 😬

However I would still like to proceed with this PR to be api consistent (as k3s-node-label was just added to k3d node create).

I'm struggling, if we should actually leave it there, as we cannot even justify it with "node-specific" option, as all of those k3s flags are "node-specific" 🤔

If you want I can leave the --label flag as it so it's not a breaking change, and we change the naming in next major release.

We could add a deprecation notice and internally treat it like the new name.

@ejose19
Copy link
Contributor Author

ejose19 commented May 12, 2021

@iwilltry42 Kubernetes labels will probably be one of the most used k3s extraServerArgs, so this is just being a convenience API.

However, in case you still don't want to proceed with that (and remove the newly added option from k3d node create so there's no "discrepancy"), what about if the config file looked like this:

// both `servers` and `agents` can take either a number or an array of node specific details
servers: 1
agents:
 - volume: '/my/host/path:/path/in/node'
   port: 8080:80
   k3sExtraArgs:
     - --node-label=foo=bar

reducing the need to specify nodeFilters everywhere when it's targeting a single node, as well keep per-node configuration together.

That of course would require more work, and it's out of the scope of this PR, so let me know how should I proceed here and I will make the adjustments.

@iwilltry42 iwilltry42 changed the base branch from main to main-v5 May 14, 2021 11:57
@iwilltry42
Copy link
Member

Hi @ejose19,
Due to additional larger changes in #605 I decided to go for a new major release soon-ish, that can contain breaking changes (like your flag renaming) without problems.
For this I created the new main-v5 branch and rebased your PR onto that.
Also, the --k3s-node-label flag PR was reverted in main and "re-reverted" in main-v5 so it also only lands in the v5.0.0 release.

@ejose19
Copy link
Contributor Author

ejose19 commented May 14, 2021

@iwilltry42 that's great! However you didn't let me know how I should proceed in this PR?

@iwilltry42
Copy link
Member

@ejose19 , I think this is those are the last missing pieces before merging:

@ejose19
Copy link
Contributor Author

ejose19 commented May 15, 2021

Yeah adjusting to latest changes is not an issue, but since you said this:

@ejose19

I was going to do another PR after this one to add nodeFilter to k3s-server-arg & k3s-agent-arg

Thanks for the initiative! I'm already on it though grimacing

However I would still like to proceed with this PR to be api consistent (as k3s-node-label was just added to k3d node create).

I'm struggling, if we should actually leave it there, as we cannot even justify it with "node-specific" option, as all of those k3s flags are "node-specific" thinking

If you want I can leave the --label flag as it so it's not a breaking change, and we change the naming in next major release.

We could add a deprecation notice and internally treat it like the new name.

what I want to know is, should I remove --node-label or not?

EDIT: I saw your comments on 7087264#commitcomment-50836483, and now it's clear that you just want to adjust this PR to anything that might have changed in main-v5, I will get it done.

@ejose19 ejose19 marked this pull request as draft May 15, 2021 21:08
@ejose19 ejose19 marked this pull request as ready for review May 15, 2021 23:28
@ejose19
Copy link
Contributor Author

ejose19 commented May 15, 2021

@iwilltry42 This should be good now, here's the summary of changes:

  • Top level labels is being removed (along with its cli flags -l, --labels)
  • options.runtime.labels is implemented as replacement for the removed labels (cli shortcut being: --runtime-label)
  • options.k3s.nodeLabels is added to allow directly specifying k3s node labels (cli shortcut being: --k3s-node-label)
  • label usage is normalized for cluster create & node create
  • adjusted migration script to migrate from v1alpha2 labels to v1alpha3 options.runtime.labels
  • added test assertions to k3s node label

Copy link
Member

@iwilltry42 iwilltry42 left a comment

Choose a reason for hiding this comment

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

Looks good!
Just one last thing to clarify 👍

pkg/types/types.go Outdated Show resolved Hide resolved
@ejose19
Copy link
Contributor Author

ejose19 commented May 17, 2021

Ok, should be good now. I also added a validation for user provided --runtime-label (both in config file and in cli flag) in order to let consumers know that some label names are reserved for internal use of k3d:

https://github.com/rancher/k3d/blob/ff61747ff3e995d0a2bc828c3aa168b9ff2195eb/pkg/types/types.go#L108-L138

From that I deducted that anything that begins with k3d. or k3s. shouldn't be allowed, along with app. If you think anything else needs to be added to the validation list let me know, and also future "k3d technical label" should respect that premise in order to not conflict with user labels.

@iwilltry42
Copy link
Member

LGTM!
The validation of labels for reserved prefixes (k3d/k3s) makes total sense, thanks for that!

Thanks a lot for your contribution :)

@iwilltry42 iwilltry42 changed the title refactor: normalize label flags (k3s node & runtime) [Enhancement] Refactoring: normalize label flags (k3s node & runtime) (#598, @ejose19) May 19, 2021
@iwilltry42 iwilltry42 merged commit 9673b53 into k3d-io:main-v5 May 19, 2021
@iwilltry42 iwilltry42 modified the milestones: v4.6.0, v5.0.0 May 19, 2021
@iwilltry42 iwilltry42 linked an issue Jul 20, 2021 that may be closed by this pull request
somaritane referenced this pull request in AbsaOSS/k3d-action Nov 16, 2021
- k3d config examples migrated to `apiVersion: k3d.io/v1alpha3`
  [https://github.com/rancher/k3d/pull/605](https://github.com/rancher/k3d/pull/605)
- `:direct` node filter option used when load balancer is disabled
  [https://github.com/rancher/k3d/pull/656](https://github.com/rancher/k3d/pull/656)
- `--label` --> `--runtime-label`
  [https://github.com/rancher/k3d/pull/598](https://github.com/rancher/k3d/pull/598)
- `--k3s-server-arg` --> `--k3s-arg` with server node filter (`@server:*`)
  [https://github.com/rancher/k3d/pull/605](https://github.com/rancher/k3d/pull/605)
- removed `disableImageVolume` option from examples and test assets
- Updated documentation

Signed-off-by: Timofey Ilinykh <[email protected]>
somaritane referenced this pull request in AbsaOSS/k3d-action Nov 16, 2021
- k3d config examples migrated to `apiVersion: k3d.io/v1alpha3`
  [https://github.com/rancher/k3d/pull/605](https://github.com/rancher/k3d/pull/605)
- `:direct` node filter option used when load balancer is disabled
  [https://github.com/rancher/k3d/pull/656](https://github.com/rancher/k3d/pull/656)
- `--label` --> `--runtime-label`
  [https://github.com/rancher/k3d/pull/598](https://github.com/rancher/k3d/pull/598)
- `--k3s-server-arg` --> `--k3s-arg` with server node filter (`@server:*`)
  [https://github.com/rancher/k3d/pull/605](https://github.com/rancher/k3d/pull/605)
- removed `disableImageVolume` option from examples and test assets
- Updated documentation

Signed-off-by: Timofey Ilinykh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change enhancement New feature or request scope/cli Issue concerns the CLI (cmd/) scope/package pkg/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] node-label not working
2 participants