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
51d7f856
Commit
51d7f856
authored
Sep 01, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13406 from nikhiljindal/kubectlDeployment
Auto commit by PR queue bot
parents
3d51f524
ac0b060e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
0 deletions
+67
-0
kubectl
contrib/completions/bash/kubectl
+2
-0
resource_printer.go
pkg/kubectl/resource_printer.go
+28
-0
resource_printer_test.go
pkg/kubectl/resource_printer_test.go
+37
-0
No files found.
contrib/completions/bash/kubectl
View file @
51d7f856
...
...
@@ -273,6 +273,7 @@ _kubectl_get()
must_have_one_flag
=()
must_have_one_noun
=()
must_have_one_noun+
=(
"componentstatus"
)
must_have_one_noun+
=(
"deployment"
)
must_have_one_noun+
=(
"endpoints"
)
must_have_one_noun+
=(
"event"
)
must_have_one_noun+
=(
"limitrange"
)
...
...
@@ -447,6 +448,7 @@ _kubectl_delete()
must_have_one_flag
=()
must_have_one_noun
=()
must_have_one_noun+
=(
"componentstatus"
)
must_have_one_noun+
=(
"deployment"
)
must_have_one_noun+
=(
"endpoints"
)
must_have_one_noun+
=(
"event"
)
must_have_one_noun+
=(
"limitrange"
)
...
...
pkg/kubectl/resource_printer.go
View file @
51d7f856
...
...
@@ -341,6 +341,7 @@ var persistentVolumeClaimColumns = []string{"NAME", "LABELS", "STATUS", "VOLUME"
var
componentStatusColumns
=
[]
string
{
"NAME"
,
"STATUS"
,
"MESSAGE"
,
"ERROR"
}
var
thirdPartyResourceColumns
=
[]
string
{
"NAME"
,
"DESCRIPTION"
,
"VERSION(S)"
}
var
withNamespacePrefixColumns
=
[]
string
{
"NAMESPACE"
}
// TODO(erictune): print cluster name too.
var
deploymentColumns
=
[]
string
{
"NAME"
,
"UPDATEDREPLICAS"
,
"AGE"
}
// addDefaultHandlers adds print handlers for default Kubernetes types.
func
(
h
*
HumanReadablePrinter
)
addDefaultHandlers
()
{
...
...
@@ -376,6 +377,8 @@ func (h *HumanReadablePrinter) addDefaultHandlers() {
h
.
Handler
(
componentStatusColumns
,
printComponentStatusList
)
h
.
Handler
(
thirdPartyResourceColumns
,
printThirdPartyResource
)
h
.
Handler
(
thirdPartyResourceColumns
,
printThirdPartyResourceList
)
h
.
Handler
(
deploymentColumns
,
printDeployment
)
h
.
Handler
(
deploymentColumns
,
printDeploymentList
)
}
func
(
h
*
HumanReadablePrinter
)
unknown
(
data
[]
byte
,
w
io
.
Writer
)
error
{
...
...
@@ -1096,6 +1099,31 @@ func printThirdPartyResourceList(list *expapi.ThirdPartyResourceList, w io.Write
return
nil
}
func
printDeployment
(
deployment
*
expapi
.
Deployment
,
w
io
.
Writer
,
withNamespace
bool
,
wide
bool
,
showAll
bool
,
columnLabels
[]
string
)
error
{
if
withNamespace
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
"
,
deployment
.
Namespace
);
err
!=
nil
{
return
err
}
}
updatedReplicas
:=
fmt
.
Sprintf
(
"%d/%d"
,
deployment
.
Status
.
UpdatedReplicas
,
deployment
.
Spec
.
Replicas
)
age
:=
translateTimestamp
(
deployment
.
CreationTimestamp
)
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s"
,
deployment
.
Name
,
updatedReplicas
,
age
);
err
!=
nil
{
return
err
}
_
,
err
:=
fmt
.
Fprint
(
w
,
appendLabels
(
deployment
.
Labels
,
columnLabels
))
return
err
}
func
printDeploymentList
(
list
*
expapi
.
DeploymentList
,
w
io
.
Writer
,
withNamespace
bool
,
wide
bool
,
showAll
bool
,
columnLabels
[]
string
)
error
{
for
_
,
item
:=
range
list
.
Items
{
if
err
:=
printDeployment
(
&
item
,
w
,
withNamespace
,
wide
,
showAll
,
columnLabels
);
err
!=
nil
{
return
err
}
}
return
nil
}
func
appendLabels
(
itemLabels
map
[
string
]
string
,
columnLabels
[]
string
)
string
{
var
buffer
bytes
.
Buffer
...
...
pkg/kubectl/resource_printer_test.go
View file @
51d7f856
...
...
@@ -29,6 +29,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/expapi"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
...
...
@@ -1221,3 +1222,39 @@ func TestTranslateTimestamp(t *testing.T) {
}
}
}
func
TestPrintDeployment
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
deployment
expapi
.
Deployment
expect
string
}{
{
expapi
.
Deployment
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test1"
,
CreationTimestamp
:
util
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
},
Spec
:
expapi
.
DeploymentSpec
{
Replicas
:
5
,
Template
:
&
api
.
PodTemplateSpec
{
Spec
:
api
.
PodSpec
{
Containers
:
make
([]
api
.
Container
,
2
)},
},
},
Status
:
expapi
.
DeploymentStatus
{
Replicas
:
10
,
UpdatedReplicas
:
2
,
},
},
"test1
\t
2/5
\t
0s
\n
"
,
},
}
buf
:=
bytes
.
NewBuffer
([]
byte
{})
for
_
,
test
:=
range
tests
{
printDeployment
(
&
test
.
deployment
,
buf
,
false
,
false
,
true
,
[]
string
{})
if
buf
.
String
()
!=
test
.
expect
{
t
.
Fatalf
(
"Expected: %s, got: %s"
,
test
.
expect
,
buf
.
String
())
}
buf
.
Reset
()
}
}
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