2 Copyright 2014 The Kubernetes Authors.
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
22 "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
23 "k8s.io/kubernetes/pkg/conversion"
24 "k8s.io/kubernetes/pkg/runtime"
28 err := api.Scheme.AddConversionFuncs(
29 func(in *Cluster, out *api.Cluster, s conversion.Scope) error {
30 return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
32 func(in *api.Cluster, out *Cluster, s conversion.Scope) error {
33 return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
35 func(in *Preferences, out *api.Preferences, s conversion.Scope) error {
36 return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
38 func(in *api.Preferences, out *Preferences, s conversion.Scope) error {
39 return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
41 func(in *AuthInfo, out *api.AuthInfo, s conversion.Scope) error {
42 return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
44 func(in *api.AuthInfo, out *AuthInfo, s conversion.Scope) error {
45 return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
47 func(in *Context, out *api.Context, s conversion.Scope) error {
48 return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
50 func(in *api.Context, out *Context, s conversion.Scope) error {
51 return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
54 func(in *Config, out *api.Config, s conversion.Scope) error {
55 out.CurrentContext = in.CurrentContext
56 if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil {
60 out.Clusters = make(map[string]*api.Cluster)
61 if err := s.Convert(&in.Clusters, &out.Clusters, 0); err != nil {
64 out.AuthInfos = make(map[string]*api.AuthInfo)
65 if err := s.Convert(&in.AuthInfos, &out.AuthInfos, 0); err != nil {
68 out.Contexts = make(map[string]*api.Context)
69 if err := s.Convert(&in.Contexts, &out.Contexts, 0); err != nil {
72 out.Extensions = make(map[string]runtime.Object)
73 if err := s.Convert(&in.Extensions, &out.Extensions, 0); err != nil {
78 func(in *api.Config, out *Config, s conversion.Scope) error {
79 out.CurrentContext = in.CurrentContext
80 if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil {
84 out.Clusters = make([]NamedCluster, 0, 0)
85 if err := s.Convert(&in.Clusters, &out.Clusters, 0); err != nil {
88 out.AuthInfos = make([]NamedAuthInfo, 0, 0)
89 if err := s.Convert(&in.AuthInfos, &out.AuthInfos, 0); err != nil {
92 out.Contexts = make([]NamedContext, 0, 0)
93 if err := s.Convert(&in.Contexts, &out.Contexts, 0); err != nil {
96 out.Extensions = make([]NamedExtension, 0, 0)
97 if err := s.Convert(&in.Extensions, &out.Extensions, 0); err != nil {
102 func(in *[]NamedCluster, out *map[string]*api.Cluster, s conversion.Scope) error {
103 for _, curr := range *in {
104 newCluster := api.NewCluster()
105 if err := s.Convert(&curr.Cluster, newCluster, 0); err != nil {
108 (*out)[curr.Name] = newCluster
113 func(in *map[string]*api.Cluster, out *[]NamedCluster, s conversion.Scope) error {
114 allKeys := make([]string, 0, len(*in))
115 for key := range *in {
116 allKeys = append(allKeys, key)
118 sort.Strings(allKeys)
120 for _, key := range allKeys {
121 newCluster := (*in)[key]
122 oldCluster := &Cluster{}
123 if err := s.Convert(newCluster, oldCluster, 0); err != nil {
127 namedCluster := NamedCluster{key, *oldCluster}
128 *out = append(*out, namedCluster)
133 func(in *[]NamedAuthInfo, out *map[string]*api.AuthInfo, s conversion.Scope) error {
134 for _, curr := range *in {
135 newAuthInfo := api.NewAuthInfo()
136 if err := s.Convert(&curr.AuthInfo, newAuthInfo, 0); err != nil {
139 (*out)[curr.Name] = newAuthInfo
144 func(in *map[string]*api.AuthInfo, out *[]NamedAuthInfo, s conversion.Scope) error {
145 allKeys := make([]string, 0, len(*in))
146 for key := range *in {
147 allKeys = append(allKeys, key)
149 sort.Strings(allKeys)
151 for _, key := range allKeys {
152 newAuthInfo := (*in)[key]
153 oldAuthInfo := &AuthInfo{}
154 if err := s.Convert(newAuthInfo, oldAuthInfo, 0); err != nil {
158 namedAuthInfo := NamedAuthInfo{key, *oldAuthInfo}
159 *out = append(*out, namedAuthInfo)
164 func(in *[]NamedContext, out *map[string]*api.Context, s conversion.Scope) error {
165 for _, curr := range *in {
166 newContext := api.NewContext()
167 if err := s.Convert(&curr.Context, newContext, 0); err != nil {
170 (*out)[curr.Name] = newContext
175 func(in *map[string]*api.Context, out *[]NamedContext, s conversion.Scope) error {
176 allKeys := make([]string, 0, len(*in))
177 for key := range *in {
178 allKeys = append(allKeys, key)
180 sort.Strings(allKeys)
182 for _, key := range allKeys {
183 newContext := (*in)[key]
184 oldContext := &Context{}
185 if err := s.Convert(newContext, oldContext, 0); err != nil {
189 namedContext := NamedContext{key, *oldContext}
190 *out = append(*out, namedContext)
195 func(in *[]NamedExtension, out *map[string]runtime.Object, s conversion.Scope) error {
196 for _, curr := range *in {
197 var newExtension runtime.Object
198 if err := s.Convert(&curr.Extension, &newExtension, 0); err != nil {
201 (*out)[curr.Name] = newExtension
206 func(in *map[string]runtime.Object, out *[]NamedExtension, s conversion.Scope) error {
207 allKeys := make([]string, 0, len(*in))
208 for key := range *in {
209 allKeys = append(allKeys, key)
211 sort.Strings(allKeys)
213 for _, key := range allKeys {
214 newExtension := (*in)[key]
215 oldExtension := &runtime.RawExtension{}
216 if err := s.Convert(newExtension, oldExtension, 0); err != nil {
220 namedExtension := NamedExtension{key, *oldExtension}
221 *out = append(*out, namedExtension)
228 // If one of the conversion functions is malformed, detect it immediately.