mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
Merge pull request #50205 from dixudx/fix_kubectl_edit_panic_nil_list
Automatic merge from submit-queue (batch tested with PRs 50537, 49699, 50160, 49025, 50205) not allowing "kubectl edit <resource>" when you got an empty list **What this PR does / why we need it**: `kubectl edit` will panic when adding an empty list. > panic: runtime error: index out of range **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #50147 **Special notes for your reviewer**: /assign @errordeveloper @mengqiy @janetkuo @fabianofranz /cc @rootfs @soltysh @sttts **Release note**: ```release-note not allowing "kubectl edit <resource>" when you got an empty list ```
This commit is contained in:
commit
577fdf91c2
0
pkg/kubectl/cmd/testdata/edit/testcase-edit-from-empty/0.request
vendored
Executable file
0
pkg/kubectl/cmd/testdata/edit/testcase-edit-from-empty/0.request
vendored
Executable file
9
pkg/kubectl/cmd/testdata/edit/testcase-edit-from-empty/0.response
vendored
Executable file
9
pkg/kubectl/cmd/testdata/edit/testcase-edit-from-empty/0.response
vendored
Executable file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"kind": "ConfigMapList",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"selfLink": "/api/v1/namespaces/edit-test/configmaps",
|
||||
"resourceVersion": "252"
|
||||
},
|
||||
"items": []
|
||||
}
|
15
pkg/kubectl/cmd/testdata/edit/testcase-edit-from-empty/test.yaml
vendored
Executable file
15
pkg/kubectl/cmd/testdata/edit/testcase-edit-from-empty/test.yaml
vendored
Executable file
@ -0,0 +1,15 @@
|
||||
description: add a testcase description
|
||||
mode: edit
|
||||
args:
|
||||
- configmap
|
||||
namespace: "edit-test"
|
||||
expectedStderr:
|
||||
- edit cancelled, no objects found.
|
||||
expectedExitCode: 1
|
||||
steps:
|
||||
- type: request
|
||||
expectedMethod: GET
|
||||
expectedPath: /api/v1/namespaces/edit-test/configmaps
|
||||
expectedInput: 0.request
|
||||
resultingStatusCode: 200
|
||||
resultingOutput: 0.response
|
@ -336,6 +336,9 @@ func (o *EditOptions) Run() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(infos) == 0 {
|
||||
return errors.New("edit cancelled, no objects found.")
|
||||
}
|
||||
return editFn(infos)
|
||||
case ApplyEditMode:
|
||||
infos, err := o.OriginalResult.Infos()
|
||||
@ -500,11 +503,7 @@ func getPrinter(format string) *editPrinterOptions {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *EditOptions) visitToPatch(
|
||||
originalInfos []*resource.Info,
|
||||
patchVisitor resource.Visitor,
|
||||
results *editResults,
|
||||
) error {
|
||||
func (o *EditOptions) visitToPatch(originalInfos []*resource.Info, patchVisitor resource.Visitor, results *editResults) error {
|
||||
err := patchVisitor.Visit(func(info *resource.Info, incomingErr error) error {
|
||||
editObjUID, err := meta.NewAccessor().UID(info.Object)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user