Unverified Commit ad750b60 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #54411 from frodenas/kubectl-pdb-fix

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fixes kubectl Pod Disruption Budget and adds tests **What this PR does / why we need it**: This PR fixes several kubectl Pod Disruption Budget issues: * The `min-available` parameter in Pod Disruption Budget V1 is not required (otherwise it will never use the default value) * Removes the deprecated `min-available` default in Pod Disruption Budget V2 * The `selector` parameter in Pod Disruption Budget V2 is required * Fixes (typo) the `max-unavailable` parameter check in Pod Disruption Budget V2 * Fixes some assertion error messages where the value printed was always the zero value of the parameter type instead of the parameter provided * Updated kubectl Pod Disruption Budget to use policy V1Beta1 instead of unversioned API (see https://github.com/kubernetes/kubectl/issues/90) * Add missing tests **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes https://github.com/kubernetes/kubectl/issues/101 **Special notes for your reviewer**: Spllited in several commits to make the review process easier. Please let me know if you prefer to squash some commits or if you prefer to split them in different PRs. **Release note**: ```release-note NONE ``` /cc @kubernetes/sig-cli-pr-reviews
parents 00fe2cfe c73518d1
...@@ -38,7 +38,7 @@ var _ StructuredGenerator = &PodDisruptionBudgetV1Generator{} ...@@ -38,7 +38,7 @@ var _ StructuredGenerator = &PodDisruptionBudgetV1Generator{}
func (PodDisruptionBudgetV1Generator) ParamNames() []GeneratorParam { func (PodDisruptionBudgetV1Generator) ParamNames() []GeneratorParam {
return []GeneratorParam{ return []GeneratorParam{
{"name", true}, {"name", true},
{"min-available", true}, {"min-available", false},
{"selector", true}, {"selector", true},
} }
} }
...@@ -50,15 +50,15 @@ func (s PodDisruptionBudgetV1Generator) Generate(params map[string]interface{}) ...@@ -50,15 +50,15 @@ func (s PodDisruptionBudgetV1Generator) Generate(params map[string]interface{})
} }
name, isString := params["name"].(string) name, isString := params["name"].(string)
if !isString { if !isString {
return nil, fmt.Errorf("expected string, saw %v for 'name'", name) return nil, fmt.Errorf("expected string, found %T for 'name'", params["name"])
} }
minAvailable, isString := params["min-available"].(string) minAvailable, isString := params["min-available"].(string)
if !isString { if !isString {
return nil, fmt.Errorf("expected string, found %v", minAvailable) return nil, fmt.Errorf("expected string, found %T for 'min-available'", params["min-available"])
} }
selector, isString := params["selector"].(string) selector, isString := params["selector"].(string)
if !isString { if !isString {
return nil, fmt.Errorf("expected string, found %v", selector) return nil, fmt.Errorf("expected string, found %T for 'selector'", params["selector"])
} }
delegate := &PodDisruptionBudgetV1Generator{Name: name, MinAvailable: minAvailable, Selector: selector} delegate := &PodDisruptionBudgetV1Generator{Name: name, MinAvailable: minAvailable, Selector: selector}
return delegate.StructuredGenerate() return delegate.StructuredGenerate()
...@@ -122,7 +122,7 @@ func (PodDisruptionBudgetV2Generator) ParamNames() []GeneratorParam { ...@@ -122,7 +122,7 @@ func (PodDisruptionBudgetV2Generator) ParamNames() []GeneratorParam {
{"name", true}, {"name", true},
{"min-available", false}, {"min-available", false},
{"max-unavailable", false}, {"max-unavailable", false},
{"selector", false}, {"selector", true},
} }
} }
...@@ -134,22 +134,22 @@ func (s PodDisruptionBudgetV2Generator) Generate(params map[string]interface{}) ...@@ -134,22 +134,22 @@ func (s PodDisruptionBudgetV2Generator) Generate(params map[string]interface{})
name, isString := params["name"].(string) name, isString := params["name"].(string)
if !isString { if !isString {
return nil, fmt.Errorf("expected string, saw %v for 'name'", name) return nil, fmt.Errorf("expected string, found %T for 'name'", params["name"])
} }
minAvailable, isString := params["min-available"].(string) minAvailable, isString := params["min-available"].(string)
if !isString { if !isString {
return nil, fmt.Errorf("expected string, found %v", minAvailable) return nil, fmt.Errorf("expected string, found %T for 'min-available'", params["min-available"])
} }
maxUnavailable, isString := params["max-available"].(string) maxUnavailable, isString := params["max-unavailable"].(string)
if !isString { if !isString {
return nil, fmt.Errorf("expected string, found %v", maxUnavailable) return nil, fmt.Errorf("expected string, found %T for 'max-unavailable'", params["max-unavailable"])
} }
selector, isString := params["selector"].(string) selector, isString := params["selector"].(string)
if !isString { if !isString {
return nil, fmt.Errorf("expected string, found %v", selector) return nil, fmt.Errorf("expected string, found %T for 'selector'", params["selector"])
} }
delegate := &PodDisruptionBudgetV2Generator{Name: name, MinAvailable: minAvailable, MaxUnavailable: maxUnavailable, Selector: selector} delegate := &PodDisruptionBudgetV2Generator{Name: name, MinAvailable: minAvailable, MaxUnavailable: maxUnavailable, Selector: selector}
return delegate.StructuredGenerate() return delegate.StructuredGenerate()
...@@ -204,7 +204,7 @@ func (s *PodDisruptionBudgetV2Generator) validate() error { ...@@ -204,7 +204,7 @@ func (s *PodDisruptionBudgetV2Generator) validate() error {
return fmt.Errorf("a selector must be specified") return fmt.Errorf("a selector must be specified")
} }
if len(s.MaxUnavailable) == 0 && len(s.MinAvailable) == 0 { if len(s.MaxUnavailable) == 0 && len(s.MinAvailable) == 0 {
return fmt.Errorf("one of min-available/max-available must be specified") return fmt.Errorf("one of min-available or max-unavailable must be specified")
} }
if len(s.MaxUnavailable) > 0 && len(s.MinAvailable) > 0 { if len(s.MaxUnavailable) > 0 && len(s.MinAvailable) > 0 {
return fmt.Errorf("min-available and max-unavailable cannot be both specified") return fmt.Errorf("min-available and max-unavailable cannot be both specified")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment