From 5663294dc3a536293e162d3466593f49fc1a11ed Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Fri, 31 May 2024 12:43:21 +0600 Subject: [PATCH] Break import cycle Signed-off-by: Tamal Saha --- api/v1/{ => conversion}/conversion.go | 51 +++++++++++++-------------- api/v1/register.go | 29 --------------- 2 files changed, 24 insertions(+), 56 deletions(-) rename api/v1/{ => conversion}/conversion.go (80%) delete mode 100644 api/v1/register.go diff --git a/api/v1/conversion.go b/api/v1/conversion/conversion.go similarity index 80% rename from api/v1/conversion.go rename to api/v1/conversion/conversion.go index 4d0a71f..6bf1d19 100644 --- a/api/v1/conversion.go +++ b/api/v1/conversion/conversion.go @@ -14,11 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package conversion import ( "unsafe" + v1 "kmodules.xyz/offshoot-api/api/v1" v2 "kmodules.xyz/offshoot-api/api/v2" core "k8s.io/api/core/v1" @@ -27,58 +28,54 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) -func init() { - localSchemeBuilder.Register(RegisterConversions) -} - // RegisterConversions adds conversion functions to the given scheme. // Public to allow building arbitrary schemes. func RegisterConversions(s *runtime.Scheme) error { - if err := s.AddGeneratedConversionFunc((*ObjectMeta)(nil), (*metav1.ObjectMeta)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1_ObjectMeta_To_metav1_ObjectMeta(a.(*ObjectMeta), b.(*metav1.ObjectMeta), scope) + if err := s.AddGeneratedConversionFunc((*v1.ObjectMeta)(nil), (*metav1.ObjectMeta)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1_ObjectMeta_To_metav1_ObjectMeta(a.(*v1.ObjectMeta), b.(*metav1.ObjectMeta), scope) }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*metav1.ObjectMeta)(nil), (*ObjectMeta)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_metav1_ObjectMeta_To_v1_ObjectMeta(a.(*metav1.ObjectMeta), b.(*ObjectMeta), scope) + if err := s.AddGeneratedConversionFunc((*metav1.ObjectMeta)(nil), (*v1.ObjectMeta)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_metav1_ObjectMeta_To_v1_ObjectMeta(a.(*metav1.ObjectMeta), b.(*v1.ObjectMeta), scope) }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*PodSpec)(nil), (*v2.PodSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1_PodSpec_To_v2_PodSpec(a.(*PodSpec), b.(*v2.PodSpec), scope) + if err := s.AddGeneratedConversionFunc((*v1.PodSpec)(nil), (*v2.PodSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1_PodSpec_To_v2_PodSpec(a.(*v1.PodSpec), b.(*v2.PodSpec), scope) }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v2.PodSpec)(nil), (*PodSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v2_PodSpec_To_v1_PodSpec(a.(*v2.PodSpec), b.(*PodSpec), scope) + if err := s.AddGeneratedConversionFunc((*v2.PodSpec)(nil), (*v1.PodSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v2_PodSpec_To_v1_PodSpec(a.(*v2.PodSpec), b.(*v1.PodSpec), scope) }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*PodTemplateSpec)(nil), (*v2.PodTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1_PodTemplateSpec_To_v2_PodTemplateSpec(a.(*PodTemplateSpec), b.(*v2.PodTemplateSpec), scope) + if err := s.AddGeneratedConversionFunc((*v1.PodTemplateSpec)(nil), (*v2.PodTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1_PodTemplateSpec_To_v2_PodTemplateSpec(a.(*v1.PodTemplateSpec), b.(*v2.PodTemplateSpec), scope) }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v2.PodTemplateSpec)(nil), (*PodTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v2_PodTemplateSpec_To_v1_PodTemplateSpec(a.(*v2.PodTemplateSpec), b.(*PodTemplateSpec), scope) + if err := s.AddGeneratedConversionFunc((*v2.PodTemplateSpec)(nil), (*v1.PodTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v2_PodTemplateSpec_To_v1_PodTemplateSpec(a.(*v2.PodTemplateSpec), b.(*v1.PodTemplateSpec), scope) }); err != nil { return err } return nil } -func autoConvert_v1_ObjectMeta_To_metav1_ObjectMeta(in *ObjectMeta, out *metav1.ObjectMeta, s conversion.Scope) error { +func autoConvert_v1_ObjectMeta_To_metav1_ObjectMeta(in *v1.ObjectMeta, out *metav1.ObjectMeta, s conversion.Scope) error { out.Labels = *(*map[string]string)(unsafe.Pointer(&in.Labels)) out.Annotations = *(*map[string]string)(unsafe.Pointer(&in.Annotations)) return nil } // Convert_v1_ObjectMeta_To_v1_ObjectMeta is an autogenerated conversion function. -func Convert_v1_ObjectMeta_To_metav1_ObjectMeta(in *ObjectMeta, out *metav1.ObjectMeta, s conversion.Scope) error { +func Convert_v1_ObjectMeta_To_metav1_ObjectMeta(in *v1.ObjectMeta, out *metav1.ObjectMeta, s conversion.Scope) error { return autoConvert_v1_ObjectMeta_To_metav1_ObjectMeta(in, out, s) } -func autoConvert_metav1_ObjectMeta_To_v1_ObjectMeta(in *metav1.ObjectMeta, out *ObjectMeta, s conversion.Scope) error { +func autoConvert_metav1_ObjectMeta_To_v1_ObjectMeta(in *metav1.ObjectMeta, out *v1.ObjectMeta, s conversion.Scope) error { // WARNING: in.Name requires manual conversion: does not exist in peer-type // WARNING: in.GenerateName requires manual conversion: does not exist in peer-type // WARNING: in.Namespace requires manual conversion: does not exist in peer-type @@ -97,11 +94,11 @@ func autoConvert_metav1_ObjectMeta_To_v1_ObjectMeta(in *metav1.ObjectMeta, out * return nil } -func Convert_metav1_ObjectMeta_To_v1_ObjectMeta(in *metav1.ObjectMeta, out *ObjectMeta, s conversion.Scope) error { +func Convert_metav1_ObjectMeta_To_v1_ObjectMeta(in *metav1.ObjectMeta, out *v1.ObjectMeta, s conversion.Scope) error { return autoConvert_metav1_ObjectMeta_To_v1_ObjectMeta(in, out, s) } -func Convert_v1_PodSpec_To_v2_PodSpec(in *PodSpec, out *v2.PodSpec, s conversion.Scope) error { +func Convert_v1_PodSpec_To_v2_PodSpec(in *v1.PodSpec, out *v2.PodSpec, s conversion.Scope) error { if in.Volumes != nil { out.Volumes = in.Volumes } else { @@ -143,7 +140,7 @@ func Convert_v1_PodSpec_To_v2_PodSpec(in *PodSpec, out *v2.PodSpec, s conversion return nil } -func Convert_v2_PodSpec_To_v1_PodSpec(in *v2.PodSpec, out *PodSpec, s conversion.Scope) error { +func Convert_v2_PodSpec_To_v1_PodSpec(in *v2.PodSpec, out *v1.PodSpec, s conversion.Scope) error { if in.Volumes != nil { out.Volumes = in.Volumes } else { @@ -194,7 +191,7 @@ func Convert_v2_PodSpec_To_v1_PodSpec(in *v2.PodSpec, out *PodSpec, s conversion return nil } -func autoConvert_v1_PodTemplateSpec_To_v2_PodTemplateSpec(in *PodTemplateSpec, out *v2.PodTemplateSpec, s conversion.Scope) error { +func autoConvert_v1_PodTemplateSpec_To_v2_PodTemplateSpec(in *v1.PodTemplateSpec, out *v2.PodTemplateSpec, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta out.Controller = in.Controller if err := Convert_v1_PodSpec_To_v2_PodSpec(&in.Spec, &out.Spec, s); err != nil { @@ -204,11 +201,11 @@ func autoConvert_v1_PodTemplateSpec_To_v2_PodTemplateSpec(in *PodTemplateSpec, o } // Convert_v1_PodTemplateSpec_To_v2_PodTemplateSpec is an autogenerated conversion function. -func Convert_v1_PodTemplateSpec_To_v2_PodTemplateSpec(in *PodTemplateSpec, out *v2.PodTemplateSpec, s conversion.Scope) error { +func Convert_v1_PodTemplateSpec_To_v2_PodTemplateSpec(in *v1.PodTemplateSpec, out *v2.PodTemplateSpec, s conversion.Scope) error { return autoConvert_v1_PodTemplateSpec_To_v2_PodTemplateSpec(in, out, s) } -func autoConvert_v2_PodTemplateSpec_To_v1_PodTemplateSpec(in *v2.PodTemplateSpec, out *PodTemplateSpec, s conversion.Scope) error { +func autoConvert_v2_PodTemplateSpec_To_v1_PodTemplateSpec(in *v2.PodTemplateSpec, out *v1.PodTemplateSpec, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta out.Controller = in.Controller if err := Convert_v2_PodSpec_To_v1_PodSpec(&in.Spec, &out.Spec, s); err != nil { @@ -218,6 +215,6 @@ func autoConvert_v2_PodTemplateSpec_To_v1_PodTemplateSpec(in *v2.PodTemplateSpec } // Convert_v2_PodTemplateSpec_To_v1_PodTemplateSpec is an autogenerated conversion function. -func Convert_v2_PodTemplateSpec_To_v1_PodTemplateSpec(in *v2.PodTemplateSpec, out *PodTemplateSpec, s conversion.Scope) error { +func Convert_v2_PodTemplateSpec_To_v1_PodTemplateSpec(in *v2.PodTemplateSpec, out *v1.PodTemplateSpec, s conversion.Scope) error { return autoConvert_v2_PodTemplateSpec_To_v1_PodTemplateSpec(in, out, s) } diff --git a/api/v1/register.go b/api/v1/register.go deleted file mode 100644 index d20744a..0000000 --- a/api/v1/register.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright AppsCode Inc. and Contributors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - "k8s.io/apimachinery/pkg/runtime" -) - -var ( - // TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api. - // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. - SchemeBuilder runtime.SchemeBuilder - localSchemeBuilder = &SchemeBuilder - AddToScheme = localSchemeBuilder.AddToScheme -)