Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
682e0285
Commit
682e0285
authored
May 07, 2018
by
David Eads
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stop pretending that we have statically known shortcuts
parent
8d064823
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
24 additions
and
226 deletions
+24
-226
BUILD
pkg/kubectl/BUILD
+0
-1
apply_test.go
pkg/kubectl/cmd/apply_test.go
+4
-4
autoscale.go
pkg/kubectl/cmd/autoscale.go
+1
-3
expose.go
pkg/kubectl/cmd/expose.go
+1
-2
rollout_history.go
pkg/kubectl/cmd/rollout/rollout_history.go
+1
-4
rollout_pause.go
pkg/kubectl/cmd/rollout/rollout_pause.go
+1
-4
rollout_resume.go
pkg/kubectl/cmd/rollout/rollout_resume.go
+1
-4
rollout_status.go
pkg/kubectl/cmd/rollout/rollout_status.go
+1
-3
rollout_undo.go
pkg/kubectl/cmd/rollout/rollout_undo.go
+1
-3
scale.go
pkg/kubectl/cmd/scale.go
+1
-3
taint.go
pkg/kubectl/cmd/taint.go
+2
-5
shortcut_restmapper.go
pkg/kubectl/cmd/util/shortcut_restmapper.go
+10
-6
kubectl.go
pkg/kubectl/kubectl.go
+0
-184
No files found.
pkg/kubectl/BUILD
View file @
682e0285
...
...
@@ -98,7 +98,6 @@ go_library(
"generate.go",
"history.go",
"interfaces.go",
"kubectl.go",
"namespace.go",
"pdb.go",
"priorityclass.go",
...
...
pkg/kubectl/cmd/apply_test.go
View file @
682e0285
...
...
@@ -359,7 +359,7 @@ func TestRunApplyViewLastApplied(t *testing.T) {
expectedErr
:
"error: Unexpected -o output mode: wide, the flag 'output' must be one of yaml|json
\n
See 'view-last-applied -h' for help and examples."
,
expectedOut
:
""
,
selector
:
""
,
args
:
[]
string
{
"r
c
"
,
"test-rc"
},
args
:
[]
string
{
"r
eplicationcontroller
"
,
"test-rc"
},
respBytes
:
rcBytesWithConfig
,
},
{
...
...
@@ -369,7 +369,7 @@ func TestRunApplyViewLastApplied(t *testing.T) {
expectedErr
:
""
,
expectedOut
:
"test: 1234
\n
"
,
selector
:
"name=test-rc"
,
args
:
[]
string
{
"r
c
"
},
args
:
[]
string
{
"r
eplicationcontroller
"
},
respBytes
:
rcBytesWithConfig
,
},
{
...
...
@@ -379,7 +379,7 @@ func TestRunApplyViewLastApplied(t *testing.T) {
expectedErr
:
"error: no last-applied-configuration annotation found on resource: test-rc"
,
expectedOut
:
""
,
selector
:
""
,
args
:
[]
string
{
"r
c
"
,
"test-rc"
},
args
:
[]
string
{
"r
eplicationcontroller
"
,
"test-rc"
},
respBytes
:
rcBytes
,
},
{
...
...
@@ -389,7 +389,7 @@ func TestRunApplyViewLastApplied(t *testing.T) {
expectedErr
:
"Error from server (NotFound): the server could not find the requested resource (get replicationcontrollers no-match)"
,
expectedOut
:
""
,
selector
:
""
,
args
:
[]
string
{
"r
c
"
,
"no-match"
},
args
:
[]
string
{
"r
eplicationcontroller
"
,
"no-match"
},
respBytes
:
nil
,
},
}
...
...
pkg/kubectl/cmd/autoscale.go
View file @
682e0285
...
...
@@ -95,7 +95,6 @@ func NewCmdAutoscale(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *
o
:=
NewAutoscaleOptions
(
ioStreams
)
validArgs
:=
[]
string
{
"deployment"
,
"replicaset"
,
"replicationcontroller"
}
argAliases
:=
kubectl
.
ResourceAliases
(
validArgs
)
cmd
:=
&
cobra
.
Command
{
Use
:
"autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU]"
,
...
...
@@ -108,8 +107,7 @@ func NewCmdAutoscale(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *
cmdutil
.
CheckErr
(
o
.
Validate
())
cmdutil
.
CheckErr
(
o
.
Run
())
},
ValidArgs
:
validArgs
,
ArgAliases
:
argAliases
,
ValidArgs
:
validArgs
,
}
// bind flag structs
...
...
pkg/kubectl/cmd/expose.go
View file @
682e0285
...
...
@@ -136,8 +136,7 @@ func NewCmdExposeService(f cmdutil.Factory, streams genericclioptions.IOStreams)
cmdutil
.
CheckErr
(
o
.
Complete
(
f
,
cmd
))
cmdutil
.
CheckErr
(
o
.
RunExpose
(
cmd
,
args
))
},
ValidArgs
:
validArgs
,
ArgAliases
:
kubectl
.
ResourceAliases
(
validArgs
),
ValidArgs
:
validArgs
,
}
o
.
RecordFlags
.
AddFlags
(
cmd
)
...
...
pkg/kubectl/cmd/rollout/rollout_history.go
View file @
682e0285
...
...
@@ -21,7 +21,6 @@ import (
"io"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
...
...
@@ -46,7 +45,6 @@ func NewCmdRolloutHistory(f cmdutil.Factory, out io.Writer) *cobra.Command {
options
:=
&
resource
.
FilenameOptions
{}
validArgs
:=
[]
string
{
"deployment"
,
"daemonset"
,
"statefulset"
}
argAliases
:=
kubectl
.
ResourceAliases
(
validArgs
)
cmd
:=
&
cobra
.
Command
{
Use
:
"history (TYPE NAME | TYPE/NAME) [flags]"
,
...
...
@@ -57,8 +55,7 @@ func NewCmdRolloutHistory(f cmdutil.Factory, out io.Writer) *cobra.Command {
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
cmdutil
.
CheckErr
(
RunHistory
(
f
,
cmd
,
out
,
args
,
options
))
},
ValidArgs
:
validArgs
,
ArgAliases
:
argAliases
,
ValidArgs
:
validArgs
,
}
cmd
.
Flags
()
.
Int64
(
"revision"
,
0
,
"See the details, including podTemplate of the revision specified"
)
...
...
pkg/kubectl/cmd/rollout/rollout_pause.go
View file @
682e0285
...
...
@@ -24,7 +24,6 @@ import (
"k8s.io/apimachinery/pkg/types"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/cmd/set"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
...
...
@@ -69,7 +68,6 @@ func NewCmdRolloutPause(f cmdutil.Factory, streams genericclioptions.IOStreams)
}
validArgs
:=
[]
string
{
"deployment"
}
argAliases
:=
kubectl
.
ResourceAliases
(
validArgs
)
cmd
:=
&
cobra
.
Command
{
Use
:
"pause RESOURCE"
,
...
...
@@ -89,8 +87,7 @@ func NewCmdRolloutPause(f cmdutil.Factory, streams genericclioptions.IOStreams)
}
cmdutil
.
CheckErr
(
utilerrors
.
Flatten
(
utilerrors
.
NewAggregate
(
allErrs
)))
},
ValidArgs
:
validArgs
,
ArgAliases
:
argAliases
,
ValidArgs
:
validArgs
,
}
usage
:=
"identifying the resource to get from a server."
...
...
pkg/kubectl/cmd/rollout/rollout_resume.go
View file @
682e0285
...
...
@@ -24,7 +24,6 @@ import (
"k8s.io/apimachinery/pkg/types"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/cmd/set"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
...
...
@@ -67,7 +66,6 @@ func NewCmdRolloutResume(f cmdutil.Factory, streams genericclioptions.IOStreams)
}
validArgs
:=
[]
string
{
"deployment"
}
argAliases
:=
kubectl
.
ResourceAliases
(
validArgs
)
cmd
:=
&
cobra
.
Command
{
Use
:
"resume RESOURCE"
,
...
...
@@ -87,8 +85,7 @@ func NewCmdRolloutResume(f cmdutil.Factory, streams genericclioptions.IOStreams)
}
cmdutil
.
CheckErr
(
utilerrors
.
Flatten
(
utilerrors
.
NewAggregate
(
allErrs
)))
},
ValidArgs
:
validArgs
,
ArgAliases
:
argAliases
,
ValidArgs
:
validArgs
,
}
usage
:=
"identifying the resource to get from a server."
...
...
pkg/kubectl/cmd/rollout/rollout_status.go
View file @
682e0285
...
...
@@ -77,7 +77,6 @@ func NewCmdRolloutStatus(f cmdutil.Factory, streams genericclioptions.IOStreams)
o
:=
NewRolloutStatusOptions
(
streams
)
validArgs
:=
[]
string
{
"deployment"
,
"daemonset"
,
"statefulset"
}
argAliases
:=
kubectl
.
ResourceAliases
(
validArgs
)
cmd
:=
&
cobra
.
Command
{
Use
:
"status (TYPE NAME | TYPE/NAME) [flags]"
,
...
...
@@ -90,8 +89,7 @@ func NewCmdRolloutStatus(f cmdutil.Factory, streams genericclioptions.IOStreams)
cmdutil
.
CheckErr
(
o
.
Validate
(
cmd
,
args
))
cmdutil
.
CheckErr
(
o
.
Run
())
},
ValidArgs
:
validArgs
,
ArgAliases
:
argAliases
,
ValidArgs
:
validArgs
,
}
usage
:=
"identifying the resource to get from a server."
...
...
pkg/kubectl/cmd/rollout/rollout_undo.go
View file @
682e0285
...
...
@@ -68,7 +68,6 @@ func NewCmdRolloutUndo(f cmdutil.Factory, out io.Writer) *cobra.Command {
}
validArgs
:=
[]
string
{
"deployment"
,
"daemonset"
,
"statefulset"
}
argAliases
:=
kubectl
.
ResourceAliases
(
validArgs
)
cmd
:=
&
cobra
.
Command
{
Use
:
"undo (TYPE NAME | TYPE/NAME) [flags]"
,
...
...
@@ -88,8 +87,7 @@ func NewCmdRolloutUndo(f cmdutil.Factory, out io.Writer) *cobra.Command {
}
cmdutil
.
CheckErr
(
utilerrors
.
Flatten
(
utilerrors
.
NewAggregate
(
allErrs
)))
},
ValidArgs
:
validArgs
,
ArgAliases
:
argAliases
,
ValidArgs
:
validArgs
,
}
cmd
.
Flags
()
.
Int64
(
"to-revision"
,
0
,
"The revision to rollback to. Default to 0 (last revision)."
)
...
...
pkg/kubectl/cmd/scale.go
View file @
682e0285
...
...
@@ -114,7 +114,6 @@ func NewCmdScale(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobr
o
:=
NewScaleOptions
(
ioStreams
)
validArgs
:=
[]
string
{
"deployment"
,
"replicaset"
,
"replicationcontroller"
,
"statefulset"
}
argAliases
:=
kubectl
.
ResourceAliases
(
validArgs
)
cmd
:=
&
cobra
.
Command
{
Use
:
"scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME)"
,
...
...
@@ -127,8 +126,7 @@ func NewCmdScale(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobr
cmdutil
.
CheckErr
(
o
.
Validate
(
cmd
))
cmdutil
.
CheckErr
(
o
.
RunScale
())
},
ValidArgs
:
validArgs
,
ArgAliases
:
argAliases
,
ValidArgs
:
validArgs
,
}
o
.
RecordFlags
.
AddFlags
(
cmd
)
...
...
pkg/kubectl/cmd/taint.go
View file @
682e0285
...
...
@@ -32,7 +32,6 @@ import (
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
...
...
@@ -93,7 +92,6 @@ func NewCmdTaint(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.
}
validArgs
:=
[]
string
{
"node"
}
argAliases
:=
kubectl
.
ResourceAliases
(
validArgs
)
cmd
:=
&
cobra
.
Command
{
Use
:
"taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N"
,
...
...
@@ -112,8 +110,7 @@ func NewCmdTaint(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.
cmdutil
.
CheckErr
(
err
)
}
},
ValidArgs
:
validArgs
,
ArgAliases
:
argAliases
,
ValidArgs
:
validArgs
,
}
options
.
PrintFlags
.
AddFlags
(
cmd
)
...
...
@@ -212,7 +209,7 @@ func (o TaintOptions) validateFlags() error {
// Validate checks to the TaintOptions to see if there is sufficient information run the command.
func
(
o
TaintOptions
)
Validate
()
error
{
resourceType
:=
strings
.
ToLower
(
o
.
resources
[
0
])
validResources
,
isValidResource
:=
append
(
kubectl
.
ResourceAliases
([]
string
{
"node"
}),
"node"
)
,
false
validResources
,
isValidResource
:=
[]
string
{
"node"
,
"nodes"
}
,
false
for
_
,
validResource
:=
range
validResources
{
if
resourceType
==
validResource
{
isValidResource
=
true
...
...
pkg/kubectl/cmd/util/shortcut_restmapper.go
View file @
682e0285
...
...
@@ -25,7 +25,6 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/kubernetes/pkg/kubectl"
)
// shortcutExpander is a RESTMapper that can be used for Kubernetes resources. It expands the resource first, then invokes the wrapped
...
...
@@ -73,8 +72,8 @@ func (e shortcutExpander) RESTMappings(gk schema.GroupKind, versions ...string)
// First the list of potential resources will be taken from the API server.
// Next we will append the hardcoded list of resources - to be backward compatible with old servers.
// NOTE that the list is ordered by group priority.
func
(
e
shortcutExpander
)
getShortcutMappings
()
([]
*
metav1
.
APIResourceList
,
[]
kubectl
.
R
esourceShortcuts
,
error
)
{
res
:=
[]
kubectl
.
R
esourceShortcuts
{}
func
(
e
shortcutExpander
)
getShortcutMappings
()
([]
*
metav1
.
APIResourceList
,
[]
r
esourceShortcuts
,
error
)
{
res
:=
[]
r
esourceShortcuts
{}
// get server resources
// This can return an error *and* the results it was able to find. We don't need to fail on the error.
apiResList
,
err
:=
e
.
discoveryClient
.
ServerResources
()
...
...
@@ -89,7 +88,7 @@ func (e shortcutExpander) getShortcutMappings() ([]*metav1.APIResourceList, []ku
}
for
_
,
apiRes
:=
range
apiResources
.
APIResources
{
for
_
,
shortName
:=
range
apiRes
.
ShortNames
{
rs
:=
kubectl
.
R
esourceShortcuts
{
rs
:=
r
esourceShortcuts
{
ShortForm
:
schema
.
GroupResource
{
Group
:
gv
.
Group
,
Resource
:
shortName
},
LongForm
:
schema
.
GroupResource
{
Group
:
gv
.
Group
,
Resource
:
apiRes
.
Name
},
}
...
...
@@ -98,8 +97,6 @@ func (e shortcutExpander) getShortcutMappings() ([]*metav1.APIResourceList, []ku
}
}
// append hardcoded short forms at the end of the list
res
=
append
(
res
,
kubectl
.
ResourcesShortcutStatic
...
)
return
apiResList
,
res
,
nil
}
...
...
@@ -158,3 +155,10 @@ func (e shortcutExpander) expandResourceShortcut(resource schema.GroupVersionRes
return
resource
}
// ResourceShortcuts represents a structure that holds the information how to
// transition from resource's shortcut to its full name.
type
resourceShortcuts
struct
{
ShortForm
schema
.
GroupResource
LongForm
schema
.
GroupResource
}
pkg/kubectl/kubectl.go
deleted
100644 → 0
View file @
8d064823
/*
Copyright 2014 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// A set of common functions needed by cmd/kubectl and pkg/kubectl packages.
package
kubectl
import
(
"strings"
"k8s.io/apimachinery/pkg/runtime/schema"
)
type
NamespaceInfo
struct
{
Namespace
string
}
// ResourceShortcuts represents a structure that holds the information how to
// transition from resource's shortcut to its full name.
type
ResourceShortcuts
struct
{
ShortForm
schema
.
GroupResource
LongForm
schema
.
GroupResource
}
// ResourcesShortcutStatic is the list of short names to their expanded names.
// Note that the list is ordered by group.
var
ResourcesShortcutStatic
=
[]
ResourceShortcuts
{
// If you add an entry here, please also take a look at pkg/kubectl/cmd/cmd.go
// and add an entry to valid_resources when appropriate.
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"cm"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"configmaps"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"cs"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"componentstatuses"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"ep"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"endpoints"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"ev"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"events"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"limits"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"limitranges"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"no"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"nodes"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"ns"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"namespaces"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"po"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"pods"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"pvc"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"persistentvolumeclaims"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"pv"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"persistentvolumes"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"quota"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"resourcequotas"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"rc"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"replicationcontrollers"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"rs"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"replicasets"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"sa"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"serviceaccounts"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Resource
:
"svc"
},
LongForm
:
schema
.
GroupResource
{
Resource
:
"services"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Group
:
"autoscaling"
,
Resource
:
"hpa"
},
LongForm
:
schema
.
GroupResource
{
Group
:
"autoscaling"
,
Resource
:
"horizontalpodautoscalers"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Group
:
"certificates.k8s.io"
,
Resource
:
"csr"
},
LongForm
:
schema
.
GroupResource
{
Group
:
"certificates.k8s.io"
,
Resource
:
"certificatesigningrequests"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Group
:
"policy"
,
Resource
:
"pdb"
},
LongForm
:
schema
.
GroupResource
{
Group
:
"policy"
,
Resource
:
"poddisruptionbudgets"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Group
:
"extensions"
,
Resource
:
"deploy"
},
LongForm
:
schema
.
GroupResource
{
Group
:
"extensions"
,
Resource
:
"deployments"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Group
:
"extensions"
,
Resource
:
"ds"
},
LongForm
:
schema
.
GroupResource
{
Group
:
"extensions"
,
Resource
:
"daemonsets"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Group
:
"extensions"
,
Resource
:
"hpa"
},
LongForm
:
schema
.
GroupResource
{
Group
:
"extensions"
,
Resource
:
"horizontalpodautoscalers"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Group
:
"extensions"
,
Resource
:
"ing"
},
LongForm
:
schema
.
GroupResource
{
Group
:
"extensions"
,
Resource
:
"ingresses"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Group
:
"extensions"
,
Resource
:
"netpol"
},
LongForm
:
schema
.
GroupResource
{
Group
:
"extensions"
,
Resource
:
"networkpolicies"
},
},
{
ShortForm
:
schema
.
GroupResource
{
Group
:
"extensions"
,
Resource
:
"psp"
},
LongForm
:
schema
.
GroupResource
{
Group
:
"extensions"
,
Resource
:
"podSecurityPolicies"
},
},
}
// ResourceShortFormFor looks up for a short form of resource names.
// TODO: Change the signature of this function so that it can
// make use of ResourceShortcuts.
func
ResourceShortFormFor
(
resource
string
)
(
string
,
bool
)
{
var
alias
string
exists
:=
false
for
_
,
item
:=
range
ResourcesShortcutStatic
{
if
item
.
LongForm
.
Resource
==
resource
{
alias
=
item
.
ShortForm
.
Resource
exists
=
true
break
}
}
return
alias
,
exists
}
// ResourceAliases returns the resource shortcuts and plural forms for the given resources.
func
ResourceAliases
(
rs
[]
string
)
[]
string
{
as
:=
make
([]
string
,
0
,
len
(
rs
))
plurals
:=
make
(
map
[
string
]
struct
{},
len
(
rs
))
for
_
,
r
:=
range
rs
{
var
plural
string
switch
{
case
r
==
"endpoints"
:
// Endpoints type itself is plural, unlike every other resource.
plural
=
r
case
strings
.
HasSuffix
(
r
,
"y"
)
:
plural
=
r
[
0
:
len
(
r
)
-
1
]
+
"ies"
case
strings
.
HasSuffix
(
r
,
"s"
)
:
plural
=
r
+
"es"
default
:
plural
=
r
+
"s"
}
as
=
append
(
as
,
plural
)
plurals
[
plural
]
=
struct
{}{}
}
for
_
,
item
:=
range
ResourcesShortcutStatic
{
if
_
,
found
:=
plurals
[
item
.
LongForm
.
Resource
];
found
{
as
=
append
(
as
,
item
.
ShortForm
.
Resource
)
}
}
return
as
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment