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

AC-1707 Add support for optional annotations to headless and pod services #334

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions api/v1/aerospikecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ type SeedsFinderServices struct {
// LoadBalancer created to discover Aerospike Cluster nodes from outside of
// Kubernetes cluster.
LoadBalancer *LoadBalancerSpec `json:"loadBalancer,omitempty"`

// Settings for the Headless service created by default to discover Aerospike
// Cluster nodes by pod IP.
Headless HeadlessServiceSpec `json:"headless,omitempty"`

// Pod service is a NodePort type service created to discover both Aerospike pod ports and IP
// addresses. This service is only created if `multiPodPerHost` is set to `true`.
Pod PodServiceSpec `json:"pod,omitempty"`
}

// LoadBalancerSpec contains specification for Service with type LoadBalancer.
Expand Down Expand Up @@ -192,6 +200,22 @@ type LoadBalancerSpec struct { //nolint:govet // for readability
LoadBalancerSourceRanges []string `json:"loadBalancerSourceRanges,omitempty" patchStrategy:"merge"`
}

// HeadlessServiceSpec contains specification for the headless service with type ClusterIP.
// +k8s:openapi-gen=true
type HeadlessServiceSpec struct {
// +patchStrategy=merge
// +optional
Annotations map[string]string `json:"annotations,omitempty" patchStrategy:"merge"`
}

// PodServiceSpec contains specification for the pod service with type NodePort.
// +k8s:openapi-gen=true
type PodServiceSpec struct {
// +patchStrategy=merge
// +optional
Annotations map[string]string `json:"annotations,omitempty" patchStrategy:"merge"`
}

type AerospikeOperatorClientCertSpec struct { //nolint:govet // for readability
// If specified, this name will be added to tls-authenticate-client list by the operator
// +optional
Expand Down
46 changes: 46 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

40 changes: 40 additions & 0 deletions config/crd/bases/asdb.aerospike.com_aerospikeclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7937,6 +7937,16 @@ spec:
SeedsFinderServices creates additional Kubernetes service that allow
clients to discover Aerospike cluster nodes.
properties:
headless:
description: |-
Settings for the Headless service created by default to discover Aerospike
Cluster nodes by pod IP.
properties:
annotations:
additionalProperties:
type: string
type: object
type: object
loadBalancer:
description: |-
LoadBalancer created to discover Aerospike Cluster nodes from outside of
Expand Down Expand Up @@ -7979,6 +7989,16 @@ spec:
minimum: 1024
type: integer
type: object
pod:
description: |-
Pod service is a NodePort type service created to discover both Aerospike pod ports and IP
addresses. This service is only created if `multiPodPerHost` is set to `true`.
properties:
annotations:
additionalProperties:
type: string
type: object
type: object
type: object
size:
description: Aerospike cluster size
Expand Down Expand Up @@ -16670,6 +16690,16 @@ spec:
description: SeedsFinderServices describes services which are used
for seeding Aerospike nodes.
properties:
headless:
description: |-
Settings for the Headless service created by default to discover Aerospike
Cluster nodes by pod IP.
properties:
annotations:
additionalProperties:
type: string
type: object
type: object
loadBalancer:
description: |-
LoadBalancer created to discover Aerospike Cluster nodes from outside of
Expand Down Expand Up @@ -16712,6 +16742,16 @@ spec:
minimum: 1024
type: integer
type: object
pod:
description: |-
Pod service is a NodePort type service created to discover both Aerospike pod ports and IP
addresses. This service is only created if `multiPodPerHost` is set to `true`.
properties:
annotations:
additionalProperties:
type: string
type: object
type: object
type: object
selector:
description: Selector specifies the label selector for the Aerospike
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7937,6 +7937,16 @@ spec:
SeedsFinderServices creates additional Kubernetes service that allow
clients to discover Aerospike cluster nodes.
properties:
headless:
description: |-
Settings for the Headless service created by default to discover Aerospike
Cluster nodes by pod IP.
properties:
annotations:
additionalProperties:
type: string
type: object
type: object
loadBalancer:
description: |-
LoadBalancer created to discover Aerospike Cluster nodes from outside of
Expand Down Expand Up @@ -7979,6 +7989,16 @@ spec:
minimum: 1024
type: integer
type: object
pod:
description: |-
Pod service is a NodePort type service created to discover both Aerospike pod ports and IP
addresses. This service is only created if `multiPodPerHost` is set to `true`.
properties:
annotations:
additionalProperties:
type: string
type: object
type: object
type: object
size:
description: Aerospike cluster size
Expand Down Expand Up @@ -16670,6 +16690,16 @@ spec:
description: SeedsFinderServices describes services which are used
for seeding Aerospike nodes.
properties:
headless:
description: |-
Settings for the Headless service created by default to discover Aerospike
Cluster nodes by pod IP.
properties:
annotations:
additionalProperties:
type: string
type: object
type: object
loadBalancer:
description: |-
LoadBalancer created to discover Aerospike Cluster nodes from outside of
Expand Down Expand Up @@ -16712,6 +16742,16 @@ spec:
minimum: 1024
type: integer
type: object
pod:
description: |-
Pod service is a NodePort type service created to discover both Aerospike pod ports and IP
addresses. This service is only created if `multiPodPerHost` is set to `true`.
properties:
annotations:
additionalProperties:
type: string
type: object
type: object
type: object
selector:
description: Selector specifies the label selector for the Aerospike
Expand Down
27 changes: 18 additions & 9 deletions internal/controller/cluster/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cluster
import (
"context"
"fmt"
"maps"
"reflect"

corev1 "k8s.io/api/core/v1"
Expand All @@ -23,6 +24,7 @@ func getSTSHeadLessSvcName(aeroCluster *asdbv1.AerospikeCluster) string {
}

func (r *SingleClusterReconciler) createOrUpdateSTSHeadlessSvc() error {
headlessSvc := r.aeroCluster.Spec.SeedsFinderServices.Headless
serviceName := getSTSHeadLessSvcName(r.aeroCluster)
service := &corev1.Service{}

Expand All @@ -38,17 +40,22 @@ func (r *SingleClusterReconciler) createOrUpdateSTSHeadlessSvc() error {

r.Log.Info("Creating headless service for statefulSet")

annotations := map[string]string{
// deprecation in 1.10, supported until at least 1.13, breaks peer-finder/kube-dns if not used
"service.alpha.kubernetes.io/tolerate-unready-endpoints": "true",
}
if headlessSvc.Annotations != nil {
maps.Copy(annotations, headlessSvc.Annotations)
}

ls := utils.LabelsForAerospikeCluster(r.aeroCluster.Name)
service = &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
// Headless service has the same name as AerospikeCluster
Name: serviceName,
Namespace: r.aeroCluster.Namespace,
// deprecation in 1.10, supported until at least 1.13, breaks peer-finder/kube-dns if not used
Annotations: map[string]string{
"service.alpha.kubernetes.io/tolerate-unready-endpoints": "true",
},
Labels: ls,
Name: serviceName,
Namespace: r.aeroCluster.Namespace,
Annotations: annotations,
Labels: ls,
},
Spec: corev1.ServiceSpec{
// deprecates service.alpha.kubernetes.io/tolerate-unready-endpoints as of 1.
Expand Down Expand Up @@ -211,6 +218,7 @@ func (r *SingleClusterReconciler) updateLBService(service *corev1.Service, servi
}

func (r *SingleClusterReconciler) createOrUpdatePodService(pName, pNamespace string) error {
podSvc := r.aeroCluster.Spec.SeedsFinderServices.Pod
service := &corev1.Service{}

err := r.Client.Get(
Expand All @@ -227,8 +235,9 @@ func (r *SingleClusterReconciler) createOrUpdatePodService(pName, pNamespace str
// NodePort will be allocated automatically
service = &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: pName,
Namespace: pNamespace,
Name: pName,
Namespace: pNamespace,
Annotations: podSvc.Annotations,
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeNodePort,
Expand Down
Loading