diff --git a/pkg/apis/listeners/v1alpha1/groupversion_info.go b/pkg/apis/listeners/v1alpha1/groupversion_info.go new file mode 100644 index 0000000..d5016b9 --- /dev/null +++ b/pkg/apis/listeners/v1alpha1/groupversion_info.go @@ -0,0 +1,36 @@ +/* +Copyright 2024 zncdatadev. + +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 v1alpha1 contains API Schema definitions for the listeners v1alpha1 API group +// +kubebuilder:object:generate=true +// +groupName=listeners.zncdata.dev +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "listeners.zncdata.dev", Version: "v1alpha1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/pkg/apis/listeners/v1alpha1/listener_types.go b/pkg/apis/listeners/v1alpha1/listener_types.go new file mode 100644 index 0000000..b3251cc --- /dev/null +++ b/pkg/apis/listeners/v1alpha1/listener_types.go @@ -0,0 +1,96 @@ +/* +Copyright 2024 zncdatadev. + +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 v1alpha1 + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type AddressType string + +const ( + AddressTypeHostname AddressType = "Hostname" + AddressTypeIP AddressType = "IP" +) + +// ListenerSpec defines the desired state of Listener +type ListenerSpec struct { + // +kubebuilder:validation:Required + ClassName string `json:"className,omitempty"` + + // +kubebuilder:validation:Optional + ExtraPodMatchLabels map[string]string `json:"extraPodMatchLabels,omitempty"` + + // +kubebuilder:validation:Optional + Ports []PortSpec `json:"ports,omitempty"` +} + +type PortSpec struct { + // +kubebuilder:validation:Required + Name string `json:"name,omitempty"` + + // +kubebuilder:validation:Required + Protocol corev1.Protocol `json:"protocol,omitempty"` + + // +kubebuilder:validation:Required + Port int32 `json:"port,omitempty"` +} + +// ListenerStatus defines the observed state of Listener +type ListenerStatus struct { + IngressAddresses []IngressAddressSpec `json:"ingressAddresses,omitempty"` + NodePorts map[string]int32 `json:"nodePorts,omitempty"` + ServiceName string `json:"serviceName,omitempty"` +} + +type IngressAddressSpec struct { + // +kubebuilder:validation:Required + Address string `json:"address,omitempty"` + + // +kubebuilder:validation:Required + // +kubebuilder:validation:Enum=Hostname;IP + AddressType AddressType `json:"addressType,omitempty"` + + // +kubebuilder:validation:Required + Ports map[string]int32 `json:"ports,omitempty"` +} + +//+kubebuilder:object:root=true +//+kubebuilder:subresource:status + +// Listener is the Schema for the listeners API +type Listener struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ListenerSpec `json:"spec,omitempty"` + Status ListenerStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// ListenerList contains a list of Listener +type ListenerList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Listener `json:"items"` +} + +func init() { + SchemeBuilder.Register(&Listener{}, &ListenerList{}) +} diff --git a/pkg/apis/listeners/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/listeners/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 0000000..f879db9 --- /dev/null +++ b/pkg/apis/listeners/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,177 @@ +//go:build !ignore_autogenerated + +/* +Copyright 2024 zncdatadev. + +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 controller-gen. DO NOT EDIT. + +package v1alpha1 + +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 *IngressAddressSpec) DeepCopyInto(out *IngressAddressSpec) { + *out = *in + if in.Ports != nil { + in, out := &in.Ports, &out.Ports + *out = make(map[string]int32, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IngressAddressSpec. +func (in *IngressAddressSpec) DeepCopy() *IngressAddressSpec { + if in == nil { + return nil + } + out := new(IngressAddressSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Listener) DeepCopyInto(out *Listener) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Listener. +func (in *Listener) DeepCopy() *Listener { + if in == nil { + return nil + } + out := new(Listener) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Listener) 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 *ListenerList) DeepCopyInto(out *ListenerList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Listener, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ListenerList. +func (in *ListenerList) DeepCopy() *ListenerList { + if in == nil { + return nil + } + out := new(ListenerList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ListenerList) 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 *ListenerSpec) DeepCopyInto(out *ListenerSpec) { + *out = *in + if in.ExtraPodMatchLabels != nil { + in, out := &in.ExtraPodMatchLabels, &out.ExtraPodMatchLabels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Ports != nil { + in, out := &in.Ports, &out.Ports + *out = make([]PortSpec, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ListenerSpec. +func (in *ListenerSpec) DeepCopy() *ListenerSpec { + if in == nil { + return nil + } + out := new(ListenerSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ListenerStatus) DeepCopyInto(out *ListenerStatus) { + *out = *in + if in.IngressAddresses != nil { + in, out := &in.IngressAddresses, &out.IngressAddresses + *out = make([]IngressAddressSpec, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.NodePorts != nil { + in, out := &in.NodePorts, &out.NodePorts + *out = make(map[string]int32, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ListenerStatus. +func (in *ListenerStatus) DeepCopy() *ListenerStatus { + if in == nil { + return nil + } + out := new(ListenerStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PortSpec) DeepCopyInto(out *PortSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PortSpec. +func (in *PortSpec) DeepCopy() *PortSpec { + if in == nil { + return nil + } + out := new(PortSpec) + in.DeepCopyInto(out) + return out +}