From 70561b447c6758aca9c1b2f9dc296ba2c1635e71 Mon Sep 17 00:00:00 2001 From: backguynn Date: Fri, 13 Oct 2023 11:17:58 +0900 Subject: [PATCH] Clean up duplicate structs. --- pkg/api/lb.go | 14 ++--- pkg/crds/multiclusterlbservice/v1/types.go | 53 +++------------- .../v1/zz_generated.deepcopy.go | 61 +++---------------- 3 files changed, 22 insertions(+), 106 deletions(-) diff --git a/pkg/api/lb.go b/pkg/api/lb.go index a20ab20..7b5ee80 100644 --- a/pkg/api/lb.go +++ b/pkg/api/lb.go @@ -17,7 +17,7 @@ func (lbListModel *LoadBalancerListModel) GetKeyStruct() LoxiModel { type LoadBalancerModel struct { Service LoadBalancerService `json:"serviceArguments"` - SecondaryIPs []LoadBalancerSecIp `json:"secondaryIPs"` + SecondaryIPs []LoadBalancerSecIp `json:"secondaryIPs,omitempty"` Endpoints []LoadBalancerEndpoint `json:"endpoints"` } @@ -31,15 +31,15 @@ type LoadBalancerService struct { Protocol string `json:"protocol" key:"protocol"` Sel EpSelect `json:"sel"` Mode LbMode `json:"mode"` - BGP bool `json:"BGP" options:"bgp"` - Monitor bool `json:"Monitor"` + BGP bool `json:"BGP,omitempty" options:"bgp"` + Monitor bool `json:"Monitor,omitempty"` Timeout uint32 `json:"inactiveTimeOut"` Block uint16 `json:"block" options:"block"` Managed bool `json:"managed,omitempty"` - ProbeType string `json:"probetype"` - ProbePort uint16 `json:"probeport"` - ProbeReq string `json:"probereq"` - ProbeResp string `json:"proberesp"` + ProbeType string `json:"probetype,omitempty"` + ProbePort uint16 `json:"probeport,omitempty"` + ProbeReq string `json:"probereq,omitempty"` + ProbeResp string `json:"proberesp,omitempty"` } func (lbService *LoadBalancerService) GetKeyStruct() LoxiModel { diff --git a/pkg/crds/multiclusterlbservice/v1/types.go b/pkg/crds/multiclusterlbservice/v1/types.go index 17da6c4..40ee55f 100644 --- a/pkg/crds/multiclusterlbservice/v1/types.go +++ b/pkg/crds/multiclusterlbservice/v1/types.go @@ -23,6 +23,7 @@ import ( type EpSelect uint type LbMode int32 +type MultiClusterLBModel api.LoadBalancerModel // +genclient // +genclient:nonNamespaced @@ -34,6 +35,11 @@ type MultiClusterLBService struct { Spec MultiClusterLBServiceSpec `json:"spec,omitempty"` } +// MultiClusterLBServiceSpec defines the desired state of MultiClusterLBService +type MultiClusterLBServiceSpec struct { + Model MultiClusterLBModel `json:"lbModel"` +} + // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type MultiClusterLBServiceList struct { metav1.TypeMeta `json:",inline"` @@ -41,49 +47,6 @@ type MultiClusterLBServiceList struct { Items []*MultiClusterLBService `json:"items"` } -type LoadBalancerService struct { - ExternalIP string `json:"externalIP" key:"externalipaddress"` - Port uint16 `json:"port" key:"port"` - Protocol string `json:"protocol" key:"protocol"` - Sel EpSelect `json:"sel"` - Mode LbMode `json:"mode"` - BGP bool `json:"BGP,omitempty" options:"bgp"` - Monitor bool `json:"Monitor,omitempty"` - Timeout uint32 `json:"inactiveTimeOut"` - Block uint16 `json:"block" options:"block"` - Managed bool `json:"managed,omitempty"` - ProbeType string `json:"probetype,omitempty"` - ProbePort uint16 `json:"probeport,omitempty"` - ProbeReq string `json:"probereq,omitempty"` - ProbeResp string `json:"proberesp,omitempty"` -} - -type LoadBalancerEndpoint struct { - EndpointIP string `json:"endpointIP"` - TargetPort uint16 `json:"targetPort"` - Weight uint8 `json:"weight"` - State string `json:"state,omitempty"` -} - -type LoadBalancerSecIp struct { - SecondaryIP string `json:"secondaryIP"` -} - -// MultiClusterLBServiceSpec defines the desired state of MultiClusterLBService -type MultiClusterLBServiceSpec struct { - Model LoadBalancerModel `json:"lbModel"` -} - -type LoadBalancerModel struct { - Service LoadBalancerService `json:"serviceArguments"` - SecondaryIPs []LoadBalancerSecIp `json:"secondaryIPs,omitempty"` - Endpoints []LoadBalancerEndpoint `json:"endpoints"` -} - -func (l *LoadBalancerModel) GetKeyStruct() api.LoxiModel { - return &l.Service -} - -func (lbService *LoadBalancerService) GetKeyStruct() api.LoxiModel { - return lbService +func (lbModel *MultiClusterLBModel) GetKeyStruct() api.LoxiModel { + return &lbModel.Service } diff --git a/pkg/crds/multiclusterlbservice/v1/zz_generated.deepcopy.go b/pkg/crds/multiclusterlbservice/v1/zz_generated.deepcopy.go index 67a8105..8e7626d 100644 --- a/pkg/crds/multiclusterlbservice/v1/zz_generated.deepcopy.go +++ b/pkg/crds/multiclusterlbservice/v1/zz_generated.deepcopy.go @@ -22,80 +22,33 @@ limitations under the License. package v1 import ( + api "github.com/loxilb-io/kube-loxilb/pkg/api" 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 *LoadBalancerEndpoint) DeepCopyInto(out *LoadBalancerEndpoint) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoadBalancerEndpoint. -func (in *LoadBalancerEndpoint) DeepCopy() *LoadBalancerEndpoint { - if in == nil { - return nil - } - out := new(LoadBalancerEndpoint) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LoadBalancerModel) DeepCopyInto(out *LoadBalancerModel) { +func (in *MultiClusterLBModel) DeepCopyInto(out *MultiClusterLBModel) { *out = *in out.Service = in.Service if in.SecondaryIPs != nil { in, out := &in.SecondaryIPs, &out.SecondaryIPs - *out = make([]LoadBalancerSecIp, len(*in)) + *out = make([]api.LoadBalancerSecIp, len(*in)) copy(*out, *in) } if in.Endpoints != nil { in, out := &in.Endpoints, &out.Endpoints - *out = make([]LoadBalancerEndpoint, len(*in)) + *out = make([]api.LoadBalancerEndpoint, len(*in)) copy(*out, *in) } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoadBalancerModel. -func (in *LoadBalancerModel) DeepCopy() *LoadBalancerModel { - if in == nil { - return nil - } - out := new(LoadBalancerModel) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LoadBalancerSecIp) DeepCopyInto(out *LoadBalancerSecIp) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoadBalancerSecIp. -func (in *LoadBalancerSecIp) DeepCopy() *LoadBalancerSecIp { - if in == nil { - return nil - } - out := new(LoadBalancerSecIp) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LoadBalancerService) DeepCopyInto(out *LoadBalancerService) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoadBalancerService. -func (in *LoadBalancerService) DeepCopy() *LoadBalancerService { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MultiClusterLBModel. +func (in *MultiClusterLBModel) DeepCopy() *MultiClusterLBModel { if in == nil { return nil } - out := new(LoadBalancerService) + out := new(MultiClusterLBModel) in.DeepCopyInto(out) return out }