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
078f9566
Commit
078f9566
authored
May 15, 2017
by
Anirudh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDB MaxUnavailable: kubectl changes
parent
ce48d4fb
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
190 additions
and
19 deletions
+190
-19
test-cmd-util.sh
hack/make-rules/test-cmd-util.sh
+18
-4
known-flags.txt
hack/verify-flags/known-flags.txt
+1
-0
create_pdb.go
pkg/kubectl/cmd/create_pdb.go
+11
-2
factory_client_access.go
pkg/kubectl/cmd/util/factory_client_access.go
+4
-0
pdb.go
pkg/kubectl/pdb.go
+124
-5
describe.go
pkg/printers/internalversion/describe.go
+7
-1
describe_test.go
pkg/printers/internalversion/describe_test.go
+2
-1
printers.go
pkg/printers/internalversion/printers.go
+20
-4
printers_test.go
pkg/printers/internalversion/printers_test.go
+3
-2
No files found.
hack/make-rules/test-cmd-util.sh
View file @
078f9566
...
@@ -431,16 +431,29 @@ run_pod_tests() {
...
@@ -431,16 +431,29 @@ run_pod_tests() {
# Post-condition: configmap exists and has expected values
# Post-condition: configmap exists and has expected values
kube::test::get_object_assert
'configmap/test-configmap --namespace=test-kubectl-describe-pod'
"{{
$id_field
}}"
'test-configmap'
kube::test::get_object_assert
'configmap/test-configmap --namespace=test-kubectl-describe-pod'
"{{
$id_field
}}"
'test-configmap'
### Create a pod disruption budget
### Create a pod disruption budget
with minAvailable
# Command
# Command
kubectl create pdb test-pdb
--selector
=
app
=
rails
--min-available
=
2
--namespace
=
test-kubectl-describe-pod
kubectl create pdb test-pdb
-1
--selector
=
app
=
rails
--min-available
=
2
--namespace
=
test-kubectl-describe-pod
# Post-condition: pdb exists and has expected values
# Post-condition: pdb exists and has expected values
kube::test::get_object_assert
'pdb/test-pdb --namespace=test-kubectl-describe-pod'
"{{
$pdb_min_available
}}"
'2'
kube::test::get_object_assert
'pdb/test-pdb
-1
--namespace=test-kubectl-describe-pod'
"{{
$pdb_min_available
}}"
'2'
# Command
# Command
kubectl create pdb test-pdb-2
--selector
=
app
=
rails
--min-available
=
50%
--namespace
=
test-kubectl-describe-pod
kubectl create pdb test-pdb-2
--selector
=
app
=
rails
--min-available
=
50%
--namespace
=
test-kubectl-describe-pod
# Post-condition: pdb exists and has expected values
# Post-condition: pdb exists and has expected values
kube::test::get_object_assert
'pdb/test-pdb-2 --namespace=test-kubectl-describe-pod'
"{{
$pdb_min_available
}}"
'50%'
kube::test::get_object_assert
'pdb/test-pdb-2 --namespace=test-kubectl-describe-pod'
"{{
$pdb_min_available
}}"
'50%'
### Create a pod disruption budget with maxUnavailable
# Command
kubectl create pdb test-pdb-3
--selector
=
app
=
rails
--max-unavailable
=
2
--namespace
=
test-kubectl-describe-pod
# Post-condition: pdb exists and has expected values
kube::test::get_object_assert
'pdb/test-pdb-3 --namespace=test-kubectl-describe-pod'
"{{
$pdb_max_unavailable
}}"
'2'
# Command
kubectl create pdb test-pdb-4
--selector
=
app
=
rails
--max-unavailable
=
50%
--namespace
=
test-kubectl-describe-pod
# Post-condition: pdb exists and has expected values
kube::test::get_object_assert
'pdb/test-pdb-4 --namespace=test-kubectl-describe-pod'
"{{
$pdb_max_unavailable
}}"
'50%'
### Fail creating a pod disruption budget if both maxUnavailable and minAvailable specified
!
kubectl create pdb test-pdb
--selector
=
app
=
rails
--min-available
=
2
--max-unavailable
=
3
--namespace
=
test-kubectl-describe-pod
# Create a pod that consumes secret, configmap, and downward API keys as envs
# Create a pod that consumes secret, configmap, and downward API keys as envs
kube::test::get_object_assert
'pods --namespace=test-kubectl-describe-pod'
"{{range.items}}{{
$id_field
}}:{{end}}"
''
kube::test::get_object_assert
'pods --namespace=test-kubectl-describe-pod'
"{{range.items}}{{
$id_field
}}:{{end}}"
''
kubectl create
-f
hack/testdata/pod-with-api-env.yaml
--namespace
=
test-kubectl-describe-pod
kubectl create
-f
hack/testdata/pod-with-api-env.yaml
--namespace
=
test-kubectl-describe-pod
...
@@ -453,7 +466,7 @@ run_pod_tests() {
...
@@ -453,7 +466,7 @@ run_pod_tests() {
kubectl delete pod env-test-pod
--namespace
=
test-kubectl-describe-pod
kubectl delete pod env-test-pod
--namespace
=
test-kubectl-describe-pod
kubectl delete secret test-secret
--namespace
=
test-kubectl-describe-pod
kubectl delete secret test-secret
--namespace
=
test-kubectl-describe-pod
kubectl delete configmap test-configmap
--namespace
=
test-kubectl-describe-pod
kubectl delete configmap test-configmap
--namespace
=
test-kubectl-describe-pod
kubectl delete pdb/test-pdb
pdb/test-pdb-2
--namespace
=
test-kubectl-describe-pod
kubectl delete pdb/test-pdb
-1 pdb/test-pdb-2 pdb/test-pdb-3 pdb/test-pdb-4
--namespace
=
test-kubectl-describe-pod
kubectl delete namespace test-kubectl-describe-pod
kubectl delete namespace test-kubectl-describe-pod
### Create two PODs
### Create two PODs
...
@@ -2990,6 +3003,7 @@ runTests() {
...
@@ -2990,6 +3003,7 @@ runTests() {
deployment_second_image_field
=
"(index .spec.template.spec.containers 1).image"
deployment_second_image_field
=
"(index .spec.template.spec.containers 1).image"
change_cause_annotation
=
'.*kubernetes.io/change-cause.*'
change_cause_annotation
=
'.*kubernetes.io/change-cause.*'
pdb_min_available
=
".spec.minAvailable"
pdb_min_available
=
".spec.minAvailable"
pdb_max_unavailable
=
".spec.maxUnavailable"
template_generation_field
=
".spec.templateGeneration"
template_generation_field
=
".spec.templateGeneration"
# Make sure "default" namespace exists.
# Make sure "default" namespace exists.
...
...
hack/verify-flags/known-flags.txt
View file @
078f9566
...
@@ -457,6 +457,7 @@ max-outgoing-burst
...
@@ -457,6 +457,7 @@ max-outgoing-burst
max-outgoing-qps
max-outgoing-qps
max-pods
max-pods
max-requests-inflight
max-requests-inflight
max-unavailable
mesos-authentication-principal
mesos-authentication-principal
mesos-authentication-provider
mesos-authentication-provider
mesos-authentication-secret-file
mesos-authentication-secret-file
...
...
pkg/kubectl/cmd/create_pdb.go
View file @
078f9566
...
@@ -59,8 +59,10 @@ func NewCmdCreatePodDisruptionBudget(f cmdutil.Factory, cmdOut io.Writer) *cobra
...
@@ -59,8 +59,10 @@ func NewCmdCreatePodDisruptionBudget(f cmdutil.Factory, cmdOut io.Writer) *cobra
cmdutil
.
AddApplyAnnotationFlags
(
cmd
)
cmdutil
.
AddApplyAnnotationFlags
(
cmd
)
cmdutil
.
AddValidateFlags
(
cmd
)
cmdutil
.
AddValidateFlags
(
cmd
)
cmdutil
.
AddPrinterFlags
(
cmd
)
cmdutil
.
AddPrinterFlags
(
cmd
)
cmdutil
.
AddGeneratorFlags
(
cmd
,
cmdutil
.
PodDisruptionBudgetV1GeneratorName
)
cmdutil
.
AddGeneratorFlags
(
cmd
,
cmdutil
.
PodDisruptionBudgetV2GeneratorName
)
cmd
.
Flags
()
.
String
(
"min-available"
,
"1"
,
i18n
.
T
(
"The minimum number or percentage of available pods this budget requires."
))
cmd
.
Flags
()
.
String
(
"min-available"
,
""
,
i18n
.
T
(
"The minimum number or percentage of available pods this budget requires."
))
cmd
.
Flags
()
.
String
(
"max-unavailable"
,
""
,
i18n
.
T
(
"The maximum number or percentage of unavailable pods this budget requires."
))
cmd
.
Flags
()
.
String
(
"selector"
,
""
,
i18n
.
T
(
"A label selector to use for this budget. Only equality-based selector requirements are supported."
))
cmd
.
Flags
()
.
String
(
"selector"
,
""
,
i18n
.
T
(
"A label selector to use for this budget. Only equality-based selector requirements are supported."
))
return
cmd
return
cmd
}
}
...
@@ -79,6 +81,13 @@ func CreatePodDisruptionBudget(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.C
...
@@ -79,6 +81,13 @@ func CreatePodDisruptionBudget(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.C
MinAvailable
:
cmdutil
.
GetFlagString
(
cmd
,
"min-available"
),
MinAvailable
:
cmdutil
.
GetFlagString
(
cmd
,
"min-available"
),
Selector
:
cmdutil
.
GetFlagString
(
cmd
,
"selector"
),
Selector
:
cmdutil
.
GetFlagString
(
cmd
,
"selector"
),
}
}
case
cmdutil
.
PodDisruptionBudgetV2GeneratorName
:
generator
=
&
kubectl
.
PodDisruptionBudgetV2Generator
{
Name
:
name
,
MinAvailable
:
cmdutil
.
GetFlagString
(
cmd
,
"min-available"
),
MaxUnavailable
:
cmdutil
.
GetFlagString
(
cmd
,
"max-unavailable"
),
Selector
:
cmdutil
.
GetFlagString
(
cmd
,
"selector"
),
}
default
:
default
:
return
cmdutil
.
UsageError
(
cmd
,
fmt
.
Sprintf
(
"Generator: %s not supported."
,
generatorName
))
return
cmdutil
.
UsageError
(
cmd
,
fmt
.
Sprintf
(
"Generator: %s not supported."
,
generatorName
))
}
}
...
...
pkg/kubectl/cmd/util/factory_client_access.go
View file @
078f9566
...
@@ -455,6 +455,9 @@ func (f *ring0Factory) DefaultNamespace() (string, bool, error) {
...
@@ -455,6 +455,9 @@ func (f *ring0Factory) DefaultNamespace() (string, bool, error) {
}
}
const
(
const
(
// TODO(sig-cli): Enforce consistent naming for generators here.
// See discussion in https://github.com/kubernetes/kubernetes/issues/46237
// before you add any more.
RunV1GeneratorName
=
"run/v1"
RunV1GeneratorName
=
"run/v1"
RunPodV1GeneratorName
=
"run-pod/v1"
RunPodV1GeneratorName
=
"run-pod/v1"
ServiceV1GeneratorName
=
"service/v1"
ServiceV1GeneratorName
=
"service/v1"
...
@@ -482,6 +485,7 @@ const (
...
@@ -482,6 +485,7 @@ const (
RoleBindingV1GeneratorName
=
"rolebinding.rbac.authorization.k8s.io/v1alpha1"
RoleBindingV1GeneratorName
=
"rolebinding.rbac.authorization.k8s.io/v1alpha1"
ClusterV1Beta1GeneratorName
=
"cluster/v1beta1"
ClusterV1Beta1GeneratorName
=
"cluster/v1beta1"
PodDisruptionBudgetV1GeneratorName
=
"poddisruptionbudget/v1beta1"
PodDisruptionBudgetV1GeneratorName
=
"poddisruptionbudget/v1beta1"
PodDisruptionBudgetV2GeneratorName
=
"poddisruptionbudget/v1beta1/v2"
)
)
// DefaultGenerators returns the set of default generators for use in Factory instances
// DefaultGenerators returns the set of default generators for use in Factory instances
...
...
pkg/kubectl/pdb.go
View file @
078f9566
...
@@ -18,6 +18,7 @@ package kubectl
...
@@ -18,6 +18,7 @@ package kubectl
import
(
import
(
"fmt"
"fmt"
"os"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
...
@@ -38,7 +39,7 @@ var _ StructuredGenerator = &PodDisruptionBudgetV1Generator{}
...
@@ -38,7 +39,7 @@ var _ StructuredGenerator = &PodDisruptionBudgetV1Generator{}
func
(
PodDisruptionBudgetV1Generator
)
ParamNames
()
[]
GeneratorParam
{
func
(
PodDisruptionBudgetV1Generator
)
ParamNames
()
[]
GeneratorParam
{
return
[]
GeneratorParam
{
return
[]
GeneratorParam
{
{
"name"
,
true
},
{
"name"
,
true
},
{
"mi
m
-available"
,
true
},
{
"mi
n
-available"
,
true
},
{
"selector"
,
true
},
{
"selector"
,
true
},
}
}
}
}
...
@@ -52,11 +53,11 @@ func (s PodDisruptionBudgetV1Generator) Generate(params map[string]interface{})
...
@@ -52,11 +53,11 @@ func (s PodDisruptionBudgetV1Generator) Generate(params map[string]interface{})
if
!
isString
{
if
!
isString
{
return
nil
,
fmt
.
Errorf
(
"expected string, saw %v for 'name'"
,
name
)
return
nil
,
fmt
.
Errorf
(
"expected string, saw %v for 'name'"
,
name
)
}
}
minAvailable
,
isString
:=
params
[
"mi
m
-available"
]
.
(
string
)
minAvailable
,
isString
:=
params
[
"mi
n
-available"
]
.
(
string
)
if
!
isString
{
if
!
isString
{
return
nil
,
fmt
.
Errorf
(
"expected string, found %v"
,
minAvailable
)
return
nil
,
fmt
.
Errorf
(
"expected string, found %v"
,
minAvailable
)
}
}
selector
,
isString
:=
params
[
"selecor"
]
.
(
string
)
selector
,
isString
:=
params
[
"selec
t
or"
]
.
(
string
)
if
!
isString
{
if
!
isString
{
return
nil
,
fmt
.
Errorf
(
"expected string, found %v"
,
selector
)
return
nil
,
fmt
.
Errorf
(
"expected string, found %v"
,
selector
)
}
}
...
@@ -66,6 +67,11 @@ func (s PodDisruptionBudgetV1Generator) Generate(params map[string]interface{})
...
@@ -66,6 +67,11 @@ func (s PodDisruptionBudgetV1Generator) Generate(params map[string]interface{})
// StructuredGenerate outputs a pod disruption budget object using the configured fields.
// StructuredGenerate outputs a pod disruption budget object using the configured fields.
func
(
s
*
PodDisruptionBudgetV1Generator
)
StructuredGenerate
()
(
runtime
.
Object
,
error
)
{
func
(
s
*
PodDisruptionBudgetV1Generator
)
StructuredGenerate
()
(
runtime
.
Object
,
error
)
{
if
len
(
s
.
MinAvailable
)
==
0
{
// defaulting behavior seen in Kubernetes 1.6 and below.
s
.
MinAvailable
=
"1"
}
if
err
:=
s
.
validate
();
err
!=
nil
{
if
err
:=
s
.
validate
();
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -75,12 +81,13 @@ func (s *PodDisruptionBudgetV1Generator) StructuredGenerate() (runtime.Object, e
...
@@ -75,12 +81,13 @@ func (s *PodDisruptionBudgetV1Generator) StructuredGenerate() (runtime.Object, e
return
nil
,
err
return
nil
,
err
}
}
minAvailable
:=
intstr
.
Parse
(
s
.
MinAvailable
)
return
&
policy
.
PodDisruptionBudget
{
return
&
policy
.
PodDisruptionBudget
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
s
.
Name
,
Name
:
s
.
Name
,
},
},
Spec
:
policy
.
PodDisruptionBudgetSpec
{
Spec
:
policy
.
PodDisruptionBudgetSpec
{
MinAvailable
:
intstr
.
Parse
(
s
.
MinAvailable
)
,
MinAvailable
:
&
minAvailable
,
Selector
:
selector
,
Selector
:
selector
,
},
},
},
nil
},
nil
...
@@ -95,7 +102,119 @@ func (s *PodDisruptionBudgetV1Generator) validate() error {
...
@@ -95,7 +102,119 @@ func (s *PodDisruptionBudgetV1Generator) validate() error {
return
fmt
.
Errorf
(
"a selector must be specified"
)
return
fmt
.
Errorf
(
"a selector must be specified"
)
}
}
if
len
(
s
.
MinAvailable
)
==
0
{
if
len
(
s
.
MinAvailable
)
==
0
{
return
fmt
.
Errorf
(
"the minimim number of available pods required must be specified"
)
return
fmt
.
Errorf
(
"the minimum number of available pods required must be specified"
)
}
return
nil
}
// PodDisruptionBudgetV2Generator supports stable generation of a pod disruption budget.
type
PodDisruptionBudgetV2Generator
struct
{
Name
string
MinAvailable
string
MaxUnavailable
string
Selector
string
}
// Ensure it supports the generator pattern that uses parameters specified during construction.
var
_
StructuredGenerator
=
&
PodDisruptionBudgetV2Generator
{}
func
(
PodDisruptionBudgetV2Generator
)
ParamNames
()
[]
GeneratorParam
{
return
[]
GeneratorParam
{
{
"name"
,
true
},
{
"min-available"
,
false
},
{
"max-unavailable"
,
false
},
{
"selector"
,
false
},
}
}
func
(
s
PodDisruptionBudgetV2Generator
)
Generate
(
params
map
[
string
]
interface
{})
(
runtime
.
Object
,
error
)
{
err
:=
ValidateParams
(
s
.
ParamNames
(),
params
)
if
err
!=
nil
{
return
nil
,
err
}
name
,
isString
:=
params
[
"name"
]
.
(
string
)
if
!
isString
{
return
nil
,
fmt
.
Errorf
(
"expected string, saw %v for 'name'"
,
name
)
}
minAvailable
,
isString
:=
params
[
"min-available"
]
.
(
string
)
if
!
isString
{
return
nil
,
fmt
.
Errorf
(
"expected string, found %v"
,
minAvailable
)
}
maxUnavailable
,
isString
:=
params
[
"max-available"
]
.
(
string
)
if
!
isString
{
return
nil
,
fmt
.
Errorf
(
"expected string, found %v"
,
maxUnavailable
)
}
selector
,
isString
:=
params
[
"selector"
]
.
(
string
)
if
!
isString
{
return
nil
,
fmt
.
Errorf
(
"expected string, found %v"
,
selector
)
}
delegate
:=
&
PodDisruptionBudgetV2Generator
{
Name
:
name
,
MinAvailable
:
minAvailable
,
MaxUnavailable
:
maxUnavailable
,
Selector
:
selector
}
return
delegate
.
StructuredGenerate
()
}
// StructuredGenerate outputs a pod disruption budget object using the configured fields.
func
(
s
*
PodDisruptionBudgetV2Generator
)
StructuredGenerate
()
(
runtime
.
Object
,
error
)
{
if
err
:=
s
.
validate
();
err
!=
nil
{
return
nil
,
err
}
selector
,
err
:=
metav1
.
ParseToLabelSelector
(
s
.
Selector
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
s
.
MaxUnavailable
)
==
0
&&
len
(
s
.
MinAvailable
)
==
0
{
s
.
MinAvailable
=
"1"
// This behavior is intended for backward compatibility.
// TODO: remove in Kubernetes 1.8
fmt
.
Fprintln
(
os
.
Stderr
,
"Deprecated behavior in kubectl create pdb: Defaulting min-available to 1. "
+
"Kubernetes 1.8 will remove this default, and one of min-available/max-available must be specified. "
)
}
if
len
(
s
.
MaxUnavailable
)
>
0
{
maxUnavailable
:=
intstr
.
Parse
(
s
.
MaxUnavailable
)
return
&
policy
.
PodDisruptionBudget
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
s
.
Name
,
},
Spec
:
policy
.
PodDisruptionBudgetSpec
{
MaxUnavailable
:
&
maxUnavailable
,
Selector
:
selector
,
},
},
nil
}
if
len
(
s
.
MinAvailable
)
>
0
{
minAvailable
:=
intstr
.
Parse
(
s
.
MinAvailable
)
return
&
policy
.
PodDisruptionBudget
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
s
.
Name
,
},
Spec
:
policy
.
PodDisruptionBudgetSpec
{
MinAvailable
:
&
minAvailable
,
Selector
:
selector
,
},
},
nil
}
return
nil
,
err
}
// validate validates required fields are set to support structured generation.
func
(
s
*
PodDisruptionBudgetV2Generator
)
validate
()
error
{
if
len
(
s
.
Name
)
==
0
{
return
fmt
.
Errorf
(
"name must be specified"
)
}
if
len
(
s
.
Selector
)
==
0
{
return
fmt
.
Errorf
(
"a selector must be specified"
)
}
if
len
(
s
.
MaxUnavailable
)
>
0
&&
len
(
s
.
MinAvailable
)
>
0
{
return
fmt
.
Errorf
(
"exactly one of min-available and max-available must be specified"
)
}
}
return
nil
return
nil
}
}
pkg/printers/internalversion/describe.go
View file @
078f9566
...
@@ -2881,7 +2881,13 @@ func describePodDisruptionBudget(pdb *policy.PodDisruptionBudget, events *api.Ev
...
@@ -2881,7 +2881,13 @@ func describePodDisruptionBudget(pdb *policy.PodDisruptionBudget, events *api.Ev
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
w
:=
NewPrefixWriter
(
out
)
w
:=
NewPrefixWriter
(
out
)
w
.
Write
(
LEVEL_0
,
"Name:
\t
%s
\n
"
,
pdb
.
Name
)
w
.
Write
(
LEVEL_0
,
"Name:
\t
%s
\n
"
,
pdb
.
Name
)
w
.
Write
(
LEVEL_0
,
"Min available:
\t
%s
\n
"
,
pdb
.
Spec
.
MinAvailable
.
String
())
if
pdb
.
Spec
.
MinAvailable
!=
nil
{
w
.
Write
(
LEVEL_0
,
"Min available:
\t
%s
\n
"
,
pdb
.
Spec
.
MinAvailable
.
String
())
}
else
if
pdb
.
Spec
.
MaxUnavailable
!=
nil
{
w
.
Write
(
LEVEL_0
,
"Max unavailable:
\t
%s
\n
"
,
pdb
.
Spec
.
MaxUnavailable
.
String
())
}
if
pdb
.
Spec
.
Selector
!=
nil
{
if
pdb
.
Spec
.
Selector
!=
nil
{
w
.
Write
(
LEVEL_0
,
"Selector:
\t
%s
\n
"
,
metav1
.
FormatLabelSelector
(
pdb
.
Spec
.
Selector
))
w
.
Write
(
LEVEL_0
,
"Selector:
\t
%s
\n
"
,
metav1
.
FormatLabelSelector
(
pdb
.
Spec
.
Selector
))
}
else
{
}
else
{
...
...
pkg/printers/internalversion/describe_test.go
View file @
078f9566
...
@@ -774,6 +774,7 @@ func TestDescribeStorageClass(t *testing.T) {
...
@@ -774,6 +774,7 @@ func TestDescribeStorageClass(t *testing.T) {
}
}
func
TestDescribePodDisruptionBudget
(
t
*
testing
.
T
)
{
func
TestDescribePodDisruptionBudget
(
t
*
testing
.
T
)
{
minAvailable
:=
intstr
.
FromInt
(
22
)
f
:=
fake
.
NewSimpleClientset
(
&
policy
.
PodDisruptionBudget
{
f
:=
fake
.
NewSimpleClientset
(
&
policy
.
PodDisruptionBudget
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Namespace
:
"ns1"
,
Namespace
:
"ns1"
,
...
@@ -781,7 +782,7 @@ func TestDescribePodDisruptionBudget(t *testing.T) {
...
@@ -781,7 +782,7 @@ func TestDescribePodDisruptionBudget(t *testing.T) {
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
},
},
Spec
:
policy
.
PodDisruptionBudgetSpec
{
Spec
:
policy
.
PodDisruptionBudgetSpec
{
MinAvailable
:
intstr
.
FromInt
(
22
)
,
MinAvailable
:
&
minAvailable
,
},
},
Status
:
policy
.
PodDisruptionBudgetStatus
{
Status
:
policy
.
PodDisruptionBudgetStatus
{
PodDisruptionsAllowed
:
5
,
PodDisruptionsAllowed
:
5
,
...
...
pkg/printers/internalversion/printers.go
View file @
078f9566
...
@@ -55,7 +55,7 @@ var (
...
@@ -55,7 +55,7 @@ var (
podColumns
=
[]
string
{
"NAME"
,
"READY"
,
"STATUS"
,
"RESTARTS"
,
"AGE"
}
podColumns
=
[]
string
{
"NAME"
,
"READY"
,
"STATUS"
,
"RESTARTS"
,
"AGE"
}
podWideColumns
=
[]
string
{
"IP"
,
"NODE"
}
podWideColumns
=
[]
string
{
"IP"
,
"NODE"
}
podTemplateColumns
=
[]
string
{
"TEMPLATE"
,
"CONTAINER(S)"
,
"IMAGE(S)"
,
"PODLABELS"
}
podTemplateColumns
=
[]
string
{
"TEMPLATE"
,
"CONTAINER(S)"
,
"IMAGE(S)"
,
"PODLABELS"
}
podDisruptionBudgetColumns
=
[]
string
{
"NAME"
,
"MIN-AVAILABLE"
,
"ALLOWED-DISRUPTIONS"
,
"AGE"
}
podDisruptionBudgetColumns
=
[]
string
{
"NAME"
,
"MIN-AVAILABLE"
,
"
MAX-UNAVAILABLE"
,
"
ALLOWED-DISRUPTIONS"
,
"AGE"
}
replicationControllerColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"CURRENT"
,
"READY"
,
"AGE"
}
replicationControllerColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"CURRENT"
,
"READY"
,
"AGE"
}
replicationControllerWideColumns
=
[]
string
{
"CONTAINER(S)"
,
"IMAGE(S)"
,
"SELECTOR"
}
replicationControllerWideColumns
=
[]
string
{
"CONTAINER(S)"
,
"IMAGE(S)"
,
"SELECTOR"
}
replicaSetColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"CURRENT"
,
"READY"
,
"AGE"
}
replicaSetColumns
=
[]
string
{
"NAME"
,
"DESIRED"
,
"CURRENT"
,
"READY"
,
"AGE"
}
...
@@ -397,7 +397,7 @@ func printPodTemplateList(podList *api.PodTemplateList, w io.Writer, options pri
...
@@ -397,7 +397,7 @@ func printPodTemplateList(podList *api.PodTemplateList, w io.Writer, options pri
}
}
func
printPodDisruptionBudget
(
pdb
*
policy
.
PodDisruptionBudget
,
w
io
.
Writer
,
options
printers
.
PrintOptions
)
error
{
func
printPodDisruptionBudget
(
pdb
*
policy
.
PodDisruptionBudget
,
w
io
.
Writer
,
options
printers
.
PrintOptions
)
error
{
// name, minavailable, selector
// name, minavailable,
maxUnavailable,
selector
name
:=
printers
.
FormatResourceName
(
options
.
Kind
,
pdb
.
Name
,
options
.
WithKind
)
name
:=
printers
.
FormatResourceName
(
options
.
Kind
,
pdb
.
Name
,
options
.
WithKind
)
namespace
:=
pdb
.
Namespace
namespace
:=
pdb
.
Namespace
...
@@ -406,9 +406,25 @@ func printPodDisruptionBudget(pdb *policy.PodDisruptionBudget, w io.Writer, opti
...
@@ -406,9 +406,25 @@ func printPodDisruptionBudget(pdb *policy.PodDisruptionBudget, w io.Writer, opti
return
err
return
err
}
}
}
}
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%d
\t
%s
\n
"
,
var
minAvailable
string
var
maxUnavailable
string
if
pdb
.
Spec
.
MinAvailable
!=
nil
{
minAvailable
=
pdb
.
Spec
.
MinAvailable
.
String
()
}
else
{
minAvailable
=
"N/A"
}
if
pdb
.
Spec
.
MaxUnavailable
!=
nil
{
maxUnavailable
=
pdb
.
Spec
.
MaxUnavailable
.
String
()
}
else
{
maxUnavailable
=
"N/A"
}
if
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%d
\t
%s
\n
"
,
name
,
name
,
pdb
.
Spec
.
MinAvailable
.
String
(),
minAvailable
,
maxUnavailable
,
pdb
.
Status
.
PodDisruptionsAllowed
,
pdb
.
Status
.
PodDisruptionsAllowed
,
translateTimestamp
(
pdb
.
CreationTimestamp
),
translateTimestamp
(
pdb
.
CreationTimestamp
),
);
err
!=
nil
{
);
err
!=
nil
{
...
...
pkg/printers/internalversion/printers_test.go
View file @
078f9566
...
@@ -2186,6 +2186,7 @@ func TestPrintService(t *testing.T) {
...
@@ -2186,6 +2186,7 @@ func TestPrintService(t *testing.T) {
}
}
func
TestPrintPodDisruptionBudget
(
t
*
testing
.
T
)
{
func
TestPrintPodDisruptionBudget
(
t
*
testing
.
T
)
{
minAvailable
:=
intstr
.
FromInt
(
22
)
tests
:=
[]
struct
{
tests
:=
[]
struct
{
pdb
policy
.
PodDisruptionBudget
pdb
policy
.
PodDisruptionBudget
expect
string
expect
string
...
@@ -2198,13 +2199,13 @@ func TestPrintPodDisruptionBudget(t *testing.T) {
...
@@ -2198,13 +2199,13 @@ func TestPrintPodDisruptionBudget(t *testing.T) {
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
CreationTimestamp
:
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
1.9e9
)},
},
},
Spec
:
policy
.
PodDisruptionBudgetSpec
{
Spec
:
policy
.
PodDisruptionBudgetSpec
{
MinAvailable
:
intstr
.
FromInt
(
22
)
,
MinAvailable
:
&
minAvailable
,
},
},
Status
:
policy
.
PodDisruptionBudgetStatus
{
Status
:
policy
.
PodDisruptionBudgetStatus
{
PodDisruptionsAllowed
:
5
,
PodDisruptionsAllowed
:
5
,
},
},
},
},
"pdb1
\t
22
\t
5
\t
0s
\n
"
,
"pdb1
\t
22
\t
N/A
\t
5
\t
0s
\n
"
,
}}
}}
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
...
...
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