Skip to content

Commit

Permalink
feat: add listener type to apis (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
whg517 authored Jul 23, 2024
1 parent 6e6dfcc commit 695ef92
Show file tree
Hide file tree
Showing 3 changed files with 309 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/apis/listeners/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -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
)
96 changes: 96 additions & 0 deletions pkg/apis/listeners/v1alpha1/listener_types.go
Original file line number Diff line number Diff line change
@@ -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{})
}
177 changes: 177 additions & 0 deletions pkg/apis/listeners/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 695ef92

Please sign in to comment.