Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add labels and annotations for listener #126

Merged
merged 1 commit into from Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions apis/apps/v1beta1/listener_type.go
Expand Up @@ -8,6 +8,8 @@ import (

//+kubebuilder:object:generate=true
type Listener struct {
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
//+kubebuilder:validation:Enum=NodePort;LoadBalancer;ClusterIP
Type corev1.ServiceType `json:"type,omitempty"`
LoadBalancerIP string `json:"loadBalancerIP,omitempty" protobuf:"bytes,8,opt,name=loadBalancerIP"`
Expand Down
14 changes: 14 additions & 0 deletions apis/apps/v1beta1/zz_generated.deepcopy.go

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

16 changes: 16 additions & 0 deletions config/crd/bases/apps.emqx.io_emqxbrokers.yaml
Expand Up @@ -2483,10 +2483,18 @@ spec:
type: object
listener:
properties:
annotations:
additionalProperties:
type: string
type: object
externalIPs:
items:
type: string
type: array
labels:
additionalProperties:
type: string
type: object
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -3848,10 +3856,18 @@ spec:
type: array
listener:
properties:
annotations:
additionalProperties:
type: string
type: object
externalIPs:
items:
type: string
type: array
labels:
additionalProperties:
type: string
type: object
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down
16 changes: 16 additions & 0 deletions config/crd/bases/apps.emqx.io_emqxenterprises.yaml
Expand Up @@ -2485,10 +2485,18 @@ spec:
type: string
listener:
properties:
annotations:
additionalProperties:
type: string
type: object
externalIPs:
items:
type: string
type: array
labels:
additionalProperties:
type: string
type: object
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down Expand Up @@ -3855,10 +3863,18 @@ spec:
type: string
listener:
properties:
annotations:
additionalProperties:
type: string
type: object
externalIPs:
items:
type: string
type: array
labels:
additionalProperties:
type: string
type: object
loadBalancerIP:
type: string
loadBalancerSourceRanges:
Expand Down
7 changes: 6 additions & 1 deletion controllers_suite/listener_test.go
Expand Up @@ -140,7 +140,9 @@ var _ = Describe("", func() {
}

listener := v1beta1.Listener{
Type: corev1.ServiceTypeNodePort,
Type: corev1.ServiceTypeNodePort,
Labels: map[string]string{"test/labels": "service"},
Annotations: map[string]string{"test/annotations": "service"},
Ports: v1beta1.Ports{
API: int32(28081),
MQTT: int32(21883),
Expand All @@ -166,6 +168,9 @@ var _ = Describe("", func() {
return svc.Spec.Type
}, timeout, interval).Should(Equal(corev1.ServiceTypeNodePort))
Expect(svc.Spec.Ports).Should(ConsistOf(servicePorts))
Expect(svc.Annotations).Should(HaveKeyWithValue("test/annotations", "service"))
Expect(svc.Labels).Should(HaveKeyWithValue("test/labels", "service"))
Expect(svc.Labels).Should(HaveKeyWithValue("cluster", "emqx"))

sts := &appsv1.StatefulSet{}
Eventually(func() []corev1.ContainerPort {
Expand Down
3 changes: 3 additions & 0 deletions controllers_suite/suite_test.go
Expand Up @@ -343,6 +343,9 @@ func generateEmqxEnterprise(name, namespace string) *v1beta1.EmqxEnterprise {
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: map[string]string{
"cluster": "emqx",
},
},
Spec: v1beta1.EmqxEnterpriseSpec{
Image: "emqx/emqx-ee:4.4.0",
Expand Down
14 changes: 11 additions & 3 deletions pkg/service/generator.go
Expand Up @@ -179,9 +179,9 @@ func generateSvc(emqx v1beta1.Emqx, sts *appsv1.StatefulSet) (*corev1.Service, *
Kind: "Service",
},
ObjectMeta: metav1.ObjectMeta{
Labels: emqx.GetLabels(),
Name: emqx.GetName(),
Namespace: emqx.GetNamespace(),
Name: emqx.GetName(),
Namespace: emqx.GetNamespace(),
Annotations: listener.Annotations,
},
Spec: corev1.ServiceSpec{
Type: listener.Type,
Expand All @@ -191,6 +191,14 @@ func generateSvc(emqx v1beta1.Emqx, sts *appsv1.StatefulSet) (*corev1.Service, *
Selector: emqx.GetLabels(),
},
}
labels := listener.Labels
if labels == nil {
labels = make(map[string]string)
}
Rory-Z marked this conversation as resolved.
Show resolved Hide resolved
for k, v := range emqx.GetLabels() {
labels[k] = v
}
svc.Labels = labels

container := sts.Spec.Template.Spec.Containers[0]

Expand Down