Cleanup clientcmd conversion

Kubernetes-commit: 328295c635449746ca83ac0fb2c9217491d59600
This commit is contained in:
wojtekt 2019-10-29 09:30:27 +01:00 committed by Kubernetes Publisher
parent 1a481fb1e3
commit cc78c193ee
4 changed files with 139 additions and 217 deletions

View File

@ -64,6 +64,7 @@ type Preferences struct {
// Cluster contains information about how to communicate with a kubernetes cluster // Cluster contains information about how to communicate with a kubernetes cluster
type Cluster struct { type Cluster struct {
// LocationOfOrigin indicates where this object came from. It is used for round tripping config post-merge, but never serialized. // LocationOfOrigin indicates where this object came from. It is used for round tripping config post-merge, but never serialized.
// +k8s:conversion-gen=false
LocationOfOrigin string LocationOfOrigin string
// Server is the address of the kubernetes cluster (https://hostname:port). // Server is the address of the kubernetes cluster (https://hostname:port).
Server string `json:"server"` Server string `json:"server"`
@ -84,6 +85,7 @@ type Cluster struct {
// AuthInfo contains information that describes identity information. This is use to tell the kubernetes cluster who you are. // AuthInfo contains information that describes identity information. This is use to tell the kubernetes cluster who you are.
type AuthInfo struct { type AuthInfo struct {
// LocationOfOrigin indicates where this object came from. It is used for round tripping config post-merge, but never serialized. // LocationOfOrigin indicates where this object came from. It is used for round tripping config post-merge, but never serialized.
// +k8s:conversion-gen=false
LocationOfOrigin string LocationOfOrigin string
// ClientCertificate is the path to a client cert file for TLS. // ClientCertificate is the path to a client cert file for TLS.
// +optional // +optional
@ -132,6 +134,7 @@ type AuthInfo struct {
// 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) // 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)
type Context struct { type Context struct {
// LocationOfOrigin indicates where this object came from. It is used for round tripping config post-merge, but never serialized. // LocationOfOrigin indicates where this object came from. It is used for round tripping config post-merge, but never serialized.
// +k8s:conversion-gen=false
LocationOfOrigin string LocationOfOrigin string
// Cluster is the name of the cluster for this context // Cluster is the name of the cluster for this context
Cluster string `json:"cluster"` Cluster string `json:"cluster"`

View File

@ -25,220 +25,138 @@ import (
"k8s.io/client-go/tools/clientcmd/api" "k8s.io/client-go/tools/clientcmd/api"
) )
func addConversionFuncs(scheme *runtime.Scheme) error { func Convert_Slice_v1_NamedCluster_To_Map_string_To_Pointer_api_Cluster(in *[]NamedCluster, out *map[string]*api.Cluster, s conversion.Scope) error {
return scheme.AddConversionFuncs( for _, curr := range *in {
func(in *Cluster, out *api.Cluster, s conversion.Scope) error { newCluster := api.NewCluster()
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) if err := Convert_v1_Cluster_To_api_Cluster(&curr.Cluster, newCluster, s); err != nil {
}, return err
func(in *api.Cluster, out *Cluster, s conversion.Scope) error { }
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) if (*out)[curr.Name] == nil {
}, (*out)[curr.Name] = newCluster
func(in *Preferences, out *api.Preferences, s conversion.Scope) error { } else {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) return fmt.Errorf("error converting *[]NamedCluster into *map[string]*api.Cluster: duplicate name \"%v\" in list: %v", curr.Name, *in)
}, }
func(in *api.Preferences, out *Preferences, s conversion.Scope) error { }
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) return nil
}, }
func(in *AuthInfo, out *api.AuthInfo, s conversion.Scope) error {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) func Convert_Map_string_To_Pointer_api_Cluster_To_Slice_v1_NamedCluster(in *map[string]*api.Cluster, out *[]NamedCluster, s conversion.Scope) error {
}, allKeys := make([]string, 0, len(*in))
func(in *api.AuthInfo, out *AuthInfo, s conversion.Scope) error { for key := range *in {
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) allKeys = append(allKeys, key)
}, }
func(in *Context, out *api.Context, s conversion.Scope) error { sort.Strings(allKeys)
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}, for _, key := range allKeys {
func(in *api.Context, out *Context, s conversion.Scope) error { newCluster := (*in)[key]
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields) oldCluster := Cluster{}
}, if err := Convert_api_Cluster_To_v1_Cluster(newCluster, &oldCluster, s); err != nil {
return err
func(in *Config, out *api.Config, s conversion.Scope) error { }
out.CurrentContext = in.CurrentContext namedCluster := NamedCluster{key, oldCluster}
if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil { *out = append(*out, namedCluster)
return err }
} return nil
}
out.Clusters = make(map[string]*api.Cluster)
if err := s.Convert(&in.Clusters, &out.Clusters, 0); err != nil { func Convert_Slice_v1_NamedAuthInfo_To_Map_string_To_Pointer_api_AuthInfo(in *[]NamedAuthInfo, out *map[string]*api.AuthInfo, s conversion.Scope) error {
return err for _, curr := range *in {
} newAuthInfo := api.NewAuthInfo()
out.AuthInfos = make(map[string]*api.AuthInfo) if err := Convert_v1_AuthInfo_To_api_AuthInfo(&curr.AuthInfo, newAuthInfo, s); err != nil {
if err := s.Convert(&in.AuthInfos, &out.AuthInfos, 0); err != nil { return err
return err }
} if (*out)[curr.Name] == nil {
out.Contexts = make(map[string]*api.Context) (*out)[curr.Name] = newAuthInfo
if err := s.Convert(&in.Contexts, &out.Contexts, 0); err != nil { } else {
return err return fmt.Errorf("error converting *[]NamedAuthInfo into *map[string]*api.AuthInfo: duplicate name \"%v\" in list: %v", curr.Name, *in)
} }
out.Extensions = make(map[string]runtime.Object) }
if err := s.Convert(&in.Extensions, &out.Extensions, 0); err != nil { return nil
return err }
}
return nil func Convert_Map_string_To_Pointer_api_AuthInfo_To_Slice_v1_NamedAuthInfo(in *map[string]*api.AuthInfo, out *[]NamedAuthInfo, s conversion.Scope) error {
}, allKeys := make([]string, 0, len(*in))
func(in *api.Config, out *Config, s conversion.Scope) error { for key := range *in {
out.CurrentContext = in.CurrentContext allKeys = append(allKeys, key)
if err := s.Convert(&in.Preferences, &out.Preferences, 0); err != nil { }
return err sort.Strings(allKeys)
}
for _, key := range allKeys {
out.Clusters = make([]NamedCluster, 0, 0) newAuthInfo := (*in)[key]
if err := s.Convert(&in.Clusters, &out.Clusters, 0); err != nil { oldAuthInfo := AuthInfo{}
return err if err := Convert_api_AuthInfo_To_v1_AuthInfo(newAuthInfo, &oldAuthInfo, s); err != nil {
} return err
out.AuthInfos = make([]NamedAuthInfo, 0, 0) }
if err := s.Convert(&in.AuthInfos, &out.AuthInfos, 0); err != nil { namedAuthInfo := NamedAuthInfo{key, oldAuthInfo}
return err *out = append(*out, namedAuthInfo)
} }
out.Contexts = make([]NamedContext, 0, 0) return nil
if err := s.Convert(&in.Contexts, &out.Contexts, 0); err != nil { }
return err
} func Convert_Slice_v1_NamedContext_To_Map_string_To_Pointer_api_Context(in *[]NamedContext, out *map[string]*api.Context, s conversion.Scope) error {
out.Extensions = make([]NamedExtension, 0, 0) for _, curr := range *in {
if err := s.Convert(&in.Extensions, &out.Extensions, 0); err != nil { newContext := api.NewContext()
return err if err := Convert_v1_Context_To_api_Context(&curr.Context, newContext, s); err != nil {
} return err
return nil }
}, if (*out)[curr.Name] == nil {
func(in *[]NamedCluster, out *map[string]*api.Cluster, s conversion.Scope) error { (*out)[curr.Name] = newContext
for _, curr := range *in { } else {
newCluster := api.NewCluster() return fmt.Errorf("error converting *[]NamedContext into *map[string]*api.Context: duplicate name \"%v\" in list: %v", curr.Name, *in)
if err := s.Convert(&curr.Cluster, newCluster, 0); err != nil { }
return err }
} return nil
if (*out)[curr.Name] == nil { }
(*out)[curr.Name] = newCluster
} else { func Convert_Map_string_To_Pointer_api_Context_To_Slice_v1_NamedContext(in *map[string]*api.Context, out *[]NamedContext, s conversion.Scope) error {
return fmt.Errorf("error converting *[]NamedCluster into *map[string]*api.Cluster: duplicate name \"%v\" in list: %v", curr.Name, *in) allKeys := make([]string, 0, len(*in))
} for key := range *in {
} allKeys = append(allKeys, key)
}
return nil sort.Strings(allKeys)
},
func(in *map[string]*api.Cluster, out *[]NamedCluster, s conversion.Scope) error { for _, key := range allKeys {
allKeys := make([]string, 0, len(*in)) newContext := (*in)[key]
for key := range *in { oldContext := Context{}
allKeys = append(allKeys, key) if err := Convert_api_Context_To_v1_Context(newContext, &oldContext, s); err != nil {
} return err
sort.Strings(allKeys) }
namedContext := NamedContext{key, oldContext}
for _, key := range allKeys { *out = append(*out, namedContext)
newCluster := (*in)[key] }
oldCluster := &Cluster{} return nil
if err := s.Convert(newCluster, oldCluster, 0); err != nil { }
return err
} func Convert_Slice_v1_NamedExtension_To_Map_string_To_runtime_Object(in *[]NamedExtension, out *map[string]runtime.Object, s conversion.Scope) error {
for _, curr := range *in {
namedCluster := NamedCluster{key, *oldCluster} var newExtension runtime.Object
*out = append(*out, namedCluster) if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&curr.Extension, &newExtension, s); err != nil {
} return err
}
return nil if (*out)[curr.Name] == nil {
}, (*out)[curr.Name] = newExtension
func(in *[]NamedAuthInfo, out *map[string]*api.AuthInfo, s conversion.Scope) error { } else {
for _, curr := range *in { return fmt.Errorf("error converting *[]NamedExtension into *map[string]runtime.Object: duplicate name \"%v\" in list: %v", curr.Name, *in)
newAuthInfo := api.NewAuthInfo() }
if err := s.Convert(&curr.AuthInfo, newAuthInfo, 0); err != nil { }
return err return nil
} }
if (*out)[curr.Name] == nil {
(*out)[curr.Name] = newAuthInfo func Convert_Map_string_To_runtime_Object_To_Slice_v1_NamedExtension(in *map[string]runtime.Object, out *[]NamedExtension, s conversion.Scope) error {
} else { allKeys := make([]string, 0, len(*in))
return fmt.Errorf("error converting *[]NamedAuthInfo into *map[string]*api.AuthInfo: duplicate name \"%v\" in list: %v", curr.Name, *in) for key := range *in {
} allKeys = append(allKeys, key)
} }
sort.Strings(allKeys)
return nil
}, for _, key := range allKeys {
func(in *map[string]*api.AuthInfo, out *[]NamedAuthInfo, s conversion.Scope) error { newExtension := (*in)[key]
allKeys := make([]string, 0, len(*in)) oldExtension := runtime.RawExtension{}
for key := range *in { if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&newExtension, &oldExtension, s); err != nil {
allKeys = append(allKeys, key) return nil
} }
sort.Strings(allKeys) namedExtension := NamedExtension{key, oldExtension}
*out = append(*out, namedExtension)
for _, key := range allKeys { }
newAuthInfo := (*in)[key] return nil
oldAuthInfo := &AuthInfo{}
if err := s.Convert(newAuthInfo, oldAuthInfo, 0); err != nil {
return err
}
namedAuthInfo := NamedAuthInfo{key, *oldAuthInfo}
*out = append(*out, namedAuthInfo)
}
return nil
},
func(in *[]NamedContext, out *map[string]*api.Context, s conversion.Scope) error {
for _, curr := range *in {
newContext := api.NewContext()
if err := s.Convert(&curr.Context, newContext, 0); err != nil {
return err
}
if (*out)[curr.Name] == nil {
(*out)[curr.Name] = newContext
} else {
return fmt.Errorf("error converting *[]NamedContext into *map[string]*api.Context: duplicate name \"%v\" in list: %v", curr.Name, *in)
}
}
return nil
},
func(in *map[string]*api.Context, out *[]NamedContext, s conversion.Scope) error {
allKeys := make([]string, 0, len(*in))
for key := range *in {
allKeys = append(allKeys, key)
}
sort.Strings(allKeys)
for _, key := range allKeys {
newContext := (*in)[key]
oldContext := &Context{}
if err := s.Convert(newContext, oldContext, 0); err != nil {
return err
}
namedContext := NamedContext{key, *oldContext}
*out = append(*out, namedContext)
}
return nil
},
func(in *[]NamedExtension, out *map[string]runtime.Object, s conversion.Scope) error {
for _, curr := range *in {
var newExtension runtime.Object
if err := s.Convert(&curr.Extension, &newExtension, 0); err != nil {
return err
}
if (*out)[curr.Name] == nil {
(*out)[curr.Name] = newExtension
} else {
return fmt.Errorf("error converting *[]NamedExtension into *map[string]runtime.Object: duplicate name \"%v\" in list: %v", curr.Name, *in)
}
}
return nil
},
func(in *map[string]runtime.Object, out *[]NamedExtension, s conversion.Scope) error {
allKeys := make([]string, 0, len(*in))
for key := range *in {
allKeys = append(allKeys, key)
}
sort.Strings(allKeys)
for _, key := range allKeys {
newExtension := (*in)[key]
oldExtension := &runtime.RawExtension{}
if err := s.Convert(newExtension, oldExtension, 0); err != nil {
return err
}
namedExtension := NamedExtension{key, *oldExtension}
*out = append(*out, namedExtension)
}
return nil
},
)
} }

View File

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// +k8s:conversion-gen=k8s.io/client-go/tools/clientcmd/api
// +k8s:deepcopy-gen=package // +k8s:deepcopy-gen=package
package v1 package v1

View File

@ -37,7 +37,7 @@ func init() {
// We only register manually written functions here. The registration of the // We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation // generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing. // makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(addKnownTypes, addConversionFuncs) localSchemeBuilder.Register(addKnownTypes)
} }
func addKnownTypes(scheme *runtime.Scheme) error { func addKnownTypes(scheme *runtime.Scheme) error {