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
5579f097
Commit
5579f097
authored
Nov 05, 2014
by
Daniel Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2148 from lavalamp/eventing3
Add events to kubectl (still need search function)
parents
259c3dc0
0b924ed9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
6 deletions
+52
-6
cmd.go
pkg/kubectl/cmd/cmd.go
+2
-0
get.go
pkg/kubectl/cmd/get.go
+1
-1
resource.go
pkg/kubectl/cmd/resource.go
+6
-5
kubectl.go
pkg/kubectl/kubectl.go
+19
-0
resource_printer.go
pkg/kubectl/resource_printer.go
+24
-0
No files found.
pkg/kubectl/cmd/cmd.go
View file @
5579f097
...
...
@@ -110,6 +110,8 @@ Find more information at https://github.com/GoogleCloudPlatform/kubernetes.`,
}
}
// TODO: remove this function and references to it-- errors it prints are
// very unhelpful because file/line number are wrong.
func
checkErr
(
err
error
)
{
if
err
!=
nil
{
glog
.
Fatalf
(
"%v"
,
err
)
...
...
pkg/kubectl/cmd/get.go
View file @
5579f097
...
...
@@ -32,7 +32,7 @@ func (f *Factory) NewCmdGet(out io.Writer) *cobra.Command {
Long
:
`Display one or many resources.
Possible resources include pods (po), replication controllers (rc), services
(se)
or minions (mi
).
(se)
, minions (mi), or events (ev
).
If you specify a Go template, you can use any fields defined for the API version
you are connecting to the server with.
...
...
pkg/kubectl/cmd/resource.go
View file @
5579f097
...
...
@@ -19,10 +19,11 @@ package cmd
import
(
"fmt"
"github.com/spf13/cobra"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/spf13/cobra"
)
// ResourceFromArgsOrFile expects two arguments or a valid file with a given type, and extracts
...
...
@@ -35,7 +36,7 @@ func ResourceFromArgsOrFile(cmd *cobra.Command, args []string, filename string,
}
if
len
(
args
)
==
2
{
resource
:=
args
[
0
]
resource
:=
kubectl
.
ExpandResourceShortcut
(
args
[
0
])
namespace
=
getKubeNamespace
(
cmd
)
name
=
args
[
1
]
if
len
(
name
)
==
0
||
len
(
resource
)
==
0
{
...
...
@@ -70,7 +71,7 @@ func ResourceFromArgs(cmd *cobra.Command, args []string, mapper meta.RESTMapper)
usageError
(
cmd
,
"Must provide resource and name command line params"
)
}
resource
:=
args
[
0
]
resource
:=
kubectl
.
ExpandResourceShortcut
(
args
[
0
])
namespace
=
getKubeNamespace
(
cmd
)
name
=
args
[
1
]
if
len
(
name
)
==
0
||
len
(
resource
)
==
0
{
...
...
@@ -93,7 +94,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"
)
}
resource
:=
args
[
0
]
resource
:=
kubectl
.
ExpandResourceShortcut
(
args
[
0
])
if
len
(
resource
)
==
0
{
usageError
(
cmd
,
"Must provide resource or a resource and name as command line params"
)
}
...
...
pkg/kubectl/kubectl.go
View file @
5579f097
...
...
@@ -146,3 +146,22 @@ func makeImageList(manifest api.ContainerManifest) string {
}
return
strings
.
Join
(
images
,
","
)
}
// ExpandResourceShortcut will return the expanded version of resource
// (something that a pkg/api/meta.RESTMapper can understand), if it is
// indeed a shortcut. Otherwise, will return resource unmodified.
// TODO: Combine with RESTMapper stuff to provide a general solution
// to this problem.
func
ExpandResourceShortcut
(
resource
string
)
string
{
shortForms
:=
map
[
string
]
string
{
"po"
:
"pods"
,
"rc"
:
"replicationcontrollers"
,
"se"
:
"services"
,
"mi"
:
"minions"
,
"ev"
:
"events"
,
}
if
expanded
,
ok
:=
shortForms
[
resource
];
ok
{
return
expanded
}
return
resource
}
pkg/kubectl/resource_printer.go
View file @
5579f097
...
...
@@ -177,6 +177,7 @@ var replicationControllerColumns = []string{"NAME", "IMAGE(S)", "SELECTOR", "REP
var
serviceColumns
=
[]
string
{
"NAME"
,
"LABELS"
,
"SELECTOR"
,
"IP"
,
"PORT"
}
var
minionColumns
=
[]
string
{
"NAME"
}
var
statusColumns
=
[]
string
{
"STATUS"
}
var
eventColumns
=
[]
string
{
"NAME"
,
"KIND"
,
"STATUS"
,
"REASON"
,
"MESSAGE"
}
// addDefaultHandlers adds print handlers for default Kubernetes types.
func
(
h
*
HumanReadablePrinter
)
addDefaultHandlers
()
{
...
...
@@ -189,6 +190,8 @@ func (h *HumanReadablePrinter) addDefaultHandlers() {
h
.
Handler
(
minionColumns
,
printMinion
)
h
.
Handler
(
minionColumns
,
printMinionList
)
h
.
Handler
(
statusColumns
,
printStatus
)
h
.
Handler
(
eventColumns
,
printEvent
)
h
.
Handler
(
eventColumns
,
printEventList
)
}
func
(
h
*
HumanReadablePrinter
)
unknown
(
data
[]
byte
,
w
io
.
Writer
)
error
{
...
...
@@ -277,6 +280,27 @@ func printStatus(status *api.Status, w io.Writer) error {
return
err
}
func
printEvent
(
event
*
api
.
Event
,
w
io
.
Writer
)
error
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s
\t
%s
\n
"
,
event
.
InvolvedObject
.
Name
,
event
.
InvolvedObject
.
Kind
,
event
.
Status
,
event
.
Reason
,
event
.
Message
,
)
return
err
}
func
printEventList
(
list
*
api
.
EventList
,
w
io
.
Writer
)
error
{
for
i
:=
range
list
.
Items
{
if
err
:=
printEvent
(
&
list
.
Items
[
i
],
w
);
err
!=
nil
{
return
err
}
}
return
nil
}
// PrintObj prints the obj in a human-friendly format according to the type of the obj.
func
(
h
*
HumanReadablePrinter
)
PrintObj
(
obj
runtime
.
Object
,
output
io
.
Writer
)
error
{
w
:=
tabwriter
.
NewWriter
(
output
,
20
,
5
,
3
,
' '
,
0
)
...
...
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