Skip to content

Commit 07023f2

Browse files
authored
Merge pull request kubernetes#84503 from wojtek-t/remove_conversion_funcs_2
Cleanup clientcmd api conversions
2 parents 4b95ea0 + c7916ca commit 07023f2

File tree

7 files changed

+560
-209
lines changed

7 files changed

+560
-209
lines changed

staging/src/k8s.io/client-go/tools/clientcmd/api/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ import (
3131
type Config struct {
3232
// Legacy field from pkg/api/types.go TypeMeta.
3333
// TODO(jlowdermilk): remove this after eliminating downstream dependencies.
34+
// +k8s:conversion-gen=false
3435
// +optional
3536
Kind string `json:"kind,omitempty"`
3637
// Legacy field from pkg/api/types.go TypeMeta.
3738
// TODO(jlowdermilk): remove this after eliminating downstream dependencies.
39+
// +k8s:conversion-gen=false
3840
// +optional
3941
APIVersion string `json:"apiVersion,omitempty"`
4042
// Preferences holds general information to be use for cli interactions
@@ -64,6 +66,7 @@ type Preferences struct {
6466
// Cluster contains information about how to communicate with a kubernetes cluster
6567
type Cluster struct {
6668
// LocationOfOrigin indicates where this object came from. It is used for round tripping config post-merge, but never serialized.
69+
// +k8s:conversion-gen=false
6770
LocationOfOrigin string
6871
// Server is the address of the kubernetes cluster (https://hostname:port).
6972
Server string `json:"server"`
@@ -84,6 +87,7 @@ type Cluster struct {
8487
// AuthInfo contains information that describes identity information. This is use to tell the kubernetes cluster who you are.
8588
type AuthInfo struct {
8689
// LocationOfOrigin indicates where this object came from. It is used for round tripping config post-merge, but never serialized.
90+
// +k8s:conversion-gen=false
8791
LocationOfOrigin string
8892
// ClientCertificate is the path to a client cert file for TLS.
8993
// +optional
@@ -132,6 +136,7 @@ type AuthInfo struct {
132136
// Context is a tuple of references to a cluster (how do I communicate with a kubernetes cluster), a user (how do I identify myself), and a namespace (what subset of resources do I want to work with)
133137
type Context struct {
134138
// LocationOfOrigin indicates where this object came from. It is used for round tripping config post-merge, but never serialized.
139+
// +k8s:conversion-gen=false
135140
LocationOfOrigin string
136141
// Cluster is the name of the cluster for this context
137142
Cluster string `json:"cluster"`

staging/src/k8s.io/client-go/tools/clientcmd/api/v1/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ go_library(
1212
"doc.go",
1313
"register.go",
1414
"types.go",
15+
"zz_generated.conversion.go",
1516
"zz_generated.deepcopy.go",
1617
],
1718
importmap = "k8s.io/kubernetes/vendor/k8s.io/client-go/tools/clientcmd/api/v1",

staging/src/k8s.io/client-go/tools/clientcmd/api/v1/conversion.go

Lines changed: 126 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -25,220 +25,138 @@ import (
2525
"k8s.io/client-go/tools/clientcmd/api"
2626
)
2727

28-
func addConversionFuncs(scheme *runtime.Scheme) error {
29-
return scheme.AddConversionFuncs(
30-
func(in *Cluster, out *api.Cluster, s conversion.Scope) error {
31-
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
32-
},
33-
func(in *api.Cluster, out *Cluster, s conversion.Scope) error {
34-
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
35-
},
36-
func(in *Preferences, out *api.Preferences, s conversion.Scope) error {
37-
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
38-
},
39-
func(in *api.Preferences, out *Preferences, s conversion.Scope) error {
40-
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
41-
},
42-
func(in *AuthInfo, out *api.AuthInfo, s conversion.Scope) error {
43-
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
44-
},
45-
func(in *api.AuthInfo, out *AuthInfo, s conversion.Scope) error {
46-
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
47-
},
48-
func(in *Context, out *api.Context, s conversion.Scope) error {
49-
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
50-
},
51-
func(in *api.Context, out *Context, s conversion.Scope) error {
52-
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
53-
},
54-
55-
func(in *Config, out *api.Config, s conversion.Scope) error {
56-
out.CurrentContext = in.CurrentContext
57-
if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil {
58-
return err
59-
}
60-
61-
out.Clusters = make(map[string]*api.Cluster)
62-
if err := s.Convert(&in.Clusters, &out.Clusters, 0); err != nil {
63-
return err
64-
}
65-
out.AuthInfos = make(map[string]*api.AuthInfo)
66-
if err := s.Convert(&in.AuthInfos, &out.AuthInfos, 0); err != nil {
67-
return err
68-
}
69-
out.Contexts = make(map[string]*api.Context)
70-
if err := s.Convert(&in.Contexts, &out.Contexts, 0); err != nil {
71-
return err
72-
}
73-
out.Extensions = make(map[string]runtime.Object)
74-
if err := s.Convert(&in.Extensions, &out.Extensions, 0); err != nil {
75-
return err
76-
}
77-
return nil
78-
},
79-
func(in *api.Config, out *Config, s conversion.Scope) error {
80-
out.CurrentContext = in.CurrentContext
81-
if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil {
82-
return err
83-
}
84-
85-
out.Clusters = make([]NamedCluster, 0, 0)
86-
if err := s.Convert(&in.Clusters, &out.Clusters, 0); err != nil {
87-
return err
88-
}
89-
out.AuthInfos = make([]NamedAuthInfo, 0, 0)
90-
if err := s.Convert(&in.AuthInfos, &out.AuthInfos, 0); err != nil {
91-
return err
92-
}
93-
out.Contexts = make([]NamedContext, 0, 0)
94-
if err := s.Convert(&in.Contexts, &out.Contexts, 0); err != nil {
95-
return err
96-
}
97-
out.Extensions = make([]NamedExtension, 0, 0)
98-
if err := s.Convert(&in.Extensions, &out.Extensions, 0); err != nil {
99-
return err
100-
}
101-
return nil
102-
},
103-
func(in *[]NamedCluster, out *map[string]*api.Cluster, s conversion.Scope) error {
104-
for _, curr := range *in {
105-
newCluster := api.NewCluster()
106-
if err := s.Convert(&curr.Cluster, newCluster, 0); err != nil {
107-
return err
108-
}
109-
if (*out)[curr.Name] == nil {
110-
(*out)[curr.Name] = newCluster
111-
} else {
112-
return fmt.Errorf("error converting *[]NamedCluster into *map[string]*api.Cluster: duplicate name \"%v\" in list: %v", curr.Name, *in)
113-
}
114-
}
115-
116-
return nil
117-
},
118-
func(in *map[string]*api.Cluster, out *[]NamedCluster, s conversion.Scope) error {
119-
allKeys := make([]string, 0, len(*in))
120-
for key := range *in {
121-
allKeys = append(allKeys, key)
122-
}
123-
sort.Strings(allKeys)
124-
125-
for _, key := range allKeys {
126-
newCluster := (*in)[key]
127-
oldCluster := &Cluster{}
128-
if err := s.Convert(newCluster, oldCluster, 0); err != nil {
129-
return err
130-
}
131-
132-
namedCluster := NamedCluster{key, *oldCluster}
133-
*out = append(*out, namedCluster)
134-
}
28+
func 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)[curr.Name] == nil {
35+
(*out)[curr.Name] = newCluster
36+
} else {
37+
return fmt.Errorf("error converting *[]NamedCluster into *map[string]*api.Cluster: duplicate name \"%v\" in list: %v", curr.Name, *in)
38+
}
39+
}
40+
return nil
41+
}
13542

136-
return nil
137-
},
138-
func(in *[]NamedAuthInfo, out *map[string]*api.AuthInfo, s conversion.Scope) error {
139-
for _, curr := range *in {
140-
newAuthInfo := api.NewAuthInfo()
141-
if err := s.Convert(&curr.AuthInfo, newAuthInfo, 0); err != nil {
142-
return err
143-
}
144-
if (*out)[curr.Name] == nil {
145-
(*out)[curr.Name] = newAuthInfo
146-
} else {
147-
return fmt.Errorf("error converting *[]NamedAuthInfo into *map[string]*api.AuthInfo: duplicate name \"%v\" in list: %v", curr.Name, *in)
148-
}
149-
}
43+
func Convert_Map_string_To_Pointer_api_Cluster_To_Slice_v1_NamedCluster(in *map[string]*api.Cluster, out *[]NamedCluster, s conversion.Scope) error {
44+
allKeys := make([]string, 0, len(*in))
45+
for key := range *in {
46+
allKeys = append(allKeys, key)
47+
}
48+
sort.Strings(allKeys)
49+
50+
for _, key := range allKeys {
51+
newCluster := (*in)[key]
52+
oldCluster := Cluster{}
53+
if err := Convert_api_Cluster_To_v1_Cluster(newCluster, &oldCluster, s); err != nil {
54+
return err
55+
}
56+
namedCluster := NamedCluster{key, oldCluster}
57+
*out = append(*out, namedCluster)
58+
}
59+
return nil
60+
}
15061

151-
return nil
152-
},
153-
func(in *map[string]*api.AuthInfo, out *[]NamedAuthInfo, s conversion.Scope) error {
154-
allKeys := make([]string, 0, len(*in))
155-
for key := range *in {
156-
allKeys = append(allKeys, key)
157-
}
158-
sort.Strings(allKeys)
159-
160-
for _, key := range allKeys {
161-
newAuthInfo := (*in)[key]
162-
oldAuthInfo := &AuthInfo{}
163-
if err := s.Convert(newAuthInfo, oldAuthInfo, 0); err != nil {
164-
return err
165-
}
166-
167-
namedAuthInfo := NamedAuthInfo{key, *oldAuthInfo}
168-
*out = append(*out, namedAuthInfo)
169-
}
62+
func Convert_Slice_v1_NamedAuthInfo_To_Map_string_To_Pointer_api_AuthInfo(in *[]NamedAuthInfo, out *map[string]*api.AuthInfo, s conversion.Scope) error {
63+
for _, curr := range *in {
64+
newAuthInfo := api.NewAuthInfo()
65+
if err := Convert_v1_AuthInfo_To_api_AuthInfo(&curr.AuthInfo, newAuthInfo, s); err != nil {
66+
return err
67+
}
68+
if (*out)[curr.Name] == nil {
69+
(*out)[curr.Name] = newAuthInfo
70+
} else {
71+
return fmt.Errorf("error converting *[]NamedAuthInfo into *map[string]*api.AuthInfo: duplicate name \"%v\" in list: %v", curr.Name, *in)
72+
}
73+
}
74+
return nil
75+
}
17076

171-
return nil
172-
},
173-
func(in *[]NamedContext, out *map[string]*api.Context, s conversion.Scope) error {
174-
for _, curr := range *in {
175-
newContext := api.NewContext()
176-
if err := s.Convert(&curr.Context, newContext, 0); err != nil {
177-
return err
178-
}
179-
if (*out)[curr.Name] == nil {
180-
(*out)[curr.Name] = newContext
181-
} else {
182-
return fmt.Errorf("error converting *[]NamedContext into *map[string]*api.Context: duplicate name \"%v\" in list: %v", curr.Name, *in)
183-
}
184-
}
77+
func Convert_Map_string_To_Pointer_api_AuthInfo_To_Slice_v1_NamedAuthInfo(in *map[string]*api.AuthInfo, out *[]NamedAuthInfo, s conversion.Scope) error {
78+
allKeys := make([]string, 0, len(*in))
79+
for key := range *in {
80+
allKeys = append(allKeys, key)
81+
}
82+
sort.Strings(allKeys)
83+
84+
for _, key := range allKeys {
85+
newAuthInfo := (*in)[key]
86+
oldAuthInfo := AuthInfo{}
87+
if err := Convert_api_AuthInfo_To_v1_AuthInfo(newAuthInfo, &oldAuthInfo, s); err != nil {
88+
return err
89+
}
90+
namedAuthInfo := NamedAuthInfo{key, oldAuthInfo}
91+
*out = append(*out, namedAuthInfo)
92+
}
93+
return nil
94+
}
18595

186-
return nil
187-
},
188-
func(in *map[string]*api.Context, out *[]NamedContext, s conversion.Scope) error {
189-
allKeys := make([]string, 0, len(*in))
190-
for key := range *in {
191-
allKeys = append(allKeys, key)
192-
}
193-
sort.Strings(allKeys)
194-
195-
for _, key := range allKeys {
196-
newContext := (*in)[key]
197-
oldContext := &Context{}
198-
if err := s.Convert(newContext, oldContext, 0); err != nil {
199-
return err
200-
}
201-
202-
namedContext := NamedContext{key, *oldContext}
203-
*out = append(*out, namedContext)
204-
}
96+
func Convert_Slice_v1_NamedContext_To_Map_string_To_Pointer_api_Context(in *[]NamedContext, out *map[string]*api.Context, s conversion.Scope) error {
97+
for _, curr := range *in {
98+
newContext := api.NewContext()
99+
if err := Convert_v1_Context_To_api_Context(&curr.Context, newContext, s); err != nil {
100+
return err
101+
}
102+
if (*out)[curr.Name] == nil {
103+
(*out)[curr.Name] = newContext
104+
} else {
105+
return fmt.Errorf("error converting *[]NamedContext into *map[string]*api.Context: duplicate name \"%v\" in list: %v", curr.Name, *in)
106+
}
107+
}
108+
return nil
109+
}
205110

206-
return nil
207-
},
208-
func(in *[]NamedExtension, out *map[string]runtime.Object, s conversion.Scope) error {
209-
for _, curr := range *in {
210-
var newExtension runtime.Object
211-
if err := s.Convert(&curr.Extension, &newExtension, 0); err != nil {
212-
return err
213-
}
214-
if (*out)[curr.Name] == nil {
215-
(*out)[curr.Name] = newExtension
216-
} else {
217-
return fmt.Errorf("error converting *[]NamedExtension into *map[string]runtime.Object: duplicate name \"%v\" in list: %v", curr.Name, *in)
218-
}
219-
}
111+
func Convert_Map_string_To_Pointer_api_Context_To_Slice_v1_NamedContext(in *map[string]*api.Context, out *[]NamedContext, s conversion.Scope) error {
112+
allKeys := make([]string, 0, len(*in))
113+
for key := range *in {
114+
allKeys = append(allKeys, key)
115+
}
116+
sort.Strings(allKeys)
117+
118+
for _, key := range allKeys {
119+
newContext := (*in)[key]
120+
oldContext := Context{}
121+
if err := Convert_api_Context_To_v1_Context(newContext, &oldContext, s); err != nil {
122+
return err
123+
}
124+
namedContext := NamedContext{key, oldContext}
125+
*out = append(*out, namedContext)
126+
}
127+
return nil
128+
}
220129

221-
return nil
222-
},
223-
func(in *map[string]runtime.Object, out *[]NamedExtension, s conversion.Scope) error {
224-
allKeys := make([]string, 0, len(*in))
225-
for key := range *in {
226-
allKeys = append(allKeys, key)
227-
}
228-
sort.Strings(allKeys)
229-
230-
for _, key := range allKeys {
231-
newExtension := (*in)[key]
232-
oldExtension := &runtime.RawExtension{}
233-
if err := s.Convert(newExtension, oldExtension, 0); err != nil {
234-
return err
235-
}
236-
237-
namedExtension := NamedExtension{key, *oldExtension}
238-
*out = append(*out, namedExtension)
239-
}
130+
func Convert_Slice_v1_NamedExtension_To_Map_string_To_runtime_Object(in *[]NamedExtension, out *map[string]runtime.Object, s conversion.Scope) error {
131+
for _, curr := range *in {
132+
var newExtension runtime.Object
133+
if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&curr.Extension, &newExtension, s); err != nil {
134+
return err
135+
}
136+
if (*out)[curr.Name] == nil {
137+
(*out)[curr.Name] = newExtension
138+
} else {
139+
return fmt.Errorf("error converting *[]NamedExtension into *map[string]runtime.Object: duplicate name \"%v\" in list: %v", curr.Name, *in)
140+
}
141+
}
142+
return nil
143+
}
240144

145+
func Convert_Map_string_To_runtime_Object_To_Slice_v1_NamedExtension(in *map[string]runtime.Object, out *[]NamedExtension, s conversion.Scope) error {
146+
allKeys := make([]string, 0, len(*in))
147+
for key := range *in {
148+
allKeys = append(allKeys, key)
149+
}
150+
sort.Strings(allKeys)
151+
152+
for _, key := range allKeys {
153+
newExtension := (*in)[key]
154+
oldExtension := runtime.RawExtension{}
155+
if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&newExtension, &oldExtension, s); err != nil {
241156
return nil
242-
},
243-
)
157+
}
158+
namedExtension := NamedExtension{key, oldExtension}
159+
*out = append(*out, namedExtension)
160+
}
161+
return nil
244162
}

staging/src/k8s.io/client-go/tools/clientcmd/api/v1/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// +k8s:conversion-gen=k8s.io/client-go/tools/clientcmd/api
1718
// +k8s:deepcopy-gen=package
1819

1920
package v1

0 commit comments

Comments
 (0)