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
5f8e76b4
Commit
5f8e76b4
authored
Oct 21, 2016
by
Maciej Szulik
Committed by
Marcin
Nov 09, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add resource printer and describer for PodDisruptionBudget
parent
c8a57231
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
describe.go
pkg/kubectl/describe.go
+36
-0
resource_printer.go
pkg/kubectl/resource_printer.go
+44
-0
No files found.
pkg/kubectl/describe.go
View file @
5f8e76b4
...
@@ -40,6 +40,7 @@ import (
...
@@ -40,6 +40,7 @@ import (
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/certificates"
"k8s.io/kubernetes/pkg/apis/certificates"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/policy"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/apis/storage"
storageutil
"k8s.io/kubernetes/pkg/apis/storage/util"
storageutil
"k8s.io/kubernetes/pkg/apis/storage/util"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
...
@@ -120,6 +121,7 @@ func describerMap(c clientset.Interface) map[unversioned.GroupKind]Describer {
...
@@ -120,6 +121,7 @@ func describerMap(c clientset.Interface) map[unversioned.GroupKind]Describer {
apps
.
Kind
(
"StatefulSet"
)
:
&
StatefulSetDescriber
{
c
},
apps
.
Kind
(
"StatefulSet"
)
:
&
StatefulSetDescriber
{
c
},
certificates
.
Kind
(
"CertificateSigningRequest"
)
:
&
CertificateSigningRequestDescriber
{
c
},
certificates
.
Kind
(
"CertificateSigningRequest"
)
:
&
CertificateSigningRequestDescriber
{
c
},
storage
.
Kind
(
"StorageClass"
)
:
&
StorageClassDescriber
{
c
},
storage
.
Kind
(
"StorageClass"
)
:
&
StorageClassDescriber
{
c
},
policy
.
Kind
(
"PodDisruptionBudget"
)
:
&
PodDisruptionBudgetDescriber
{
c
},
}
}
return
m
return
m
...
@@ -2395,6 +2397,40 @@ func (s *StorageClassDescriber) Describe(namespace, name string, describerSettin
...
@@ -2395,6 +2397,40 @@ func (s *StorageClassDescriber) Describe(namespace, name string, describerSettin
})
})
}
}
type
PodDisruptionBudgetDescriber
struct
{
clientset
.
Interface
}
func
(
p
*
PodDisruptionBudgetDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
DescriberSettings
)
(
string
,
error
)
{
pdb
,
err
:=
p
.
Policy
()
.
PodDisruptionBudgets
(
namespace
)
.
Get
(
name
)
if
err
!=
nil
{
return
""
,
err
}
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
pdb
.
Name
)
fmt
.
Fprintf
(
out
,
"Min available:
\t
%s
\n
"
,
pdb
.
Spec
.
MinAvailable
.
String
())
if
pdb
.
Spec
.
Selector
!=
nil
{
fmt
.
Fprintf
(
out
,
"Selector:
\t
%s
\n
"
,
unversioned
.
FormatLabelSelector
(
pdb
.
Spec
.
Selector
))
}
else
{
fmt
.
Fprintf
(
out
,
"Selector:
\t
<unset>
\n
"
)
}
fmt
.
Fprintf
(
out
,
"Status:
\n
"
)
fmt
.
Fprintf
(
out
,
" Current:
\t
%d
\n
"
,
pdb
.
Status
.
CurrentHealthy
)
fmt
.
Fprintf
(
out
,
" Desired:
\t
%d
\n
"
,
pdb
.
Status
.
DesiredHealthy
)
fmt
.
Fprintf
(
out
,
" Total:
\t
%d
\n
"
,
pdb
.
Status
.
ExpectedPods
)
if
describerSettings
.
ShowEvents
{
events
,
err
:=
p
.
Core
()
.
Events
(
namespace
)
.
Search
(
pdb
)
if
err
!=
nil
{
return
err
}
if
events
!=
nil
{
DescribeEvents
(
events
,
out
)
}
}
return
nil
})
}
// newErrNoDescriber creates a new ErrNoDescriber with the names of the provided types.
// newErrNoDescriber creates a new ErrNoDescriber with the names of the provided types.
func
newErrNoDescriber
(
types
...
reflect
.
Type
)
error
{
func
newErrNoDescriber
(
types
...
reflect
.
Type
)
error
{
names
:=
make
([]
string
,
0
,
len
(
types
))
names
:=
make
([]
string
,
0
,
len
(
types
))
...
...
pkg/kubectl/resource_printer.go
View file @
5f8e76b4
...
@@ -40,6 +40,7 @@ import (
...
@@ -40,6 +40,7 @@ import (
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/certificates"
"k8s.io/kubernetes/pkg/apis/certificates"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/policy"
"k8s.io/kubernetes/pkg/apis/rbac"
"k8s.io/kubernetes/pkg/apis/rbac"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/apis/storage"
storageutil
"k8s.io/kubernetes/pkg/apis/storage/util"
storageutil
"k8s.io/kubernetes/pkg/apis/storage/util"
...
@@ -474,6 +475,7 @@ func (h *HumanReadablePrinter) AfterPrint(output io.Writer, res string) error {
...
@@ -474,6 +475,7 @@ func (h *HumanReadablePrinter) AfterPrint(output io.Writer, res string) error {
var
(
var
(
podColumns
=
[]
string
{
"NAME"
,
"READY"
,
"STATUS"
,
"RESTARTS"
,
"AGE"
}
podColumns
=
[]
string
{
"NAME"
,
"READY"
,
"STATUS"
,
"RESTARTS"
,
"AGE"
}
podTemplateColumns
=
[]
string
{
"TEMPLATE"
,
"CONTAINER(S)"
,
"IMAGE(S)"
,
"PODLABELS"
}
podTemplateColumns
=
[]
string
{
"TEMPLATE"
,
"CONTAINER(S)"
,
"IMAGE(S)"
,
"PODLABELS"
}
podDisruptionBudgetColumns
=
[]
string
{
"NAME"
,
"MIN-AVAILABLE"
,
"SELECTOR"
,
"DISRUPTIONS"
}
replicationControllerColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"CURRENT"
,
"READY"
,
"AGE"
}
replicationControllerColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"CURRENT"
,
"READY"
,
"AGE"
}
replicaSetColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"CURRENT"
,
"READY"
,
"AGE"
}
replicaSetColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"CURRENT"
,
"READY"
,
"AGE"
}
jobColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"SUCCESSFUL"
,
"AGE"
}
jobColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"SUCCESSFUL"
,
"AGE"
}
...
@@ -536,6 +538,8 @@ func (h *HumanReadablePrinter) addDefaultHandlers() {
...
@@ -536,6 +538,8 @@ func (h *HumanReadablePrinter) addDefaultHandlers() {
h
.
Handler
(
podColumns
,
h
.
printPod
)
h
.
Handler
(
podColumns
,
h
.
printPod
)
h
.
Handler
(
podTemplateColumns
,
printPodTemplate
)
h
.
Handler
(
podTemplateColumns
,
printPodTemplate
)
h
.
Handler
(
podTemplateColumns
,
printPodTemplateList
)
h
.
Handler
(
podTemplateColumns
,
printPodTemplateList
)
h
.
Handler
(
podDisruptionBudgetColumns
,
printPodDisruptionBudget
)
h
.
Handler
(
podDisruptionBudgetColumns
,
printPodDisruptionBudgetList
)
h
.
Handler
(
replicationControllerColumns
,
printReplicationController
)
h
.
Handler
(
replicationControllerColumns
,
printReplicationController
)
h
.
Handler
(
replicationControllerColumns
,
printReplicationControllerList
)
h
.
Handler
(
replicationControllerColumns
,
printReplicationControllerList
)
h
.
Handler
(
replicaSetColumns
,
printReplicaSet
)
h
.
Handler
(
replicaSetColumns
,
printReplicaSet
)
...
@@ -828,6 +832,46 @@ func printPodTemplateList(podList *api.PodTemplateList, w io.Writer, options Pri
...
@@ -828,6 +832,46 @@ func printPodTemplateList(podList *api.PodTemplateList, w io.Writer, options Pri
return
nil
return
nil
}
}
func
printPodDisruptionBudget
(
pdb
*
policy
.
PodDisruptionBudget
,
w
io
.
Writer
,
options
PrintOptions
)
error
{
// name, minavailable, selector
name
:=
formatResourceName
(
options
.
Kind
,
pdb
.
Name
,
options
.
WithKind
)
namespace
:=
pdb
.
Namespace
if
options
.
WithNamespace
{
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
"
,
namespace
);
err
!=
nil
{
return
err
}
}
selector
:=
"<none>"
if
pdb
.
Spec
.
Selector
!=
nil
{
selector
=
unversioned
.
FormatLabelSelector
(
pdb
.
Spec
.
Selector
)
}
disruptions
:=
"Disallowed"
if
pdb
.
Status
.
PodDisruptionAllowed
{
disruptions
=
"Allowed"
}
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s
\n
"
,
name
,
pdb
.
Spec
.
MinAvailable
.
String
(),
selector
,
disruptions
,
);
err
!=
nil
{
return
err
}
return
nil
}
func
printPodDisruptionBudgetList
(
pdbList
*
policy
.
PodDisruptionBudgetList
,
w
io
.
Writer
,
options
PrintOptions
)
error
{
for
_
,
pdb
:=
range
pdbList
.
Items
{
if
err
:=
printPodDisruptionBudget
(
&
pdb
,
w
,
options
);
err
!=
nil
{
return
err
}
}
return
nil
}
// TODO(AdoHe): try to put wide output in a single method
// TODO(AdoHe): try to put wide output in a single method
func
printReplicationController
(
controller
*
api
.
ReplicationController
,
w
io
.
Writer
,
options
PrintOptions
)
error
{
func
printReplicationController
(
controller
*
api
.
ReplicationController
,
w
io
.
Writer
,
options
PrintOptions
)
error
{
name
:=
formatResourceName
(
options
.
Kind
,
controller
.
Name
,
options
.
WithKind
)
name
:=
formatResourceName
(
options
.
Kind
,
controller
.
Name
,
options
.
WithKind
)
...
...
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