Skip to content

Commit a1ca138

Browse files
committed
feat: Enhance error messages in vertical scaling implementation
1 parent ff8dcec commit a1ca138

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pkg/util/inplaceupdate/inplace_update_vertical.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,31 @@ func (v *NativeVerticalUpdate) UpdateInplaceUpdateMetadata(op *jsonpatch.Operati
6666
// for example: /spec/containers/0/resources/limits/cpu
6767
words := strings.Split(op.Path, "/")
6868
if len(words) != 7 {
69-
return fmt.Errorf("invalid resource path: %s", op.Path)
69+
return fmt.Errorf("invalid resource path: %s, expected format: /spec/containers/{index}/resources/{limits|requests}/{resourceName}", op.Path)
7070
}
7171
idx, err := strconv.Atoi(words[3])
72-
if err != nil || len(oldTemp.Spec.Containers) <= idx {
73-
return fmt.Errorf("invalid container index: %s", op.Path)
72+
if err != nil {
73+
return fmt.Errorf("invalid container index: %s, must be a valid integer", words[3])
74+
}
75+
if len(oldTemp.Spec.Containers) <= idx {
76+
return fmt.Errorf("container index %d is out of range, pod template has %d containers (0-%d)", idx, len(oldTemp.Spec.Containers), len(oldTemp.Spec.Containers)-1)
7477
}
7578
if op.Operation == "remove" || op.Operation == "add" {
7679
// Before k8s 1.32, we can not resize resources for a container with no limit or request
7780
// TODO(Abner-1) change it if 1.32 released and allowing this operation
78-
return errors.New("can not add or remove resources")
81+
return errors.New("can not add or remove resources - only modification of existing resources is supported until Kubernetes 1.32")
7982
}
8083

8184
if op.Value == nil {
82-
return errors.New("json patch value is nil")
85+
return errors.New("json patch value is nil - a valid resource quantity value must be provided")
8386
}
8487
quantity, err := resource.ParseQuantity(op.Value.(string))
8588
if err != nil {
86-
return fmt.Errorf("parse quantity error: %v", err)
89+
return fmt.Errorf("parse quantity error: %v - use valid format like '100m' for CPU or '1Gi' for memory", err)
8790
}
8891

8992
if !v.CanResourcesResizeInPlace(words[6]) {
90-
return fmt.Errorf("disallowed inplace update resource: %s", words[6])
93+
return fmt.Errorf("disallowed inplace update resource: %s - only CPU and memory resources can be updated in-place", words[6])
9194
}
9295

9396
cName := oldTemp.Spec.Containers[idx].Name
@@ -175,11 +178,11 @@ func (v *NativeVerticalUpdate) IsUpdateCompleted(pod *v1.Pod) (bool, error) {
175178
containers[c.Name] = c
176179
}
177180
if len(pod.Status.ContainerStatuses) != len(containers) {
178-
return false, fmt.Errorf("some container status is not reported")
181+
return false, fmt.Errorf("some container status is not reported - expected %d container statuses but got %d", len(containers), len(pod.Status.ContainerStatuses))
179182
}
180183
for _, cs := range pod.Status.ContainerStatuses {
181184
if !v.isContainerUpdateCompleted(containers[cs.Name], &cs) {
182-
return false, fmt.Errorf("container %s resources not changed", cs.Name)
185+
return false, fmt.Errorf("container %s resources not changed - requested resources in spec don't match resources in status, update may still be in progress", cs.Name)
183186
}
184187
}
185188
return true, nil

0 commit comments

Comments
 (0)