Matteo Scandolo | a428586 | 2020-12-01 18:10:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2014 The Kubernetes Authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package v1 |
| 18 | |
| 19 | import ( |
| 20 | "fmt" |
| 21 | "net/url" |
| 22 | "strconv" |
| 23 | "strings" |
| 24 | |
| 25 | "k8s.io/apimachinery/pkg/api/resource" |
| 26 | "k8s.io/apimachinery/pkg/conversion" |
| 27 | "k8s.io/apimachinery/pkg/fields" |
| 28 | "k8s.io/apimachinery/pkg/labels" |
| 29 | "k8s.io/apimachinery/pkg/types" |
| 30 | "k8s.io/apimachinery/pkg/util/intstr" |
| 31 | ) |
| 32 | |
| 33 | func Convert_Pointer_float64_To_float64(in **float64, out *float64, s conversion.Scope) error { |
| 34 | if *in == nil { |
| 35 | *out = 0 |
| 36 | return nil |
| 37 | } |
| 38 | *out = float64(**in) |
| 39 | return nil |
| 40 | } |
| 41 | |
| 42 | func Convert_float64_To_Pointer_float64(in *float64, out **float64, s conversion.Scope) error { |
| 43 | temp := float64(*in) |
| 44 | *out = &temp |
| 45 | return nil |
| 46 | } |
| 47 | |
| 48 | func Convert_Pointer_int32_To_int32(in **int32, out *int32, s conversion.Scope) error { |
| 49 | if *in == nil { |
| 50 | *out = 0 |
| 51 | return nil |
| 52 | } |
| 53 | *out = int32(**in) |
| 54 | return nil |
| 55 | } |
| 56 | |
| 57 | func Convert_int32_To_Pointer_int32(in *int32, out **int32, s conversion.Scope) error { |
| 58 | temp := int32(*in) |
| 59 | *out = &temp |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | func Convert_Pointer_int64_To_int64(in **int64, out *int64, s conversion.Scope) error { |
| 64 | if *in == nil { |
| 65 | *out = 0 |
| 66 | return nil |
| 67 | } |
| 68 | *out = int64(**in) |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | func Convert_int64_To_Pointer_int64(in *int64, out **int64, s conversion.Scope) error { |
| 73 | temp := int64(*in) |
| 74 | *out = &temp |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | func Convert_Pointer_int64_To_int(in **int64, out *int, s conversion.Scope) error { |
| 79 | if *in == nil { |
| 80 | *out = 0 |
| 81 | return nil |
| 82 | } |
| 83 | *out = int(**in) |
| 84 | return nil |
| 85 | } |
| 86 | |
| 87 | func Convert_int_To_Pointer_int64(in *int, out **int64, s conversion.Scope) error { |
| 88 | temp := int64(*in) |
| 89 | *out = &temp |
| 90 | return nil |
| 91 | } |
| 92 | |
| 93 | func Convert_Pointer_string_To_string(in **string, out *string, s conversion.Scope) error { |
| 94 | if *in == nil { |
| 95 | *out = "" |
| 96 | return nil |
| 97 | } |
| 98 | *out = **in |
| 99 | return nil |
| 100 | } |
| 101 | |
| 102 | func Convert_string_To_Pointer_string(in *string, out **string, s conversion.Scope) error { |
| 103 | if in == nil { |
| 104 | stringVar := "" |
| 105 | *out = &stringVar |
| 106 | return nil |
| 107 | } |
| 108 | *out = in |
| 109 | return nil |
| 110 | } |
| 111 | |
| 112 | func Convert_Pointer_bool_To_bool(in **bool, out *bool, s conversion.Scope) error { |
| 113 | if *in == nil { |
| 114 | *out = false |
| 115 | return nil |
| 116 | } |
| 117 | *out = **in |
| 118 | return nil |
| 119 | } |
| 120 | |
| 121 | func Convert_bool_To_Pointer_bool(in *bool, out **bool, s conversion.Scope) error { |
| 122 | if in == nil { |
| 123 | boolVar := false |
| 124 | *out = &boolVar |
| 125 | return nil |
| 126 | } |
| 127 | *out = in |
| 128 | return nil |
| 129 | } |
| 130 | |
| 131 | // +k8s:conversion-fn=drop |
| 132 | func Convert_v1_TypeMeta_To_v1_TypeMeta(in, out *TypeMeta, s conversion.Scope) error { |
| 133 | // These values are explicitly not copied |
| 134 | //out.APIVersion = in.APIVersion |
| 135 | //out.Kind = in.Kind |
| 136 | return nil |
| 137 | } |
| 138 | |
| 139 | // +k8s:conversion-fn=copy-only |
| 140 | func Convert_v1_ListMeta_To_v1_ListMeta(in, out *ListMeta, s conversion.Scope) error { |
| 141 | *out = *in |
| 142 | return nil |
| 143 | } |
| 144 | |
| 145 | // +k8s:conversion-fn=copy-only |
| 146 | func Convert_v1_DeleteOptions_To_v1_DeleteOptions(in, out *DeleteOptions, s conversion.Scope) error { |
| 147 | *out = *in |
| 148 | return nil |
| 149 | } |
| 150 | |
| 151 | // +k8s:conversion-fn=copy-only |
| 152 | func Convert_intstr_IntOrString_To_intstr_IntOrString(in, out *intstr.IntOrString, s conversion.Scope) error { |
| 153 | *out = *in |
| 154 | return nil |
| 155 | } |
| 156 | |
| 157 | func Convert_Pointer_intstr_IntOrString_To_intstr_IntOrString(in **intstr.IntOrString, out *intstr.IntOrString, s conversion.Scope) error { |
| 158 | if *in == nil { |
| 159 | *out = intstr.IntOrString{} // zero value |
| 160 | return nil |
| 161 | } |
| 162 | *out = **in // copy |
| 163 | return nil |
| 164 | } |
| 165 | |
| 166 | func Convert_intstr_IntOrString_To_Pointer_intstr_IntOrString(in *intstr.IntOrString, out **intstr.IntOrString, s conversion.Scope) error { |
| 167 | temp := *in // copy |
| 168 | *out = &temp |
| 169 | return nil |
| 170 | } |
| 171 | |
| 172 | // +k8s:conversion-fn=copy-only |
| 173 | func Convert_v1_Time_To_v1_Time(in *Time, out *Time, s conversion.Scope) error { |
| 174 | // Cannot deep copy these, because time.Time has unexported fields. |
| 175 | *out = *in |
| 176 | return nil |
| 177 | } |
| 178 | |
| 179 | // +k8s:conversion-fn=copy-only |
| 180 | func Convert_v1_MicroTime_To_v1_MicroTime(in *MicroTime, out *MicroTime, s conversion.Scope) error { |
| 181 | // Cannot deep copy these, because time.Time has unexported fields. |
| 182 | *out = *in |
| 183 | return nil |
| 184 | } |
| 185 | |
| 186 | func Convert_Pointer_v1_Duration_To_v1_Duration(in **Duration, out *Duration, s conversion.Scope) error { |
| 187 | if *in == nil { |
| 188 | *out = Duration{} // zero duration |
| 189 | return nil |
| 190 | } |
| 191 | *out = **in // copy |
| 192 | return nil |
| 193 | } |
| 194 | |
| 195 | func Convert_v1_Duration_To_Pointer_v1_Duration(in *Duration, out **Duration, s conversion.Scope) error { |
| 196 | temp := *in //copy |
| 197 | *out = &temp |
| 198 | return nil |
| 199 | } |
| 200 | |
| 201 | // Convert_Slice_string_To_v1_Time allows converting a URL query parameter value |
| 202 | func Convert_Slice_string_To_v1_Time(in *[]string, out *Time, s conversion.Scope) error { |
| 203 | str := "" |
| 204 | if len(*in) > 0 { |
| 205 | str = (*in)[0] |
| 206 | } |
| 207 | return out.UnmarshalQueryParameter(str) |
| 208 | } |
| 209 | |
| 210 | func Convert_Slice_string_To_Pointer_v1_Time(in *[]string, out **Time, s conversion.Scope) error { |
| 211 | if in == nil { |
| 212 | return nil |
| 213 | } |
| 214 | str := "" |
| 215 | if len(*in) > 0 { |
| 216 | str = (*in)[0] |
| 217 | } |
| 218 | temp := Time{} |
| 219 | if err := temp.UnmarshalQueryParameter(str); err != nil { |
| 220 | return err |
| 221 | } |
| 222 | *out = &temp |
| 223 | return nil |
| 224 | } |
| 225 | |
| 226 | func Convert_string_To_labels_Selector(in *string, out *labels.Selector, s conversion.Scope) error { |
| 227 | selector, err := labels.Parse(*in) |
| 228 | if err != nil { |
| 229 | return err |
| 230 | } |
| 231 | *out = selector |
| 232 | return nil |
| 233 | } |
| 234 | |
| 235 | func Convert_string_To_fields_Selector(in *string, out *fields.Selector, s conversion.Scope) error { |
| 236 | selector, err := fields.ParseSelector(*in) |
| 237 | if err != nil { |
| 238 | return err |
| 239 | } |
| 240 | *out = selector |
| 241 | return nil |
| 242 | } |
| 243 | |
| 244 | func Convert_labels_Selector_To_string(in *labels.Selector, out *string, s conversion.Scope) error { |
| 245 | if *in == nil { |
| 246 | return nil |
| 247 | } |
| 248 | *out = (*in).String() |
| 249 | return nil |
| 250 | } |
| 251 | |
| 252 | func Convert_fields_Selector_To_string(in *fields.Selector, out *string, s conversion.Scope) error { |
| 253 | if *in == nil { |
| 254 | return nil |
| 255 | } |
| 256 | *out = (*in).String() |
| 257 | return nil |
| 258 | } |
| 259 | |
| 260 | // +k8s:conversion-fn=copy-only |
| 261 | func Convert_resource_Quantity_To_resource_Quantity(in *resource.Quantity, out *resource.Quantity, s conversion.Scope) error { |
| 262 | *out = *in |
| 263 | return nil |
| 264 | } |
| 265 | |
| 266 | func Convert_Map_string_To_string_To_v1_LabelSelector(in *map[string]string, out *LabelSelector, s conversion.Scope) error { |
| 267 | if in == nil { |
| 268 | return nil |
| 269 | } |
| 270 | for labelKey, labelValue := range *in { |
| 271 | AddLabelToSelector(out, labelKey, labelValue) |
| 272 | } |
| 273 | return nil |
| 274 | } |
| 275 | |
| 276 | func Convert_v1_LabelSelector_To_Map_string_To_string(in *LabelSelector, out *map[string]string, s conversion.Scope) error { |
| 277 | var err error |
| 278 | *out, err = LabelSelectorAsMap(in) |
| 279 | return err |
| 280 | } |
| 281 | |
| 282 | // Convert_Slice_string_To_Slice_int32 converts multiple query parameters or |
| 283 | // a single query parameter with a comma delimited value to multiple int32. |
| 284 | // This is used for port forwarding which needs the ports as int32. |
| 285 | func Convert_Slice_string_To_Slice_int32(in *[]string, out *[]int32, s conversion.Scope) error { |
| 286 | for _, s := range *in { |
| 287 | for _, v := range strings.Split(s, ",") { |
| 288 | x, err := strconv.ParseUint(v, 10, 16) |
| 289 | if err != nil { |
| 290 | return fmt.Errorf("cannot convert to []int32: %v", err) |
| 291 | } |
| 292 | *out = append(*out, int32(x)) |
| 293 | } |
| 294 | } |
| 295 | return nil |
| 296 | } |
| 297 | |
| 298 | // Convert_Slice_string_To_Pointer_v1_DeletionPropagation allows converting a URL query parameter propagationPolicy |
| 299 | func Convert_Slice_string_To_Pointer_v1_DeletionPropagation(in *[]string, out **DeletionPropagation, s conversion.Scope) error { |
| 300 | var str string |
| 301 | if len(*in) > 0 { |
| 302 | str = (*in)[0] |
| 303 | } else { |
| 304 | str = "" |
| 305 | } |
| 306 | temp := DeletionPropagation(str) |
| 307 | *out = &temp |
| 308 | return nil |
| 309 | } |
| 310 | |
| 311 | // Convert_Slice_string_To_v1_IncludeObjectPolicy allows converting a URL query parameter value |
| 312 | func Convert_Slice_string_To_v1_IncludeObjectPolicy(in *[]string, out *IncludeObjectPolicy, s conversion.Scope) error { |
| 313 | if len(*in) > 0 { |
| 314 | *out = IncludeObjectPolicy((*in)[0]) |
| 315 | } |
| 316 | return nil |
| 317 | } |
| 318 | |
| 319 | // Convert_url_Values_To_v1_DeleteOptions allows converting a URL to DeleteOptions. |
| 320 | func Convert_url_Values_To_v1_DeleteOptions(in *url.Values, out *DeleteOptions, s conversion.Scope) error { |
| 321 | if err := autoConvert_url_Values_To_v1_DeleteOptions(in, out, s); err != nil { |
| 322 | return err |
| 323 | } |
| 324 | |
| 325 | uid := types.UID("") |
| 326 | if values, ok := (*in)["uid"]; ok && len(values) > 0 { |
| 327 | uid = types.UID(values[0]) |
| 328 | } |
| 329 | |
| 330 | resourceVersion := "" |
| 331 | if values, ok := (*in)["resourceVersion"]; ok && len(values) > 0 { |
| 332 | resourceVersion = values[0] |
| 333 | } |
| 334 | |
| 335 | if len(uid) > 0 || len(resourceVersion) > 0 { |
| 336 | if out.Preconditions == nil { |
| 337 | out.Preconditions = &Preconditions{} |
| 338 | } |
| 339 | if len(uid) > 0 { |
| 340 | out.Preconditions.UID = &uid |
| 341 | } |
| 342 | if len(resourceVersion) > 0 { |
| 343 | out.Preconditions.ResourceVersion = &resourceVersion |
| 344 | } |
| 345 | } |
| 346 | return nil |
| 347 | } |
| 348 | |
| 349 | // Convert_Slice_string_To_v1_ResourceVersionMatch allows converting a URL query parameter to ResourceVersionMatch |
| 350 | func Convert_Slice_string_To_v1_ResourceVersionMatch(in *[]string, out *ResourceVersionMatch, s conversion.Scope) error { |
| 351 | if len(*in) > 0 { |
| 352 | *out = ResourceVersionMatch((*in)[0]) |
| 353 | } |
| 354 | return nil |
| 355 | } |