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
8a4f2259
Commit
8a4f2259
authored
Dec 28, 2014
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make expandResourceShortcuts part of RESTMapper on client
parent
a1ee782d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
42 additions
and
35 deletions
+42
-35
kubectl.go
cmd/kubectl/kubectl.go
+7
-3
cmd.go
pkg/kubectl/cmd/cmd.go
+0
-0
cmd_test.go
pkg/kubectl/cmd/cmd_test.go
+1
-1
create.go
pkg/kubectl/cmd/create.go
+1
-1
createall.go
pkg/kubectl/cmd/createall.go
+1
-1
delete.go
pkg/kubectl/cmd/delete.go
+1
-1
get.go
pkg/kubectl/cmd/get.go
+1
-1
log.go
pkg/kubectl/cmd/log.go
+1
-5
proxy.go
pkg/kubectl/cmd/proxy.go
+1
-1
resource.go
pkg/kubectl/cmd/resource.go
+4
-4
rollingupdate.go
pkg/kubectl/cmd/rollingupdate.go
+1
-4
update.go
pkg/kubectl/cmd/update.go
+1
-1
version.go
pkg/kubectl/cmd/version.go
+6
-8
kubectl.go
pkg/kubectl/kubectl.go
+16
-4
No files found.
cmd/kubectl/kubectl.go
View file @
8a4f2259
...
@@ -19,11 +19,15 @@ package main
...
@@ -19,11 +19,15 @@ package main
import
(
import
(
"os"
"os"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
"github.com/golang/glog"
)
)
func
main
()
{
func
main
()
{
clientBuilder
:=
clientcmd
.
NewInteractiveClientConfig
(
clientcmd
.
Config
{},
""
,
&
clientcmd
.
ConfigOverrides
{},
os
.
Stdin
)
cmd
:=
cmd
.
NewFactory
()
.
NewKubectlCommand
(
os
.
Stdout
)
cmd
.
NewFactory
(
clientBuilder
)
.
Run
(
os
.
Stdout
)
if
err
:=
cmd
.
Execute
();
err
!=
nil
{
glog
.
Errorf
(
"error: %v"
,
err
)
os
.
Exit
(
1
)
}
}
}
pkg/kubectl/cmd/cmd.go
View file @
8a4f2259
This diff is collapsed.
Click to expand it.
pkg/kubectl/cmd/cmd_test.go
View file @
8a4f2259
...
@@ -100,7 +100,7 @@ func NewTestFactory() (*Factory, *testFactory, runtime.Codec) {
...
@@ -100,7 +100,7 @@ func NewTestFactory() (*Factory, *testFactory, runtime.Codec) {
return
&
Factory
{
return
&
Factory
{
Mapper
:
mapper
,
Mapper
:
mapper
,
Typer
:
scheme
,
Typer
:
scheme
,
Client
:
func
(
*
cobra
.
Command
,
*
meta
.
RESTMapping
)
(
kubectl
.
RESTClient
,
error
)
{
REST
Client
:
func
(
*
cobra
.
Command
,
*
meta
.
RESTMapping
)
(
kubectl
.
RESTClient
,
error
)
{
return
t
.
Client
,
t
.
Err
return
t
.
Client
,
t
.
Err
},
},
Describer
:
func
(
*
cobra
.
Command
,
*
meta
.
RESTMapping
)
(
kubectl
.
Describer
,
error
)
{
Describer
:
func
(
*
cobra
.
Command
,
*
meta
.
RESTMapping
)
(
kubectl
.
Describer
,
error
)
{
...
...
pkg/kubectl/cmd/create.go
View file @
8a4f2259
...
@@ -46,7 +46,7 @@ Examples:
...
@@ -46,7 +46,7 @@ Examples:
schema
,
err
:=
f
.
Validator
(
cmd
)
schema
,
err
:=
f
.
Validator
(
cmd
)
checkErr
(
err
)
checkErr
(
err
)
mapping
,
namespace
,
name
,
data
:=
ResourceFromFile
(
cmd
,
filename
,
f
.
Typer
,
f
.
Mapper
,
schema
)
mapping
,
namespace
,
name
,
data
:=
ResourceFromFile
(
cmd
,
filename
,
f
.
Typer
,
f
.
Mapper
,
schema
)
client
,
err
:=
f
.
Client
(
cmd
,
mapping
)
client
,
err
:=
f
.
REST
Client
(
cmd
,
mapping
)
checkErr
(
err
)
checkErr
(
err
)
// use the default namespace if not specified, or check for conflict with the file's namespace
// use the default namespace if not specified, or check for conflict with the file's namespace
...
...
pkg/kubectl/cmd/createall.go
View file @
8a4f2259
...
@@ -79,7 +79,7 @@ Examples:
...
@@ -79,7 +79,7 @@ Examples:
<creates all resources listed in config.json>`
,
<creates all resources listed in config.json>`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
clientFunc
:=
func
(
mapper
*
meta
.
RESTMapping
)
(
config
.
RESTClientPoster
,
error
)
{
clientFunc
:=
func
(
mapper
*
meta
.
RESTMapping
)
(
config
.
RESTClientPoster
,
error
)
{
client
,
err
:=
f
.
Client
(
cmd
,
mapper
)
client
,
err
:=
f
.
REST
Client
(
cmd
,
mapper
)
checkErr
(
err
)
checkErr
(
err
)
return
client
,
nil
return
client
,
nil
}
}
...
...
pkg/kubectl/cmd/delete.go
View file @
8a4f2259
...
@@ -59,7 +59,7 @@ Examples:
...
@@ -59,7 +59,7 @@ Examples:
checkErr
(
err
)
checkErr
(
err
)
selector
:=
GetFlagString
(
cmd
,
"selector"
)
selector
:=
GetFlagString
(
cmd
,
"selector"
)
found
:=
0
found
:=
0
ResourcesFromArgsOrFile
(
cmd
,
args
,
filename
,
selector
,
f
.
Typer
,
f
.
Mapper
,
f
.
Client
,
schema
)
.
Visit
(
func
(
r
*
resource
.
Info
)
error
{
ResourcesFromArgsOrFile
(
cmd
,
args
,
filename
,
selector
,
f
.
Typer
,
f
.
Mapper
,
f
.
REST
Client
,
schema
)
.
Visit
(
func
(
r
*
resource
.
Info
)
error
{
found
++
found
++
if
err
:=
resource
.
NewHelper
(
r
.
Client
,
r
.
Mapping
)
.
Delete
(
r
.
Namespace
,
r
.
Name
);
err
!=
nil
{
if
err
:=
resource
.
NewHelper
(
r
.
Client
,
r
.
Mapping
)
.
Delete
(
r
.
Namespace
,
r
.
Name
);
err
!=
nil
{
return
err
return
err
...
...
pkg/kubectl/cmd/get.go
View file @
8a4f2259
...
@@ -56,7 +56,7 @@ Examples:
...
@@ -56,7 +56,7 @@ Examples:
labelSelector
,
err
:=
labels
.
ParseSelector
(
selector
)
labelSelector
,
err
:=
labels
.
ParseSelector
(
selector
)
checkErr
(
err
)
checkErr
(
err
)
client
,
err
:=
f
.
Client
(
cmd
,
mapping
)
client
,
err
:=
f
.
REST
Client
(
cmd
,
mapping
)
checkErr
(
err
)
checkErr
(
err
)
outputFormat
:=
GetFlagString
(
cmd
,
"output"
)
outputFormat
:=
GetFlagString
(
cmd
,
"output"
)
...
...
pkg/kubectl/cmd/log.go
View file @
8a4f2259
...
@@ -21,8 +21,6 @@ import (
...
@@ -21,8 +21,6 @@ import (
"strconv"
"strconv"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
)
)
func
(
f
*
Factory
)
NewCmdLog
(
out
io
.
Writer
)
*
cobra
.
Command
{
func
(
f
*
Factory
)
NewCmdLog
(
out
io
.
Writer
)
*
cobra
.
Command
{
...
@@ -46,9 +44,7 @@ Examples:
...
@@ -46,9 +44,7 @@ Examples:
}
}
namespace
:=
GetKubeNamespace
(
cmd
)
namespace
:=
GetKubeNamespace
(
cmd
)
config
,
err
:=
f
.
ClientConfig
.
ClientConfig
()
client
,
err
:=
f
.
Client
(
cmd
)
checkErr
(
err
)
client
,
err
:=
client
.
New
(
config
)
checkErr
(
err
)
checkErr
(
err
)
podID
:=
args
[
0
]
podID
:=
args
[
0
]
...
...
pkg/kubectl/cmd/proxy.go
View file @
8a4f2259
...
@@ -33,7 +33,7 @@ func (f *Factory) NewCmdProxy(out io.Writer) *cobra.Command {
...
@@ -33,7 +33,7 @@ func (f *Factory) NewCmdProxy(out io.Writer) *cobra.Command {
port
:=
GetFlagInt
(
cmd
,
"port"
)
port
:=
GetFlagInt
(
cmd
,
"port"
)
glog
.
Infof
(
"Starting to serve on localhost:%d"
,
port
)
glog
.
Infof
(
"Starting to serve on localhost:%d"
,
port
)
clientConfig
,
err
:=
f
.
ClientConfig
.
ClientConfig
(
)
clientConfig
,
err
:=
f
.
ClientConfig
(
cmd
)
checkErr
(
err
)
checkErr
(
err
)
server
,
err
:=
kubectl
.
NewProxyServer
(
GetFlagString
(
cmd
,
"www"
),
clientConfig
,
port
)
server
,
err
:=
kubectl
.
NewProxyServer
(
GetFlagString
(
cmd
,
"www"
),
clientConfig
,
port
)
...
...
pkg/kubectl/cmd/resource.go
View file @
8a4f2259
...
@@ -63,7 +63,7 @@ func ResourcesFromArgsOrFile(
...
@@ -63,7 +63,7 @@ func ResourcesFromArgsOrFile(
}
}
types
:=
SplitResourceArgument
(
args
[
0
])
types
:=
SplitResourceArgument
(
args
[
0
])
for
_
,
arg
:=
range
types
{
for
_
,
arg
:=
range
types
{
resourceName
:=
kubectl
.
ExpandResourceShortcut
(
arg
)
resourceName
:=
arg
if
len
(
resourceName
)
==
0
{
if
len
(
resourceName
)
==
0
{
usageError
(
cmd
,
"Unknown resource %s"
,
resourceName
)
usageError
(
cmd
,
"Unknown resource %s"
,
resourceName
)
}
}
...
@@ -91,7 +91,7 @@ func ResourceFromArgsOrFile(cmd *cobra.Command, args []string, filename string,
...
@@ -91,7 +91,7 @@ func ResourceFromArgsOrFile(cmd *cobra.Command, args []string, filename string,
}
}
if
len
(
args
)
==
2
{
if
len
(
args
)
==
2
{
resource
:=
kubectl
.
ExpandResourceShortcut
(
args
[
0
])
resource
:=
args
[
0
]
namespace
=
GetKubeNamespace
(
cmd
)
namespace
=
GetKubeNamespace
(
cmd
)
name
=
args
[
1
]
name
=
args
[
1
]
if
len
(
name
)
==
0
||
len
(
resource
)
==
0
{
if
len
(
name
)
==
0
||
len
(
resource
)
==
0
{
...
@@ -129,7 +129,7 @@ func ResourceFromArgs(cmd *cobra.Command, args []string, mapper meta.RESTMapper)
...
@@ -129,7 +129,7 @@ func ResourceFromArgs(cmd *cobra.Command, args []string, mapper meta.RESTMapper)
usageError
(
cmd
,
"Must provide resource and name command line params"
)
usageError
(
cmd
,
"Must provide resource and name command line params"
)
}
}
resource
:=
kubectl
.
ExpandResourceShortcut
(
args
[
0
])
resource
:=
args
[
0
]
namespace
=
GetKubeNamespace
(
cmd
)
namespace
=
GetKubeNamespace
(
cmd
)
name
=
args
[
1
]
name
=
args
[
1
]
if
len
(
name
)
==
0
||
len
(
resource
)
==
0
{
if
len
(
name
)
==
0
||
len
(
resource
)
==
0
{
...
@@ -152,7 +152,7 @@ func ResourceOrTypeFromArgs(cmd *cobra.Command, args []string, mapper meta.RESTM
...
@@ -152,7 +152,7 @@ func ResourceOrTypeFromArgs(cmd *cobra.Command, args []string, mapper meta.RESTM
usageError
(
cmd
,
"Must provide resource or a resource and name as command line params"
)
usageError
(
cmd
,
"Must provide resource or a resource and name as command line params"
)
}
}
resource
:=
kubectl
.
ExpandResourceShortcut
(
args
[
0
])
resource
:=
args
[
0
]
if
len
(
resource
)
==
0
{
if
len
(
resource
)
==
0
{
usageError
(
cmd
,
"Must provide resource or a resource and name as command line params"
)
usageError
(
cmd
,
"Must provide resource or a resource and name as command line params"
)
}
}
...
...
pkg/kubectl/cmd/rollingupdate.go
View file @
8a4f2259
...
@@ -21,7 +21,6 @@ import (
...
@@ -21,7 +21,6 @@ import (
"io"
"io"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
)
)
...
@@ -69,9 +68,7 @@ $ cat frontend-v2.json | kubectl rollingupdate frontend-v1 -f -
...
@@ -69,9 +68,7 @@ $ cat frontend-v2.json | kubectl rollingupdate frontend-v1 -f -
err
=
CompareNamespaceFromFile
(
cmd
,
namespace
)
err
=
CompareNamespaceFromFile
(
cmd
,
namespace
)
checkErr
(
err
)
checkErr
(
err
)
config
,
err
:=
f
.
ClientConfig
.
ClientConfig
()
client
,
err
:=
f
.
Client
(
cmd
)
checkErr
(
err
)
client
,
err
:=
client
.
New
(
config
)
checkErr
(
err
)
checkErr
(
err
)
obj
,
err
:=
mapping
.
Codec
.
Decode
(
data
)
obj
,
err
:=
mapping
.
Codec
.
Decode
(
data
)
...
...
pkg/kubectl/cmd/update.go
View file @
8a4f2259
...
@@ -46,7 +46,7 @@ Examples:
...
@@ -46,7 +46,7 @@ Examples:
schema
,
err
:=
f
.
Validator
(
cmd
)
schema
,
err
:=
f
.
Validator
(
cmd
)
checkErr
(
err
)
checkErr
(
err
)
mapping
,
namespace
,
name
,
data
:=
ResourceFromFile
(
cmd
,
filename
,
f
.
Typer
,
f
.
Mapper
,
schema
)
mapping
,
namespace
,
name
,
data
:=
ResourceFromFile
(
cmd
,
filename
,
f
.
Typer
,
f
.
Mapper
,
schema
)
client
,
err
:=
f
.
Client
(
cmd
,
mapping
)
client
,
err
:=
f
.
REST
Client
(
cmd
,
mapping
)
checkErr
(
err
)
checkErr
(
err
)
err
=
CompareNamespaceFromFile
(
cmd
,
namespace
)
err
=
CompareNamespaceFromFile
(
cmd
,
namespace
)
...
...
pkg/kubectl/cmd/version.go
View file @
8a4f2259
...
@@ -21,7 +21,6 @@ import (
...
@@ -21,7 +21,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
)
)
...
@@ -32,14 +31,13 @@ func (f *Factory) NewCmdVersion(out io.Writer) *cobra.Command {
...
@@ -32,14 +31,13 @@ func (f *Factory) NewCmdVersion(out io.Writer) *cobra.Command {
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
GetFlagBool
(
cmd
,
"client"
)
{
if
GetFlagBool
(
cmd
,
"client"
)
{
kubectl
.
GetClientVersion
(
out
)
kubectl
.
GetClientVersion
(
out
)
}
else
{
return
config
,
err
:=
f
.
ClientConfig
.
ClientConfig
()
checkErr
(
err
)
client
,
err
:=
client
.
New
(
config
)
checkErr
(
err
)
kubectl
.
GetVersion
(
out
,
client
)
}
}
client
,
err
:=
f
.
Client
(
cmd
)
checkErr
(
err
)
kubectl
.
GetVersion
(
out
,
client
)
},
},
}
}
cmd
.
Flags
()
.
BoolP
(
"client"
,
"c"
,
false
,
"Client version only (no server required)"
)
cmd
.
Flags
()
.
BoolP
(
"client"
,
"c"
,
false
,
"Client version only (no server required)"
)
...
...
pkg/kubectl/kubectl.go
View file @
8a4f2259
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
"strings"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
...
@@ -111,12 +112,23 @@ func makeImageList(spec *api.PodSpec) string {
...
@@ -111,12 +112,23 @@ func makeImageList(spec *api.PodSpec) string {
return
strings
.
Join
(
listOfImages
(
spec
),
","
)
return
strings
.
Join
(
listOfImages
(
spec
),
","
)
}
}
// ExpandResourceShortcut will return the expanded version of resource
// ShortcutExpander is a RESTMapper that can be used for Kubernetes
// resources.
type
ShortcutExpander
struct
{
meta
.
RESTMapper
}
// VersionAndKindForResource implements meta.RESTMapper. It expands the resource first, then invokes the wrapped
// mapper.
func
(
e
ShortcutExpander
)
VersionAndKindForResource
(
resource
string
)
(
defaultVersion
,
kind
string
,
err
error
)
{
resource
=
expandResourceShortcut
(
resource
)
return
e
.
RESTMapper
.
VersionAndKindForResource
(
resource
)
}
// expandResourceShortcut will return the expanded version of resource
// (something that a pkg/api/meta.RESTMapper can understand), if it is
// (something that a pkg/api/meta.RESTMapper can understand), if it is
// indeed a shortcut. Otherwise, will return resource unmodified.
// indeed a shortcut. Otherwise, will return resource unmodified.
// TODO: Combine with RESTMapper stuff to provide a general solution
func
expandResourceShortcut
(
resource
string
)
string
{
// to this problem.
func
ExpandResourceShortcut
(
resource
string
)
string
{
shortForms
:=
map
[
string
]
string
{
shortForms
:=
map
[
string
]
string
{
"po"
:
"pods"
,
"po"
:
"pods"
,
"rc"
:
"replicationcontrollers"
,
"rc"
:
"replicationcontrollers"
,
...
...
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