mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #85077 from gongguan/DeleteOptions
add DeleteOptions conversion
This commit is contained in:
commit
3b440dfd55
@ -18,6 +18,7 @@ package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -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"
|
||||
)
|
||||
|
||||
@ -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,
|
||||
)
|
||||
@ -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 {
|
||||
var str string
|
||||
if len(*in) > 0 {
|
||||
*out = DeletionPropagation((*in)[0])
|
||||
str = (*in)[0]
|
||||
} else {
|
||||
*out = ""
|
||||
str = ""
|
||||
}
|
||||
temp := DeletionPropagation(str)
|
||||
*out = &temp
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,6 +163,7 @@ message DeleteOptions {
|
||||
|
||||
// Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be
|
||||
// returned.
|
||||
// +k8s:conversion-gen=false
|
||||
// +optional
|
||||
optional Preconditions preconditions = 2;
|
||||
|
||||
|
@ -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.
|
||||
@ -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
|
||||
// +optional
|
||||
Preconditions *Preconditions `json:"preconditions,omitempty" protobuf:"bytes,2,opt,name=preconditions"`
|
||||
|
||||
|
@ -45,6 +45,11 @@ func RegisterConversions(s *runtime.Scheme) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*url.Values)(nil), (*DeleteOptions)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_url_Values_To_v1_DeleteOptions(a.(*url.Values), b.(*DeleteOptions), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddGeneratedConversionFunc((*url.Values)(nil), (*ExportOptions)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_url_Values_To_v1_ExportOptions(a.(*url.Values), b.(*ExportOptions), scope)
|
||||
}); err != nil {
|
||||
@ -120,6 +125,11 @@ func RegisterConversions(s *runtime.Scheme) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*[]string)(nil), (**DeletionPropagation)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_Slice_string_To_Pointer_v1_DeletionPropagation(a.(*[]string), b.(**DeletionPropagation), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*[]string)(nil), (**Time)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_Slice_string_To_Pointer_v1_Time(a.(*[]string), b.(**Time), scope)
|
||||
}); err != nil {
|
||||
@ -130,11 +140,6 @@ func RegisterConversions(s *runtime.Scheme) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*[]string)(nil), (*DeletionPropagation)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_Slice_string_To_v1_DeletionPropagation(a.(*[]string), b.(*DeletionPropagation), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*[]string)(nil), (*IncludeObjectPolicy)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_Slice_string_To_v1_IncludeObjectPolicy(a.(*[]string), b.(*IncludeObjectPolicy), scope)
|
||||
}); err != nil {
|
||||
@ -210,6 +215,11 @@ func RegisterConversions(s *runtime.Scheme) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*url.Values)(nil), (*DeleteOptions)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_url_Values_To_v1_DeleteOptions(a.(*url.Values), b.(*DeleteOptions), scope)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.AddConversionFunc((*DeleteOptions)(nil), (*DeleteOptions)(nil), func(a, b interface{}, scope conversion.Scope) error {
|
||||
return Convert_v1_DeleteOptions_To_v1_DeleteOptions(a.(*DeleteOptions), b.(*DeleteOptions), scope)
|
||||
}); err != nil {
|
||||
@ -291,6 +301,39 @@ func Convert_url_Values_To_v1_CreateOptions(in *url.Values, out *CreateOptions,
|
||||
return autoConvert_url_Values_To_v1_CreateOptions(in, out, s)
|
||||
}
|
||||
|
||||
func autoConvert_url_Values_To_v1_DeleteOptions(in *url.Values, out *DeleteOptions, s conversion.Scope) error {
|
||||
// WARNING: Field TypeMeta does not have json tag, skipping.
|
||||
|
||||
if values, ok := map[string][]string(*in)["gracePeriodSeconds"]; ok && len(values) > 0 {
|
||||
if err := runtime.Convert_Slice_string_To_Pointer_int64(&values, &out.GracePeriodSeconds, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.GracePeriodSeconds = nil
|
||||
}
|
||||
// INFO: in.Preconditions opted out of conversion generation
|
||||
if values, ok := map[string][]string(*in)["orphanDependents"]; ok && len(values) > 0 {
|
||||
if err := runtime.Convert_Slice_string_To_Pointer_bool(&values, &out.OrphanDependents, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.OrphanDependents = nil
|
||||
}
|
||||
if values, ok := map[string][]string(*in)["propagationPolicy"]; ok && len(values) > 0 {
|
||||
if err := Convert_Slice_string_To_Pointer_v1_DeletionPropagation(&values, &out.PropagationPolicy, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.PropagationPolicy = nil
|
||||
}
|
||||
if values, ok := map[string][]string(*in)["dryRun"]; ok && len(values) > 0 {
|
||||
out.DryRun = *(*[]string)(unsafe.Pointer(&values))
|
||||
} else {
|
||||
out.DryRun = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func autoConvert_url_Values_To_v1_ExportOptions(in *url.Values, out *ExportOptions, s conversion.Scope) error {
|
||||
// WARNING: Field TypeMeta does not have json tag, skipping.
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user