mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
add err message if <rsrc>/<name> pairs specified under --local
This commit is contained in:
parent
6003f87b78
commit
c10f4f78bc
@ -150,7 +150,15 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
|
||||
SelectorParam(o.Selector).
|
||||
ResourceTypeOrNameArgs(o.All, o.Resources...).
|
||||
Latest()
|
||||
} else {
|
||||
// if a --local flag was provided, and a resource was specified in the form
|
||||
// <resource>/<name>, fail immediately as --local cannot query the api server
|
||||
// for the specified resource.
|
||||
if len(o.Resources) > 0 {
|
||||
return resource.LocalResourceError
|
||||
}
|
||||
}
|
||||
|
||||
o.Infos, err = builder.Do().Infos()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -155,6 +155,13 @@ func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
|
||||
SelectorParam(o.Selector).
|
||||
ResourceTypeOrNameArgs(o.All, args...).
|
||||
Latest()
|
||||
} else {
|
||||
// if a --local flag was provided, and a resource was specified in the form
|
||||
// <resource>/<name>, fail immediately as --local cannot query the api server
|
||||
// for the specified resource.
|
||||
if len(args) > 0 {
|
||||
return resource.LocalResourceError
|
||||
}
|
||||
}
|
||||
|
||||
o.Infos, err = builder.Do().Infos()
|
||||
|
@ -60,7 +60,7 @@ func TestResourcesLocal(t *testing.T) {
|
||||
Requests: "cpu=200m,memory=512Mi",
|
||||
ContainerSelector: "*"}
|
||||
|
||||
err := opts.Complete(f, cmd, []string{""})
|
||||
err := opts.Complete(f, cmd, []string{})
|
||||
if err == nil {
|
||||
err = opts.Validate()
|
||||
}
|
||||
|
@ -134,6 +134,13 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
|
||||
o.builder = o.builder.
|
||||
ResourceTypeOrNameArgs(o.all, o.resources...).
|
||||
Latest()
|
||||
} else {
|
||||
// if a --local flag was provided, and a resource was specified in the form
|
||||
// <resource>/<name>, fail immediately as --local cannot query the api server
|
||||
// for the specified resource.
|
||||
if len(o.resources) > 0 {
|
||||
return resource.LocalResourceError
|
||||
}
|
||||
}
|
||||
|
||||
o.PrintObject = func(obj runtime.Object) error {
|
||||
|
@ -137,7 +137,15 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
|
||||
SelectorParam(o.Selector).
|
||||
ResourceTypeOrNameArgs(o.All, args...).
|
||||
Latest()
|
||||
} else {
|
||||
// if a --local flag was provided, and a resource was specified in the form
|
||||
// <resource>/<name>, fail immediately as --local cannot query the api server
|
||||
// for the specified resource.
|
||||
if len(args) > 0 {
|
||||
return resource.LocalResourceError
|
||||
}
|
||||
}
|
||||
|
||||
o.Infos, err = builder.Do().Infos()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package resource
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
@ -88,6 +89,11 @@ Example resource specifications include:
|
||||
'<resource> <name>'
|
||||
'<resource>'`)
|
||||
|
||||
var LocalResourceError = errors.New(`error: you must specify resources by --filename when --local is set.
|
||||
Example resource specifications include:
|
||||
'-f rsrc.yaml'
|
||||
'--filename=rsrc.json'`)
|
||||
|
||||
// TODO: expand this to include other errors.
|
||||
func IsUsageError(err error) bool {
|
||||
if err == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user