github.com/aclisp/heapster@v0.19.2-0.20160613100040-51756f899a96/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/conversion.go (about) 1 /* 2 Copyright 2014 The Kubernetes Authors All rights reserved. 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 api 18 19 import ( 20 "k8s.io/kubernetes/pkg/api/resource" 21 "k8s.io/kubernetes/pkg/api/unversioned" 22 "k8s.io/kubernetes/pkg/conversion" 23 "k8s.io/kubernetes/pkg/fields" 24 "k8s.io/kubernetes/pkg/labels" 25 "k8s.io/kubernetes/pkg/util/intstr" 26 ) 27 28 func init() { 29 Scheme.AddDefaultingFuncs( 30 func(obj *ListOptions) { 31 if obj.LabelSelector == nil { 32 obj.LabelSelector = labels.Everything() 33 } 34 if obj.FieldSelector == nil { 35 obj.FieldSelector = fields.Everything() 36 } 37 }, 38 ) 39 Scheme.AddConversionFuncs( 40 Convert_unversioned_TypeMeta_To_unversioned_TypeMeta, 41 Convert_unversioned_ListMeta_To_unversioned_ListMeta, 42 Convert_intstr_IntOrString_To_intstr_IntOrString, 43 Convert_unversioned_Time_To_unversioned_Time, 44 Convert_Slice_string_To_unversioned_Time, 45 Convert_string_To_labels_Selector, 46 Convert_string_To_fields_Selector, 47 Convert_Pointer_bool_To_bool, 48 Convert_bool_To_Pointer_bool, 49 Convert_Pointer_string_To_string, 50 Convert_string_To_Pointer_string, 51 Convert_labels_Selector_To_string, 52 Convert_fields_Selector_To_string, 53 Convert_resource_Quantity_To_resource_Quantity, 54 ) 55 } 56 57 func Convert_Pointer_string_To_string(in **string, out *string, s conversion.Scope) error { 58 if *in == nil { 59 *out = "" 60 return nil 61 } 62 *out = **in 63 return nil 64 } 65 66 func Convert_string_To_Pointer_string(in *string, out **string, s conversion.Scope) error { 67 if in == nil { 68 stringVar := "" 69 *out = &stringVar 70 return nil 71 } 72 *out = in 73 return nil 74 } 75 76 func Convert_Pointer_bool_To_bool(in **bool, out *bool, s conversion.Scope) error { 77 if *in == nil { 78 *out = false 79 return nil 80 } 81 *out = **in 82 return nil 83 } 84 85 func Convert_bool_To_Pointer_bool(in *bool, out **bool, s conversion.Scope) error { 86 if in == nil { 87 boolVar := false 88 *out = &boolVar 89 return nil 90 } 91 *out = in 92 return nil 93 } 94 95 func Convert_unversioned_TypeMeta_To_unversioned_TypeMeta(in, out *unversioned.TypeMeta, s conversion.Scope) error { 96 // These values are explicitly not copied 97 //out.APIVersion = in.APIVersion 98 //out.Kind = in.Kind 99 return nil 100 } 101 102 func Convert_unversioned_ListMeta_To_unversioned_ListMeta(in, out *unversioned.ListMeta, s conversion.Scope) error { 103 out.ResourceVersion = in.ResourceVersion 104 out.SelfLink = in.SelfLink 105 return nil 106 } 107 108 func Convert_intstr_IntOrString_To_intstr_IntOrString(in, out *intstr.IntOrString, s conversion.Scope) error { 109 out.Type = in.Type 110 out.IntVal = in.IntVal 111 out.StrVal = in.StrVal 112 return nil 113 } 114 115 func Convert_unversioned_Time_To_unversioned_Time(in *unversioned.Time, out *unversioned.Time, s conversion.Scope) error { 116 // Cannot deep copy these, because time.Time has unexported fields. 117 *out = *in 118 return nil 119 } 120 121 // Convert_Slice_string_To_unversioned_Time allows converting a URL query parameter value 122 func Convert_Slice_string_To_unversioned_Time(input *[]string, out *unversioned.Time, s conversion.Scope) error { 123 str := "" 124 if len(*input) > 0 { 125 str = (*input)[0] 126 } 127 return out.UnmarshalQueryParameter(str) 128 } 129 130 func Convert_string_To_labels_Selector(in *string, out *labels.Selector, s conversion.Scope) error { 131 selector, err := labels.Parse(*in) 132 if err != nil { 133 return err 134 } 135 *out = selector 136 return nil 137 } 138 func Convert_string_To_fields_Selector(in *string, out *fields.Selector, s conversion.Scope) error { 139 selector, err := fields.ParseSelector(*in) 140 if err != nil { 141 return err 142 } 143 *out = selector 144 return nil 145 } 146 func Convert_labels_Selector_To_string(in *labels.Selector, out *string, s conversion.Scope) error { 147 if *in == nil { 148 return nil 149 } 150 *out = (*in).String() 151 return nil 152 } 153 func Convert_fields_Selector_To_string(in *fields.Selector, out *string, s conversion.Scope) error { 154 if *in == nil { 155 return nil 156 } 157 *out = (*in).String() 158 return nil 159 } 160 func Convert_resource_Quantity_To_resource_Quantity(in *resource.Quantity, out *resource.Quantity, s conversion.Scope) error { 161 // Cannot deep copy these, because inf.Dec has unexported fields. 162 *out = *in.Copy() 163 return nil 164 }