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
b712bfd7
Commit
b712bfd7
authored
Aug 01, 2016
by
Daniel Smith
Committed by
GitHub
Aug 01, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Extend all to more resources"
parent
1ec10511
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
46 additions
and
151 deletions
+46
-151
kubectl-conventions.md
docs/devel/kubectl-conventions.md
+0
-16
test-cmd.sh
hack/make-rules/test-cmd.sh
+0
-12
install.go
pkg/api/install/install.go
+8
-1
factory.go
pkg/kubectl/cmd/util/factory.go
+2
-44
factory_test.go
pkg/kubectl/cmd/util/factory_test.go
+0
-42
kubectl.go
pkg/kubectl/kubectl.go
+0
-33
builder.go
pkg/kubectl/resource/builder.go
+3
-3
builder_test.go
pkg/kubectl/resource/builder_test.go
+33
-0
No files found.
docs/devel/kubectl-conventions.md
View file @
b712bfd7
...
@@ -43,7 +43,6 @@ Updated: 8/27/2015
...
@@ -43,7 +43,6 @@ Updated: 8/27/2015
-
[
Principles
](
#principles
)
-
[
Principles
](
#principles
)
-
[
Command conventions
](
#command-conventions
)
-
[
Command conventions
](
#command-conventions
)
-
[
Create commands
](
#create-commands
)
-
[
Create commands
](
#create-commands
)
-
[
Rules for extending special resource alias - "all"
](
#rules-for-extending-special-resource-alias---all
)
-
[
Flag conventions
](
#flag-conventions
)
-
[
Flag conventions
](
#flag-conventions
)
-
[
Output conventions
](
#output-conventions
)
-
[
Output conventions
](
#output-conventions
)
-
[
Documentation conventions
](
#documentation-conventions
)
-
[
Documentation conventions
](
#documentation-conventions
)
...
@@ -119,21 +118,6 @@ creating tls secrets. You create these as separate commands to get distinct
...
@@ -119,21 +118,6 @@ creating tls secrets. You create these as separate commands to get distinct
flags and separate help that is tailored for the particular usage.
flags and separate help that is tailored for the particular usage.
### Rules for extending special resource alias - "all"
Here are the rules to add a new resource to the
`kubectl get all`
output.
*
No cluster scoped resources
*
No namespace admin level resources (limits, quota, policy, authorization
rules)
*
No resources that are potentially unrecoverable (secrets and pvc)
*
Resources that are considered "similar" to #3 should be grouped
the same (configmaps)
## Flag conventions
## Flag conventions
*
Flags are all lowercase, with words separated by hyphens
*
Flags are all lowercase, with words separated by hyphens
...
...
hack/make-rules/test-cmd.sh
View file @
b712bfd7
...
@@ -1014,18 +1014,6 @@ __EOF__
...
@@ -1014,18 +1014,6 @@ __EOF__
exit
1
exit
1
fi
fi
### Test kubectl get all
output_message
=
$(
kubectl
--v
=
6
--namespace
default get all 2>&1
"
${
kube_flags
[@]
}
"
)
# Post-condition: Check if we get 200 OK from all the url(s)
kube::test::if_has_string
"
${
output_message
}
"
"/api 200 OK"
kube::test::if_has_string
"
${
output_message
}
"
"/apis 200 OK"
kube::test::if_has_string
"
${
output_message
}
"
"/apis/apps/v1alpha1/namespaces/default/petsets 200 OK"
kube::test::if_has_string
"
${
output_message
}
"
"/apis/autoscaling/v1/namespaces/default/horizontalpodautoscalers 200 OK"
kube::test::if_has_string
"
${
output_message
}
"
"/apis/extensions/v1beta1/namespaces/default/jobs 200 OK"
kube::test::if_has_string
"
${
output_message
}
"
"/apis/extensions/v1beta1/namespaces/default/deployments 200 OK"
kube::test::if_has_string
"
${
output_message
}
"
"/apis/extensions/v1beta1/namespaces/default/deployments 200 OK"
#####################################
#####################################
# Third Party Resources #
# Third Party Resources #
#####################################
#####################################
...
...
pkg/api/install/install.go
View file @
b712bfd7
...
@@ -88,6 +88,9 @@ func enableVersions(externalVersions []unversioned.GroupVersion) error {
...
@@ -88,6 +88,9 @@ func enableVersions(externalVersions []unversioned.GroupVersion) error {
return
nil
return
nil
}
}
// userResources is a group of resources mostly used by a kubectl user
var
userResources
=
[]
string
{
"rc"
,
"svc"
,
"pods"
,
"pvc"
}
func
newRESTMapper
(
externalVersions
[]
unversioned
.
GroupVersion
)
meta
.
RESTMapper
{
func
newRESTMapper
(
externalVersions
[]
unversioned
.
GroupVersion
)
meta
.
RESTMapper
{
// the list of kinds that are scoped at the root of the api hierarchy
// the list of kinds that are scoped at the root of the api hierarchy
// if a kind is not enumerated here, it is assumed to have a namespace scope
// if a kind is not enumerated here, it is assumed to have a namespace scope
...
@@ -113,7 +116,11 @@ func newRESTMapper(externalVersions []unversioned.GroupVersion) meta.RESTMapper
...
@@ -113,7 +116,11 @@ func newRESTMapper(externalVersions []unversioned.GroupVersion) meta.RESTMapper
"ThirdPartyResourceData"
,
"ThirdPartyResourceData"
,
"ThirdPartyResourceList"
)
"ThirdPartyResourceList"
)
return
api
.
NewDefaultRESTMapper
(
externalVersions
,
interfacesFor
,
importPrefix
,
ignoredKinds
,
rootScoped
)
mapper
:=
api
.
NewDefaultRESTMapper
(
externalVersions
,
interfacesFor
,
importPrefix
,
ignoredKinds
,
rootScoped
)
// setup aliases for groups of resources
mapper
.
AddResourceAlias
(
"all"
,
userResources
...
)
return
mapper
}
}
// InterfacesFor returns the default Codec and ResourceVersioner for a given version
// InterfacesFor returns the default Codec and ResourceVersioner for a given version
...
...
pkg/kubectl/cmd/util/factory.go
View file @
b712bfd7
...
@@ -236,53 +236,12 @@ func makeInterfacesFor(versionList []unversioned.GroupVersion) func(version unve
...
@@ -236,53 +236,12 @@ func makeInterfacesFor(versionList []unversioned.GroupVersion) func(version unve
}
}
}
}
func
DiscoveryRESTMapper
(
clients
*
ClientCache
,
delegate
meta
.
RESTMapper
)
kubectl
.
ShortcutExpander
{
defaultMapper
:=
kubectl
.
NewShortcutExpander
(
delegate
)
if
clients
==
nil
{
return
defaultMapper
}
client
,
err
:=
clients
.
ClientForVersion
(
&
unversioned
.
GroupVersion
{
Version
:
"v1"
})
if
err
!=
nil
{
return
defaultMapper
}
// Check if we have access to server resources
apiResources
,
err
:=
client
.
Discovery
()
.
ServerResources
()
if
err
!=
nil
{
return
defaultMapper
}
availableResources
:=
[]
unversioned
.
GroupVersionResource
{}
for
groupVersionString
,
resourceList
:=
range
apiResources
{
currVersion
,
err
:=
unversioned
.
ParseGroupVersion
(
groupVersionString
)
if
err
!=
nil
{
return
defaultMapper
}
for
_
,
resource
:=
range
resourceList
.
APIResources
{
availableResources
=
append
(
availableResources
,
currVersion
.
WithResource
(
resource
.
Name
))
}
}
availableAll
:=
[]
unversioned
.
GroupResource
{}
for
_
,
requestedResource
:=
range
defaultMapper
.
All
{
for
_
,
availableResource
:=
range
availableResources
{
if
requestedResource
.
Group
==
availableResource
.
Group
&&
requestedResource
.
Resource
==
availableResource
.
Resource
{
availableAll
=
append
(
availableAll
,
requestedResource
)
break
}
}
}
return
kubectl
.
ShortcutExpander
{
All
:
availableAll
,
RESTMapper
:
delegate
}
}
// NewFactory creates a factory with the default Kubernetes resources defined
// NewFactory creates a factory with the default Kubernetes resources defined
// if optionalClientConfig is nil, then flags will be bound to a new clientcmd.ClientConfig.
// if optionalClientConfig is nil, then flags will be bound to a new clientcmd.ClientConfig.
// if optionalClientConfig is not nil, then this factory will make use of it.
// if optionalClientConfig is not nil, then this factory will make use of it.
func
NewFactory
(
optionalClientConfig
clientcmd
.
ClientConfig
)
*
Factory
{
func
NewFactory
(
optionalClientConfig
clientcmd
.
ClientConfig
)
*
Factory
{
mapper
:=
kubectl
.
ShortcutExpander
{
RESTMapper
:
registered
.
RESTMapper
()}
flags
:=
pflag
.
NewFlagSet
(
""
,
pflag
.
ContinueOnError
)
flags
:=
pflag
.
NewFlagSet
(
""
,
pflag
.
ContinueOnError
)
flags
.
SetNormalizeFunc
(
utilflag
.
WarnWordSepNormalizeFunc
)
// Warn for "_" flags
flags
.
SetNormalizeFunc
(
utilflag
.
WarnWordSepNormalizeFunc
)
// Warn for "_" flags
...
@@ -292,7 +251,6 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -292,7 +251,6 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}
}
clients
:=
NewClientCache
(
clientConfig
)
clients
:=
NewClientCache
(
clientConfig
)
mapper
:=
DiscoveryRESTMapper
(
clients
,
registered
.
RESTMapper
())
return
&
Factory
{
return
&
Factory
{
clients
:
clients
,
clients
:
clients
,
...
...
pkg/kubectl/cmd/util/factory_test.go
View file @
b712bfd7
...
@@ -32,7 +32,6 @@ import (
...
@@ -32,7 +32,6 @@ import (
"time"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/validation"
"k8s.io/kubernetes/pkg/api/validation"
...
@@ -43,7 +42,6 @@ import (
...
@@ -43,7 +42,6 @@ import (
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/flag"
"k8s.io/kubernetes/pkg/util/flag"
...
@@ -716,43 +714,3 @@ func TestMakePortsString(t *testing.T) {
...
@@ -716,43 +714,3 @@ func TestMakePortsString(t *testing.T) {
}
}
}
}
}
}
func
fakeClient
()
resource
.
ClientMapper
{
return
resource
.
ClientMapperFunc
(
func
(
*
meta
.
RESTMapping
)
(
resource
.
RESTClient
,
error
)
{
return
&
fake
.
RESTClient
{},
nil
})
}
func
TestReplaceAliases
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
arg
string
expected
string
}{
{
name
:
"no-replacement"
,
arg
:
"service"
,
expected
:
"service"
,
},
{
name
:
"all-replacement"
,
arg
:
"all"
,
expected
:
"pods,replicationcontrollers,services,petsets,horizontalpodautoscalers,jobs,deployments,replicasets"
,
},
{
name
:
"alias-in-comma-separated-arg"
,
arg
:
"all,secrets"
,
expected
:
"pods,replicationcontrollers,services,petsets,horizontalpodautoscalers,jobs,deployments,replicasets,secrets"
,
},
}
mapper
:=
DiscoveryRESTMapper
(
nil
,
testapi
.
Default
.
RESTMapper
())
b
:=
resource
.
NewBuilder
(
mapper
,
api
.
Scheme
,
fakeClient
(),
testapi
.
Default
.
Codec
())
for
_
,
test
:=
range
tests
{
replaced
:=
b
.
ReplaceAliases
(
test
.
arg
)
if
replaced
!=
test
.
expected
{
t
.
Errorf
(
"%s: unexpected argument: expected %s, got %s"
,
test
.
name
,
test
.
expected
,
replaced
)
}
}
}
pkg/kubectl/kubectl.go
View file @
b712bfd7
...
@@ -38,18 +38,6 @@ serviceaccounts (aka 'sa'), ingresses (aka 'ing'), horizontalpodautoscalers (aka
...
@@ -38,18 +38,6 @@ serviceaccounts (aka 'sa'), ingresses (aka 'ing'), horizontalpodautoscalers (aka
componentstatuses (aka 'cs), endpoints (aka 'ep'), petsets (alpha feature, may be unstable) and secrets.`
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
{
type
NamespaceInfo
struct
{
Namespace
string
Namespace
string
}
}
...
@@ -119,15 +107,6 @@ func (m OutputVersionMapper) RESTMapping(gk unversioned.GroupKind, versions ...s
...
@@ -119,15 +107,6 @@ func (m OutputVersionMapper) RESTMapping(gk unversioned.GroupKind, versions ...s
// resources. It expands the resource first, then invokes the wrapped RESTMapper
// resources. It expands the resource first, then invokes the wrapped RESTMapper
type
ShortcutExpander
struct
{
type
ShortcutExpander
struct
{
RESTMapper
meta
.
RESTMapper
RESTMapper
meta
.
RESTMapper
All
[]
unversioned
.
GroupResource
}
func
NewShortcutExpander
(
delegate
meta
.
RESTMapper
)
ShortcutExpander
{
return
ShortcutExpander
{
All
:
userResources
,
RESTMapper
:
delegate
,
}
}
}
var
_
meta
.
RESTMapper
=
&
ShortcutExpander
{}
var
_
meta
.
RESTMapper
=
&
ShortcutExpander
{}
...
@@ -160,19 +139,7 @@ func (e ShortcutExpander) ResourceSingularizer(resource string) (string, error)
...
@@ -160,19 +139,7 @@ func (e ShortcutExpander) ResourceSingularizer(resource string) (string, error)
return
e
.
RESTMapper
.
ResourceSingularizer
(
expandResourceShortcut
(
unversioned
.
GroupVersionResource
{
Resource
:
resource
})
.
Resource
)
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
)
{
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
)
return
e
.
RESTMapper
.
AliasesForResource
(
expandResourceShortcut
(
unversioned
.
GroupVersionResource
{
Resource
:
resource
})
.
Resource
)
}
}
...
...
pkg/kubectl/resource/builder.go
View file @
b712bfd7
...
@@ -317,7 +317,7 @@ func (b *Builder) ResourceTypeOrNameArgs(allowEmptySelector bool, args ...string
...
@@ -317,7 +317,7 @@ func (b *Builder) ResourceTypeOrNameArgs(allowEmptySelector bool, args ...string
}
}
if
len
(
args
)
>
0
{
if
len
(
args
)
>
0
{
// Try replacing aliases only in types
// Try replacing aliases only in types
args
[
0
]
=
b
.
R
eplaceAliases
(
args
[
0
])
args
[
0
]
=
b
.
r
eplaceAliases
(
args
[
0
])
}
}
switch
{
switch
{
case
len
(
args
)
>
2
:
case
len
(
args
)
>
2
:
...
@@ -338,9 +338,9 @@ func (b *Builder) ResourceTypeOrNameArgs(allowEmptySelector bool, args ...string
...
@@ -338,9 +338,9 @@ func (b *Builder) ResourceTypeOrNameArgs(allowEmptySelector bool, args ...string
return
b
return
b
}
}
//
R
eplaceAliases accepts an argument and tries to expand any existing
//
r
eplaceAliases accepts an argument and tries to expand any existing
// aliases found in it
// aliases found in it
func
(
b
*
Builder
)
R
eplaceAliases
(
input
string
)
string
{
func
(
b
*
Builder
)
r
eplaceAliases
(
input
string
)
string
{
replaced
:=
[]
string
{}
replaced
:=
[]
string
{}
for
_
,
arg
:=
range
strings
.
Split
(
input
,
","
)
{
for
_
,
arg
:=
range
strings
.
Split
(
input
,
","
)
{
if
aliases
,
ok
:=
b
.
mapper
.
AliasesForResource
(
arg
);
ok
{
if
aliases
,
ok
:=
b
.
mapper
.
AliasesForResource
(
arg
);
ok
{
...
...
pkg/kubectl/resource/builder_test.go
View file @
b712bfd7
...
@@ -1154,6 +1154,39 @@ func TestReceiveMultipleErrors(t *testing.T) {
...
@@ -1154,6 +1154,39 @@ func TestReceiveMultipleErrors(t *testing.T) {
}
}
}
}
func
TestReplaceAliases
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
arg
string
expected
string
}{
{
name
:
"no-replacement"
,
arg
:
"service"
,
expected
:
"service"
,
},
{
name
:
"all-replacement"
,
arg
:
"all"
,
expected
:
"rc,svc,pods,pvc"
,
},
{
name
:
"alias-in-comma-separated-arg"
,
arg
:
"all,secrets"
,
expected
:
"rc,svc,pods,pvc,secrets"
,
},
}
b
:=
NewBuilder
(
testapi
.
Default
.
RESTMapper
(),
api
.
Scheme
,
fakeClient
(),
testapi
.
Default
.
Codec
())
for
_
,
test
:=
range
tests
{
replaced
:=
b
.
replaceAliases
(
test
.
arg
)
if
replaced
!=
test
.
expected
{
t
.
Errorf
(
"%s: unexpected argument: expected %s, got %s"
,
test
.
name
,
test
.
expected
,
replaced
)
}
}
}
func
TestHasNames
(
t
*
testing
.
T
)
{
func
TestHasNames
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
args
[]
string
args
[]
string
...
...
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