1/*
2Copyright 2014 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package v1
18
19import (
20	"fmt"
21	"sort"
22
23	"k8s.io/apimachinery/pkg/conversion"
24	"k8s.io/apimachinery/pkg/runtime"
25	"k8s.io/client-go/tools/clientcmd/api"
26)
27
28func Convert_Slice_v1_NamedCluster_To_Map_string_To_Pointer_api_Cluster(in *[]NamedCluster, out *map[string]*api.Cluster, s conversion.Scope) error {
29	for _, curr := range *in {
30		newCluster := api.NewCluster()
31		if err := Convert_v1_Cluster_To_api_Cluster(&curr.Cluster, newCluster, s); err != nil {
32			return err
33		}
34		if *out == nil {
35			*out = make(map[string]*api.Cluster)
36		}
37		if (*out)[curr.Name] == nil {
38			(*out)[curr.Name] = newCluster
39		} else {
40			return fmt.Errorf("error converting *[]NamedCluster into *map[string]*api.Cluster: duplicate name \"%v\" in list: %v", curr.Name, *in)
41		}
42	}
43	return nil
44}
45
46func Convert_Map_string_To_Pointer_api_Cluster_To_Slice_v1_NamedCluster(in *map[string]*api.Cluster, out *[]NamedCluster, s conversion.Scope) error {
47	allKeys := make([]string, 0, len(*in))
48	for key := range *in {
49		allKeys = append(allKeys, key)
50	}
51	sort.Strings(allKeys)
52
53	for _, key := range allKeys {
54		newCluster := (*in)[key]
55		oldCluster := Cluster{}
56		if err := Convert_api_Cluster_To_v1_Cluster(newCluster, &oldCluster, s); err != nil {
57			return err
58		}
59		namedCluster := NamedCluster{key, oldCluster}
60		*out = append(*out, namedCluster)
61	}
62	return nil
63}
64
65func Convert_Slice_v1_NamedAuthInfo_To_Map_string_To_Pointer_api_AuthInfo(in *[]NamedAuthInfo, out *map[string]*api.AuthInfo, s conversion.Scope) error {
66	for _, curr := range *in {
67		newAuthInfo := api.NewAuthInfo()
68		if err := Convert_v1_AuthInfo_To_api_AuthInfo(&curr.AuthInfo, newAuthInfo, s); err != nil {
69			return err
70		}
71		if *out == nil {
72			*out = make(map[string]*api.AuthInfo)
73		}
74		if (*out)[curr.Name] == nil {
75			(*out)[curr.Name] = newAuthInfo
76		} else {
77			return fmt.Errorf("error converting *[]NamedAuthInfo into *map[string]*api.AuthInfo: duplicate name \"%v\" in list: %v", curr.Name, *in)
78		}
79	}
80	return nil
81}
82
83func Convert_Map_string_To_Pointer_api_AuthInfo_To_Slice_v1_NamedAuthInfo(in *map[string]*api.AuthInfo, out *[]NamedAuthInfo, s conversion.Scope) error {
84	allKeys := make([]string, 0, len(*in))
85	for key := range *in {
86		allKeys = append(allKeys, key)
87	}
88	sort.Strings(allKeys)
89
90	for _, key := range allKeys {
91		newAuthInfo := (*in)[key]
92		oldAuthInfo := AuthInfo{}
93		if err := Convert_api_AuthInfo_To_v1_AuthInfo(newAuthInfo, &oldAuthInfo, s); err != nil {
94			return err
95		}
96		namedAuthInfo := NamedAuthInfo{key, oldAuthInfo}
97		*out = append(*out, namedAuthInfo)
98	}
99	return nil
100}
101
102func Convert_Slice_v1_NamedContext_To_Map_string_To_Pointer_api_Context(in *[]NamedContext, out *map[string]*api.Context, s conversion.Scope) error {
103	for _, curr := range *in {
104		newContext := api.NewContext()
105		if err := Convert_v1_Context_To_api_Context(&curr.Context, newContext, s); err != nil {
106			return err
107		}
108		if *out == nil {
109			*out = make(map[string]*api.Context)
110		}
111		if (*out)[curr.Name] == nil {
112			(*out)[curr.Name] = newContext
113		} else {
114			return fmt.Errorf("error converting *[]NamedContext into *map[string]*api.Context: duplicate name \"%v\" in list: %v", curr.Name, *in)
115		}
116	}
117	return nil
118}
119
120func Convert_Map_string_To_Pointer_api_Context_To_Slice_v1_NamedContext(in *map[string]*api.Context, out *[]NamedContext, s conversion.Scope) error {
121	allKeys := make([]string, 0, len(*in))
122	for key := range *in {
123		allKeys = append(allKeys, key)
124	}
125	sort.Strings(allKeys)
126
127	for _, key := range allKeys {
128		newContext := (*in)[key]
129		oldContext := Context{}
130		if err := Convert_api_Context_To_v1_Context(newContext, &oldContext, s); err != nil {
131			return err
132		}
133		namedContext := NamedContext{key, oldContext}
134		*out = append(*out, namedContext)
135	}
136	return nil
137}
138
139func Convert_Slice_v1_NamedExtension_To_Map_string_To_runtime_Object(in *[]NamedExtension, out *map[string]runtime.Object, s conversion.Scope) error {
140	for _, curr := range *in {
141		var newExtension runtime.Object
142		if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&curr.Extension, &newExtension, s); err != nil {
143			return err
144		}
145		if *out == nil {
146			*out = make(map[string]runtime.Object)
147		}
148		if (*out)[curr.Name] == nil {
149			(*out)[curr.Name] = newExtension
150		} else {
151			return fmt.Errorf("error converting *[]NamedExtension into *map[string]runtime.Object: duplicate name \"%v\" in list: %v", curr.Name, *in)
152		}
153	}
154	return nil
155}
156
157func Convert_Map_string_To_runtime_Object_To_Slice_v1_NamedExtension(in *map[string]runtime.Object, out *[]NamedExtension, s conversion.Scope) error {
158	allKeys := make([]string, 0, len(*in))
159	for key := range *in {
160		allKeys = append(allKeys, key)
161	}
162	sort.Strings(allKeys)
163
164	for _, key := range allKeys {
165		newExtension := (*in)[key]
166		oldExtension := runtime.RawExtension{}
167		if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&newExtension, &oldExtension, s); err != nil {
168			return nil
169		}
170		namedExtension := NamedExtension{key, oldExtension}
171		*out = append(*out, namedExtension)
172	}
173	return nil
174}
175