Extend all to more resources

Added more things from the list here:
https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/cmd.go#L159

Update the devel/kubectl-conventions.md with the rules mentioned by
a few folks on which resources could be added to the special 'all' alias

Related to a suggestion in issue #22337
This commit is contained in:
Davanum Srinivas
2016-07-14 07:48:32 -04:00
parent 4fdde68f78
commit ccf4e4d61e
8 changed files with 151 additions and 46 deletions

View File

@@ -38,6 +38,18 @@ serviceaccounts (aka 'sa'), ingresses (aka 'ing'), horizontalpodautoscalers (aka
componentstatuses (aka 'cs), endpoints (aka 'ep'), petsets (alpha feature, may be unstable) and secrets.`
)
// userResources is a group of resources mostly used by a kubectl user
var userResources = []unversioned.GroupResource{
{Group: "", Resource: "pods"},
{Group: "", Resource: "replicationcontrollers"},
{Group: "", Resource: "services"},
{Group: "apps", Resource: "petsets"},
{Group: "autoscaling", Resource: "horizontalpodautoscalers"},
{Group: "extensions", Resource: "jobs"},
{Group: "extensions", Resource: "deployments"},
{Group: "extensions", Resource: "replicasets"},
}
type NamespaceInfo struct {
Namespace string
}
@@ -107,6 +119,15 @@ func (m OutputVersionMapper) RESTMapping(gk unversioned.GroupKind, versions ...s
// resources. It expands the resource first, then invokes the wrapped RESTMapper
type ShortcutExpander struct {
RESTMapper meta.RESTMapper
All []unversioned.GroupResource
}
func NewShortcutExpander(delegate meta.RESTMapper) ShortcutExpander {
return ShortcutExpander{
All: userResources,
RESTMapper: delegate,
}
}
var _ meta.RESTMapper = &ShortcutExpander{}
@@ -139,7 +160,19 @@ func (e ShortcutExpander) ResourceSingularizer(resource string) (string, error)
return e.RESTMapper.ResourceSingularizer(expandResourceShortcut(unversioned.GroupVersionResource{Resource: resource}).Resource)
}
// AliasesForResource returns whether a resource has an alias or not
func (e ShortcutExpander) AliasesForResource(resource string) ([]string, bool) {
if strings.ToLower(resource) == "all" {
var resources []unversioned.GroupResource
if resources = e.All; len(e.All) == 0 {
resources = userResources
}
aliases := []string{}
for _, r := range resources {
aliases = append(aliases, r.Resource)
}
return aliases, true
}
return e.RESTMapper.AliasesForResource(expandResourceShortcut(unversioned.GroupVersionResource{Resource: resource}).Resource)
}