- Notifications
You must be signed in to change notification settings - Fork 988
Description
What happened?
I was testing the new kubectl alpha kuberc set command (added in kubernetes/kubernetes#135003) in the local environment.
I discovered what appears to be unintended behavior when updating existing configurations without specifying --option flags.
When updating an existing defaults/alias entry with --overwrite but without any --option flags, the existing options are cleared (set to nil).
I wrote a simple test case to verify this behavior:
ref: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/cmd/kuberc/set_test.go
{ name: "overwrite existing defaults without options", existingKuberc: `apiVersion: kubectl.config.k8s.io/v1beta1 kind: Preference defaults: - command: get options: - name: output default: wide `, options: SetOptions{ Section: sectionDefaults, Command: "get", Options: []string{}, // No options Overwrite: true, }, expectedPref: &v1beta1.Preference{ Defaults: []v1beta1.CommandDefaults{ { Command: "get", Options: nil, // existing options are cleared }, }, }, },The test passes, which means the current implementation clears existing options when --overwrite is used without any --option flags.
In the same way, for alias, without specifying --option flags, existing options are also cleared.
What did you expect to happen?
Existing options are preserved when --options flags is not provided.
I am not sure this behavior is intentional or not.
How can we reproduce it (as minimally and precisely as possible)?
- Clone kubernetes/kubernetes repository
- Add the test case above to
staging/src/k8s.io/kubectl/pkg/cmd/kuberc/set_test.go - Run:
go test ./staging/src/k8s.io/kubectl/pkg/cmd/kuberc/
Anything else we need to know?
I can submit a follow-up PR if this behavior is considered unintended.
Either way, I think adding explicit test cases for this behavior would be valuable to document the intended design.
Kubernetes version
Cloud provider
OS version
# On Linux: $ cat /etc/os-release # paste output here $ uname -a # paste output here # On Windows: C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture # paste output hereInstall tools
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, ...) and versions (if applicable)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status