diff --git a/pkg/apis/addtoscheme_raven_v1alpha1.go b/pkg/apis/addtoscheme_raven_v1alpha1.go index cbcf05fb284..c708293be82 100644 --- a/pkg/apis/addtoscheme_raven_v1alpha1.go +++ b/pkg/apis/addtoscheme_raven_v1alpha1.go @@ -17,8 +17,7 @@ limitations under the License. package apis import ( - v3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3" - + v3 "github.com/openyurtio/openyurt/pkg/apis/calico/v3" version "github.com/openyurtio/openyurt/pkg/apis/raven/v1alpha1" ) diff --git a/pkg/apis/calico/v3/blockaffinity.go b/pkg/apis/calico/v3/blockaffinity.go new file mode 100644 index 00000000000..087cfbf4828 --- /dev/null +++ b/pkg/apis/calico/v3/blockaffinity.go @@ -0,0 +1,82 @@ +/* +Copyright 2023 The OpenYurt Authors. + +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 v3 + +import ( + apiv3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const ( + KindBlockAffinity = "BlockAffinity" + KindBlockAffinityList = "BlockAffinityList" +) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// BlockAffinity maintains a block affinity's state +type BlockAffinity struct { + metav1.TypeMeta `json:",inline"` + // Standard object's metadata. + metav1.ObjectMeta `json:"metadata,omitempty"` + // Specification of the BlockAffinity. + Spec BlockAffinitySpec `json:"spec,omitempty"` +} + +// BlockAffinitySpec contains the specification for a BlockAffinity resource. +type BlockAffinitySpec struct { + State string `json:"state"` + Node string `json:"node"` + CIDR string `json:"cidr"` + + // Deleted indicates that this block affinity is being deleted. + // This field is a string for compatibility with older releases that + // mistakenly treat this field as a string. + Deleted string `json:"deleted"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// BlockAffinityList contains a list of BlockAffinity resources. +type BlockAffinityList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + Items []BlockAffinity `json:"items"` +} + +// NewBlockAffinity creates a new (zeroed) BlockAffinity struct with the TypeMetadata initialised to the current +// version. +func NewBlockAffinity() *BlockAffinity { + return &BlockAffinity{ + TypeMeta: metav1.TypeMeta{ + Kind: KindBlockAffinity, + APIVersion: apiv3.GroupVersionCurrent, + }, + } +} + +// NewBlockAffinityList creates a new (zeroed) BlockAffinityList struct with the TypeMetadata initialised to the current +// version. +func NewBlockAffinityList() *BlockAffinityList { + return &BlockAffinityList{ + TypeMeta: metav1.TypeMeta{ + Kind: KindBlockAffinityList, + APIVersion: apiv3.GroupVersionCurrent, + }, + } +} diff --git a/pkg/apis/calico/v3/register.go b/pkg/apis/calico/v3/register.go new file mode 100644 index 00000000000..0aa49e56db4 --- /dev/null +++ b/pkg/apis/calico/v3/register.go @@ -0,0 +1,53 @@ +/* +Copyright 2023 The OpenYurt Authors. + +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 v3 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var SchemeGroupVersion = schema.GroupVersion{Group: "crd.projectcalico.org", Version: "v1"} + +var ( + SchemeBuilder runtime.SchemeBuilder + localSchemeBuilder = &SchemeBuilder + AddToScheme = localSchemeBuilder.AddToScheme +) + +func init() { + // We only register manually written functions here. The registration of the + // generated functions takes place in the generated files. The separation + // makes the code compile even when the generated files are missing. + localSchemeBuilder.Register(addKnownTypes) +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +// Adds the list of known types to api.Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, []runtime.Object{ + &BlockAffinity{}, + &BlockAffinityList{}, + }...) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/calico/v3/zz_generated.deepcopy.go b/pkg/apis/calico/v3/zz_generated.deepcopy.go new file mode 100644 index 00000000000..dd0489c4a0d --- /dev/null +++ b/pkg/apis/calico/v3/zz_generated.deepcopy.go @@ -0,0 +1,102 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright 2023 The OpenYurt Authors. + +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. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v3 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BlockAffinity) DeepCopyInto(out *BlockAffinity) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BlockAffinity. +func (in *BlockAffinity) DeepCopy() *BlockAffinity { + if in == nil { + return nil + } + out := new(BlockAffinity) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BlockAffinity) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BlockAffinityList) DeepCopyInto(out *BlockAffinityList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]BlockAffinity, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BlockAffinityList. +func (in *BlockAffinityList) DeepCopy() *BlockAffinityList { + if in == nil { + return nil + } + out := new(BlockAffinityList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BlockAffinityList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BlockAffinitySpec) DeepCopyInto(out *BlockAffinitySpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BlockAffinitySpec. +func (in *BlockAffinitySpec) DeepCopy() *BlockAffinitySpec { + if in == nil { + return nil + } + out := new(BlockAffinitySpec) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go b/pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go index 4a6c2455d60..055841e6297 100644 --- a/pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go +++ b/pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go @@ -25,7 +25,6 @@ import ( "strings" "time" - calicov3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3" corev1 "k8s.io/api/core/v1" apierrs "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" @@ -42,6 +41,7 @@ import ( appconfig "github.com/openyurtio/openyurt/cmd/yurt-manager/app/config" "github.com/openyurtio/openyurt/cmd/yurt-manager/names" + calicov3 "github.com/openyurtio/openyurt/pkg/apis/calico/v3" "github.com/openyurtio/openyurt/pkg/apis/raven" ravenv1beta1 "github.com/openyurtio/openyurt/pkg/apis/raven/v1beta1" common "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/raven"