k8s.io/kubernetes@v1.29.3/pkg/apis/networking/v1beta1/conversion.go (about) 1 /* 2 Copyright 2020 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 v1beta1 18 19 import ( 20 v1beta1 "k8s.io/api/networking/v1beta1" 21 conversion "k8s.io/apimachinery/pkg/conversion" 22 "k8s.io/apimachinery/pkg/util/intstr" 23 networking "k8s.io/kubernetes/pkg/apis/networking" 24 ) 25 26 func Convert_v1beta1_IngressBackend_To_networking_IngressBackend(in *v1beta1.IngressBackend, out *networking.IngressBackend, s conversion.Scope) error { 27 if err := autoConvert_v1beta1_IngressBackend_To_networking_IngressBackend(in, out, s); err != nil { 28 return err 29 } 30 if len(in.ServiceName) > 0 || in.ServicePort.IntVal != 0 || in.ServicePort.StrVal != "" || in.ServicePort.Type == intstr.String { 31 out.Service = &networking.IngressServiceBackend{} 32 out.Service.Name = in.ServiceName 33 out.Service.Port.Name = in.ServicePort.StrVal 34 out.Service.Port.Number = in.ServicePort.IntVal 35 } 36 return nil 37 } 38 39 func Convert_networking_IngressBackend_To_v1beta1_IngressBackend(in *networking.IngressBackend, out *v1beta1.IngressBackend, s conversion.Scope) error { 40 if err := autoConvert_networking_IngressBackend_To_v1beta1_IngressBackend(in, out, s); err != nil { 41 return err 42 } 43 if in.Service != nil { 44 out.ServiceName = in.Service.Name 45 if len(in.Service.Port.Name) > 0 { 46 out.ServicePort = intstr.FromString(in.Service.Port.Name) 47 } else { 48 out.ServicePort = intstr.FromInt32(in.Service.Port.Number) 49 } 50 } 51 return nil 52 } 53 func Convert_v1beta1_IngressSpec_To_networking_IngressSpec(in *v1beta1.IngressSpec, out *networking.IngressSpec, s conversion.Scope) error { 54 if err := autoConvert_v1beta1_IngressSpec_To_networking_IngressSpec(in, out, s); err != nil { 55 return err 56 } 57 if in.Backend != nil { 58 out.DefaultBackend = &networking.IngressBackend{} 59 if err := Convert_v1beta1_IngressBackend_To_networking_IngressBackend(in.Backend, out.DefaultBackend, s); err != nil { 60 return err 61 } 62 } 63 return nil 64 } 65 66 func Convert_networking_IngressSpec_To_v1beta1_IngressSpec(in *networking.IngressSpec, out *v1beta1.IngressSpec, s conversion.Scope) error { 67 if err := autoConvert_networking_IngressSpec_To_v1beta1_IngressSpec(in, out, s); err != nil { 68 return err 69 } 70 if in.DefaultBackend != nil { 71 out.Backend = &v1beta1.IngressBackend{} 72 if err := Convert_networking_IngressBackend_To_v1beta1_IngressBackend(in.DefaultBackend, out.Backend, s); err != nil { 73 return err 74 } 75 } 76 return nil 77 }