Merge pull request #63414 from roycaihw/fix-delete-query

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>.

Add conversion to properly parse query parameter propagationPolicy

**What this PR does / why we need it**:
This delete request query parameter has been broken for a year. I'm not sure if we want to deprecate the non-standard DeleteOptions body on delete request eventually. 

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #43329

**Special notes for your reviewer**:

**Release note**:

```release-note
API server properly parses propagationPolicy as a query parameter sent with a delete request
```

/sig api-machinery
This commit is contained in:
Kubernetes Submit Queue 2018-05-25 06:59:05 -07:00 committed by GitHub
commit c0f91a8a1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View File

@ -75,6 +75,8 @@ func AddConversionFuncs(scheme *runtime.Scheme) error {
Convert_unversioned_LabelSelector_to_map,
Convert_Slice_string_To_Slice_int32,
Convert_Slice_string_To_v1_DeletionPropagation,
)
}
@ -304,3 +306,13 @@ func Convert_Slice_string_To_Slice_int32(in *[]string, out *[]int32, s conversio
}
return nil
}
// Convert_Slice_string_To_v1_DeletionPropagation allows converting a URL query parameter propagationPolicy
func Convert_Slice_string_To_v1_DeletionPropagation(input *[]string, out *DeletionPropagation, s conversion.Scope) error {
if len(*input) > 0 {
*out = DeletionPropagation((*input)[0])
} else {
*out = ""
}
return nil
}

View File

@ -47,3 +47,38 @@ func TestMapToLabelSelectorRoundTrip(t *testing.T) {
}
}
}
func TestConvertSliceStringToDeletionPropagation(t *testing.T) {
tcs := []struct {
Input []string
Output v1.DeletionPropagation
}{
{
Input: nil,
Output: "",
},
{
Input: []string{},
Output: "",
},
{
Input: []string{"foo"},
Output: "foo",
},
{
Input: []string{"bar", "foo"},
Output: "bar",
},
}
for _, tc := range tcs {
var dp v1.DeletionPropagation
if err := v1.Convert_Slice_string_To_v1_DeletionPropagation(&tc.Input, &dp, nil); err != nil {
t.Errorf("Convert_Slice_string_To_v1_DeletionPropagation(%#v): %v", tc.Input, err)
continue
}
if !apiequality.Semantic.DeepEqual(dp, tc.Output) {
t.Errorf("slice string to DeletionPropagation conversion failed: got %v; want %v", dp, tc.Output)
}
}
}