k8s.io/client-go@v0.31.1/scale/scheme/autoscalingv1/conversion.go (about) 1 /* 2 Copyright 2017 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 autoscalingv1 18 19 import ( 20 "fmt" 21 22 v1 "k8s.io/api/autoscaling/v1" 23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 "k8s.io/apimachinery/pkg/conversion" 25 scheme "k8s.io/client-go/scale/scheme" 26 ) 27 28 func Convert_scheme_ScaleStatus_To_v1_ScaleStatus(in *scheme.ScaleStatus, out *v1.ScaleStatus, s conversion.Scope) error { 29 out.Replicas = in.Replicas 30 out.Selector = "" 31 if in.Selector != nil { 32 selector, err := metav1.LabelSelectorAsSelector(in.Selector) 33 if err != nil { 34 return fmt.Errorf("invalid label selector: %v", err) 35 } 36 out.Selector = selector.String() 37 } 38 39 return nil 40 } 41 42 func Convert_v1_ScaleStatus_To_scheme_ScaleStatus(in *v1.ScaleStatus, out *scheme.ScaleStatus, s conversion.Scope) error { 43 out.Replicas = in.Replicas 44 if in.Selector != "" { 45 labelSelector, err := metav1.ParseToLabelSelector(in.Selector) 46 if err != nil { 47 out.Selector = nil 48 return fmt.Errorf("failed to parse target selector: %v", err) 49 } 50 out.Selector = labelSelector 51 } 52 53 return nil 54 }