Commit 6b2f3c81 authored by Di Xu's avatar Di Xu

forbid kubectl edit an empty list

parent f75f49e7
{
"kind": "ConfigMapList",
"apiVersion": "v1",
"metadata": {
"selfLink": "/api/v1/namespaces/edit-test/configmaps",
"resourceVersion": "252"
},
"items": []
}
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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment