Skip to content

Conversation

@ardaguclu
Copy link
Member

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR introduces two commands under kubectl alpha for kuberc file operations.

  • kubectl alpha kuberc view: This command views the kuberc file (either explicitly defined via --kuberc or KUBERC env var or default location).
  • kubectl alpha kuberc set: This command creates/updates kuberc file (either in default location or explicitly defined via --file).

Which issue(s) this PR is related to:

KEP: kubernetes/enhancements#3104

Does this PR introduce a user-facing change?

Adding new kuberc view/set commands in kubectl to perform operations against kuberc file 

Special notes for your reviewer:

Claude helped me preparation of this PR (but this is not a bulk generated PR).

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

- [KEP]: https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/3104-introduce-kuberc 
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 31, 2025
@ardaguclu
Copy link
Member Author

/triage accepted
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. area/kubectl area/test sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 31, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Oct 31, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG CLI Oct 31, 2025
@ardaguclu
Copy link
Member Author

@ardaguclu
Copy link
Member Author

/hold
for review

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 31, 2025
@ardaguclu
Copy link
Member Author

/retest

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

This is great - thank you! But I left a bunch of comments 😅

}

var pref v1beta1.Preference
if err := yaml.Unmarshal(data, &pref); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same argument about decoding prefs.

return fmt.Errorf("kuberc file not found at %s", o.KubeRCFile)
}
return fmt.Errorf("error reading kuberc file: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we've agreed that when running kubectl kuberc view w/o any flags, so for the default location ($HOME/.kube/kuberc) and with the file NOT existing, we would create the default one for the user. No?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the code to generate a recommended preference file by first prompting to the user. Please let me know your thoughts about the mechanism and flow.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is great! One suggestion I have is to create a DefaultPreferences function, again in staging/src/k8s.io/kubectl/pkg/kuberc/ directory and just re-use it here. This way we'll have all of kuberc management in a single spot. This way when promoting to GA we'll update all of those helpers to always produce the latest version.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

explicitly = true
}

if kubeRCFile == "" && os.Getenv("KUBERC") != "" {
Copy link
Member Author

Choose a reason for hiding this comment

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

This seems to be the bug. kubeRCFile can't be empty.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch 😅

@ardaguclu
Copy link
Member Author

/retest

@ardaguclu
Copy link
Member Author

unrelated
/retest

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

A few comments, mostly non-blocking. Let's sync on slack, if you're able to pick them up before the freeze.

}

// SavePreference saves the preference to the kuberc file
func SavePreference(pref *v1beta1.Preference, file string, out io.Writer) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

For some time in the future, I think we would want all kuberc management function inside staging/src/k8s.io/kubectl/pkg/kuberc/ directory. We already have there marshal.go so saving that file would be a natural place as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

This file has been moved under pkg/kuberc.

explicitly = true
}

if kubeRCFile == "" && os.Getenv("KUBERC") != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch 😅

return fmt.Errorf("kuberc file not found at %s", o.KubeRCFile)
}
return fmt.Errorf("error reading kuberc file: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is great! One suggestion I have is to create a DefaultPreferences function, again in staging/src/k8s.io/kubectl/pkg/kuberc/ directory and just re-use it here. This way we'll have all of kuberc management in a single spot. This way when promoting to GA we'll update all of those helpers to always produce the latest version.

}

var pref *v1beta1.Preference
if err := yaml.Unmarshal(data, &pref); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

That's odd, I'll look into it, so let's leave it for a followup.

},
}

cmd.Flags().StringVar(&o.KubeRCFile, "file", o.KubeRCFile, "Path to the kuberc file to modify. If it is not specified, default kuberc location will be used.")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should not matter, we should use only one flag for consistency. If you look into what we're doing in kubectl config commands, all of them rely on the built-in --kubeconfig flag. So introducing a different name here, would be confusing.

@ardaguclu
Copy link
Member Author

/retest

@soltysh
Copy link
Contributor

soltysh commented Nov 5, 2025

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Nov 5, 2025
Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 5, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 1b10d35cf414d1093812d1246e9f6e1ab388659a

@soltysh
Copy link
Contributor

soltysh commented Nov 5, 2025

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 5, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ardaguclu, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 9cad3f8 into kubernetes:master Nov 5, 2025
13 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.35 milestone Nov 5, 2025
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in SIG CLI Nov 5, 2025
@ardaguclu ardaguclu deleted the kuberc-cmds branch November 5, 2025 09:56
darshansreenivas pushed a commit to darshansreenivas/kubernetes that referenced this pull request Nov 25, 2025
…5003) * Introduce kuberc view/set commands under kubectl alpha * Apply requested changes * Apply requested changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubectl area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. triage/accepted Indicates an issue or PR is ready to be actively worked on.

3 participants