mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
fixed some issues with kubectl set resources
when using kubectl set resources it resets all resource fields that are not being set. for example # kubectl set resources deployments nginx --limits=cpu=100m followed by # kubectl set resources deployments nginx --limits=memory=256Mi would result in the nginx deployment only limiting memory at 256Mi with the previous limit placed on the cpu being wiped out. This behavior is corrected so that each invocation only modifies fields set in that command and changed the testing so that the desired behavior is checked. Also a typo: you must specify an update to requests or limits or (in the form of --requests/--limits) corrected to you must specify an update to requests or limits (in the form of --requests/--limits) changelog: - fixed a typo in hack/make-rules/test-cmd.sh "effecting" to "affecting"
This commit is contained in:
parent
bcfb4366e3
commit
9d7ae7b80d
@ -159,7 +159,7 @@ func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
|
||||
func (o *ResourcesOptions) Validate() error {
|
||||
var err error
|
||||
if len(o.Limits) == 0 && len(o.Requests) == 0 {
|
||||
return fmt.Errorf("you must specify an update to requests or limits or (in the form of --requests/--limits)")
|
||||
return fmt.Errorf("you must specify an update to requests or limits (in the form of --requests/--limits)")
|
||||
}
|
||||
|
||||
o.ResourceRequirements, err = kubectl.HandleResourceRequirements(map[string]string{"limits": o.Limits, "requests": o.Requests})
|
||||
@ -178,7 +178,19 @@ func (o *ResourcesOptions) Run() error {
|
||||
containers, _ := selectContainers(spec.Containers, o.ContainerSelector)
|
||||
if len(containers) != 0 {
|
||||
for i := range containers {
|
||||
containers[i].Resources = o.ResourceRequirements
|
||||
if len(o.Limits) != 0 && len(containers[i].Resources.Limits) == 0 {
|
||||
containers[i].Resources.Limits = make(api.ResourceList)
|
||||
}
|
||||
for key, value := range o.ResourceRequirements.Limits {
|
||||
containers[i].Resources.Limits[key] = value
|
||||
}
|
||||
|
||||
if len(o.Requests) != 0 && len(containers[i].Resources.Requests) == 0 {
|
||||
containers[i].Resources.Requests = make(api.ResourceList)
|
||||
}
|
||||
for key, value := range o.ResourceRequirements.Requests {
|
||||
containers[i].Resources.Requests[key] = value
|
||||
}
|
||||
transformed = true
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user