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
9cee1456
Commit
9cee1456
authored
Nov 09, 2016
by
Marcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Describe and get support for the updated api + tests
parent
5f8e76b4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
13 deletions
+64
-13
describe.go
pkg/kubectl/describe.go
+1
-0
describe_test.go
pkg/kubectl/describe_test.go
+26
-0
resource_printer.go
pkg/kubectl/resource_printer.go
+4
-13
resource_printer_test.go
pkg/kubectl/resource_printer_test.go
+33
-0
No files found.
pkg/kubectl/describe.go
View file @
9cee1456
...
...
@@ -2415,6 +2415,7 @@ func (p *PodDisruptionBudgetDescriber) Describe(namespace, name string, describe
fmt
.
Fprintf
(
out
,
"Selector:
\t
<unset>
\n
"
)
}
fmt
.
Fprintf
(
out
,
"Status:
\n
"
)
fmt
.
Fprintf
(
out
,
" Allowed disruptions:
\t
%d
\n
"
,
pdb
.
Status
.
PodDisruptionsAllowed
)
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
)
...
...
pkg/kubectl/describe_test.go
View file @
9cee1456
...
...
@@ -31,9 +31,11 @@ import (
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/policy"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/util/intstr"
)
type
describeClient
struct
{
...
...
@@ -694,6 +696,30 @@ func TestDescribeStorageClass(t *testing.T) {
}
}
func
TestDescribePodDisruptionBudget
(
t
*
testing
.
T
)
{
f
:=
fake
.
NewSimpleClientset
(
&
policy
.
PodDisruptionBudget
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
"ns1"
,
Name
:
"pdb1"
,
CreationTimestamp
:
unversioned
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
},
Spec
:
policy
.
PodDisruptionBudgetSpec
{
MinAvailable
:
intstr
.
FromInt
(
22
),
},
Status
:
policy
.
PodDisruptionBudgetStatus
{
PodDisruptionsAllowed
:
5
,
},
})
s
:=
PodDisruptionBudgetDescriber
{
f
}
out
,
err
:=
s
.
Describe
(
"ns1"
,
"pdb1"
,
DescriberSettings
{
ShowEvents
:
true
})
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
if
!
strings
.
Contains
(
out
,
"pdb1"
)
{
t
.
Errorf
(
"unexpected out: %s"
,
out
)
}
}
func
TestDescribeEvents
(
t
*
testing
.
T
)
{
events
:=
&
api
.
EventList
{
...
...
pkg/kubectl/resource_printer.go
View file @
9cee1456
...
...
@@ -475,7 +475,7 @@ func (h *HumanReadablePrinter) AfterPrint(output io.Writer, res string) error {
var
(
podColumns
=
[]
string
{
"NAME"
,
"READY"
,
"STATUS"
,
"RESTARTS"
,
"AGE"
}
podTemplateColumns
=
[]
string
{
"TEMPLATE"
,
"CONTAINER(S)"
,
"IMAGE(S)"
,
"PODLABELS"
}
podDisruptionBudgetColumns
=
[]
string
{
"NAME"
,
"MIN-AVAILABLE"
,
"
SELECTOR"
,
"DISRUPTIONS
"
}
podDisruptionBudgetColumns
=
[]
string
{
"NAME"
,
"MIN-AVAILABLE"
,
"
ALLOWED-DISRUPTIONS"
,
"AGE
"
}
replicationControllerColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"CURRENT"
,
"READY"
,
"AGE"
}
replicaSetColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"CURRENT"
,
"READY"
,
"AGE"
}
jobColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"SUCCESSFUL"
,
"AGE"
}
...
...
@@ -842,20 +842,11 @@ func printPodDisruptionBudget(pdb *policy.PodDisruptionBudget, w io.Writer, opti
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
"
,
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%d
\t
%s
\n
"
,
name
,
pdb
.
Spec
.
MinAvailable
.
String
(),
selector
,
disruptions
,
pdb
.
Status
.
PodDisruptionsAllowed
,
translateTimestamp
(
pdb
.
CreationTimestamp
)
,
);
err
!=
nil
{
return
err
}
...
...
pkg/kubectl/resource_printer_test.go
View file @
9cee1456
...
...
@@ -33,6 +33,7 @@ import (
"k8s.io/kubernetes/pkg/apimachinery/registered"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/policy"
kubectltesting
"k8s.io/kubernetes/pkg/kubectl/testing"
"k8s.io/kubernetes/pkg/runtime"
yamlserializer
"k8s.io/kubernetes/pkg/runtime/serializer/yaml"
...
...
@@ -1622,3 +1623,35 @@ func TestPrintService(t *testing.T) {
buf
.
Reset
()
}
}
func
TestPrintPodDisruptionBudget
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
pdb
policy
.
PodDisruptionBudget
expect
string
}{
{
policy
.
PodDisruptionBudget
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
"ns1"
,
Name
:
"pdb1"
,
CreationTimestamp
:
unversioned
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
},
Spec
:
policy
.
PodDisruptionBudgetSpec
{
MinAvailable
:
intstr
.
FromInt
(
22
),
},
Status
:
policy
.
PodDisruptionBudgetStatus
{
PodDisruptionsAllowed
:
5
,
},
},
"pdb1
\t
22
\t
5
\t
0s
\n
"
,
}}
buf
:=
bytes
.
NewBuffer
([]
byte
{})
for
_
,
test
:=
range
tests
{
printPodDisruptionBudget
(
&
test
.
pdb
,
buf
,
PrintOptions
{
false
,
false
,
false
,
false
,
true
,
false
,
false
,
""
,
[]
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