Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DeleteOptions conversion #85077

Merged
merged 1 commit into from Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 40 additions & 5 deletions staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/conversion.go
Expand Up @@ -18,6 +18,7 @@ package v1

import (
"fmt"
"net/url"
"strconv"
"strings"

Expand All @@ -26,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
)

Expand Down Expand Up @@ -81,7 +83,7 @@ func AddConversionFuncs(scheme *runtime.Scheme) error {

Convert_Slice_string_To_Slice_int32,

Convert_Slice_string_To_v1_DeletionPropagation,
Convert_Slice_string_To_Pointer_v1_DeletionPropagation,

Convert_Slice_string_To_v1_IncludeObjectPolicy,
)
Expand Down Expand Up @@ -352,13 +354,16 @@ 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(in *[]string, out *DeletionPropagation, s conversion.Scope) error {
// Convert_Slice_string_To_Pointer_v1_DeletionPropagation allows converting a URL query parameter propagationPolicy
func Convert_Slice_string_To_Pointer_v1_DeletionPropagation(in *[]string, out **DeletionPropagation, s conversion.Scope) error {
liggitt marked this conversation as resolved.
Show resolved Hide resolved
var str string
if len(*in) > 0 {
*out = DeletionPropagation((*in)[0])
str = (*in)[0]
liggitt marked this conversation as resolved.
Show resolved Hide resolved
} else {
*out = ""
str = ""
}
liggitt marked this conversation as resolved.
Show resolved Hide resolved
temp := DeletionPropagation(str)
*out = &temp
return nil
}

Expand All @@ -369,3 +374,33 @@ func Convert_Slice_string_To_v1_IncludeObjectPolicy(in *[]string, out *IncludeOb
}
return nil
}

// Convert_url_Values_To_v1_DeleteOptions allows converting a URL to DeleteOptions.
func Convert_url_Values_To_v1_DeleteOptions(in *url.Values, out *DeleteOptions, s conversion.Scope) error {
if err := autoConvert_url_Values_To_v1_DeleteOptions(in, out, s); err != nil {
return err
}

uid := types.UID("")
if values, ok := (*in)["uid"]; ok && len(values) > 0 {
uid = types.UID(values[0])
}

resourceVersion := ""
if values, ok := (*in)["resourceVersion"]; ok && len(values) > 0 {
resourceVersion = values[0]
}

if len(uid) > 0 || len(resourceVersion) > 0 {
if out.Preconditions == nil {
out.Preconditions = &Preconditions{}
}
if len(uid) > 0 {
out.Preconditions.UID = &uid
}
if len(resourceVersion) > 0 {
out.Preconditions.ResourceVersion = &resourceVersion
}
}
return nil
}
Expand Up @@ -75,13 +75,13 @@ func TestConvertSliceStringToDeletionPropagation(t *testing.T) {
}

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)
var dpPtr *v1.DeletionPropagation
if err := v1.Convert_Slice_string_To_Pointer_v1_DeletionPropagation(&tc.Input, &dpPtr, nil); err != nil {
t.Errorf("Convert_Slice_string_To_Pointer_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)
if !apiequality.Semantic.DeepEqual(dpPtr, &tc.Output) {
t.Errorf("slice string to DeletionPropagation conversion failed: got %v; want %v", *dpPtr, tc.Output)
}
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go
Expand Up @@ -455,6 +455,7 @@ const (
DryRunAll = "All"
)

// +k8s:conversion-gen:explicit-from=net/url.Values
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// DeleteOptions may be provided when deleting an API object.
Expand All @@ -470,6 +471,7 @@ type DeleteOptions struct {

// Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be
// returned.
// +k8s:conversion-gen=false
gongguan marked this conversation as resolved.
Show resolved Hide resolved
// +optional
Preconditions *Preconditions `json:"preconditions,omitempty" protobuf:"bytes,2,opt,name=preconditions"`

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -1068,6 +1068,11 @@ func (g *genConversion) generateFromUrlValues(inType, outType *types.Type, sw *g
}
sw.Do("func auto"+nameTmpl+"(in *$.inType|raw$, out *$.outType|raw$, s $.Scope|raw$) error {\n", args)
for _, outMember := range outType.Members {
if tagvals := extractTag(outMember.CommentLines); tagvals != nil && tagvals[0] == "false" {
// This field is excluded from conversion.
sw.Do("// INFO: in."+outMember.Name+" opted out of conversion generation\n", nil)
continue
}
jsonTag := reflect.StructTag(outMember.Tags).Get("json")
index := strings.Index(jsonTag, ",")
if index == -1 {
Expand Down