Skip to content

Conversation

@enrichman
Copy link
Collaborator

@enrichman enrichman commented Nov 14, 2025

Fix #355

There is sometimes the need to label and annotate the k3k resources.

This PR adds the --labels and --annotations flags to the create cluster and create policy commands.

@codecov-commenter
Copy link

codecov-commenter commented Nov 14, 2025

Codecov Report

❌ Patch coverage is 68.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.67%. Comparing base (d0e50a5) to head (7f5e2c8).

Files with missing lines Patch % Lines
cli/cmds/cluster_create.go 46.66% 7 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #565      +/-   ##
==========================================
- Coverage   59.71%   59.67%   -0.05%     
==========================================
  Files          56       56              
  Lines        5198     5217      +19     
==========================================
+ Hits         3104     3113       +9     
- Misses       1806     1814       +8     
- Partials      288      290       +2     
Flag Coverage Δ
cli 53.46% <68.00%> (+0.07%) ⬆️
controller 57.49% <0.00%> (-0.39%) ⬇️
e2e 57.49% <0.00%> (-0.39%) ⬇️
unit 36.59% <0.00%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@enrichman enrichman changed the title [WIP] Added labels and annotations flags to cluster and policy create Added labels and annotations flags to cluster and policy create Nov 14, 2025
@enrichman enrichman marked this pull request as ready for review November 14, 2025 13:22
@enrichman enrichman self-assigned this Nov 14, 2025
Copy link

@bigkevmcd bigkevmcd 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 apart from the parsing part which I think we should fix.


func parseKeyValuePairs(pairs []string, pairType string) map[string]string {
resultMap := make(map[string]string)

Choose a reason for hiding this comment

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

This could maybe be a bit more robust as it'll be receiving user data from the CLI?

Maybe if len(keyValue) != 2 then it's a problem, and don't limit the split?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bigkevmcd for the labels that would work, but annotations permits the value to contains = (or other chars).
Should I split the parsing logic in two? Not sure if there is a Kubernetes func that can be used to validate that.

Also an empty label, or empty annotation is still valid, so len could be 1.

Copy link

@bigkevmcd bigkevmcd Nov 14, 2025

Choose a reason for hiding this comment

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

@enrichman Good questions...I'm not sure...it feels like work for something that can be fixed with kubectl label guess :-)

I just tested this:

$ kubectl label secret/my-test-secret example.com/test=`
secret/my-test-secret labeled

Then...

$ kubectl get secret/my-test-secret -o json | jq ".metadata.labels"
{
   "example.com/test": ""
}

So...I guess that behaviour is desirable 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I've just checked the doc and it seems to be documented as well:

Valid label value:

  • must be 63 characters or less (can be empty),
  • unless empty, must begin and end with an alphanumeric character ([a-z0-9A-Z]),
  • could contain dashes (-), underscores (_), dots (.), and alphanumerics between.

Thank you!

@bigkevmcd bigkevmcd self-requested a review November 14, 2025 15:46
@enrichman enrichman merged commit 2773030 into rancher:main Nov 14, 2025
11 of 12 checks passed
@enrichman enrichman deleted the 355-labels-annotations branch November 14, 2025 15:54
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.

add cluster labels and annotations from k3kcli

3 participants