Skip to content

Commit 6f6a599

Browse files
ermajnsdudoladov
authored andcommitted
Added possibility to add custom annotations to LoadBalancer service. (#461)
* Added possibility to add custom annotations to LoadBalancer service.
1 parent 9c75588 commit 6f6a599

File tree

8 files changed

+23
-3
lines changed

8 files changed

+23
-3
lines changed

docs/reference/operator_parameters.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ In the CRD-based configuration they are grouped under the `load_balancer` key.
294294
cluster. Can be overridden by individual cluster settings. The default is
295295
`false`.
296296

297+
* **custom_service_annotations**
298+
when load balancing is enabled, LoadBalancer service is created and
299+
this parameter takes service annotations that are applied to service.
300+
Optional.
301+
297302
* **master_dns_name_format** defines the DNS name string template for the
298303
master load balancer cluster. The default is
299304
`{cluster}.{team}.{hostedzone}`, where `{cluster}` is replaced by the cluster

manifests/configmap.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ data:
1515
secret_name_template: '{username}.{cluster}.credentials'
1616
super_username: postgres
1717
enable_teams_api: "false"
18+
# custom_service_annotations:
19+
# "keyx:valuez,keya:valuea"
1820
# set_memory_request_to_limit: "true"
1921
# postgres_superuser_teams: "postgres_superusers"
2022
# enable_team_superuser: "false"

manifests/postgresql-operator-default-configuration.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ configuration:
4646
load_balancer:
4747
enable_master_load_balancer: false
4848
enable_replica_load_balancer: false
49+
# custom_service_annotations:
50+
# keyx: valuex
51+
# keyy: valuey
4952
master_dns_name_format: "{cluster}.{team}.{hostedzone}"
5053
replica_dns_name_format: "{cluster}-repl.{team}.{hostedzone}"
5154
aws_or_gcp:

pkg/apis/acid.zalan.do/v1/operator_configuration_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ type LoadBalancerConfiguration struct {
8484
DbHostedZone string `json:"db_hosted_zone,omitempty"`
8585
EnableMasterLoadBalancer bool `json:"enable_master_load_balancer,omitempty"`
8686
EnableReplicaLoadBalancer bool `json:"enable_replica_load_balancer,omitempty"`
87+
CustomServiceAnnotations map[string]string `json:"custom_service_annotations,omitempty"`
8788
MasterDNSNameFormat config.StringTemplate `json:"master_dns_name_format,omitempty"`
8889
ReplicaDNSNameFormat config.StringTemplate `json:"replica_dns_name_format,omitempty"`
8990
}

pkg/cluster/k8sres.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,13 @@ func (c *Cluster) generateService(role PostgresRole, spec *acidv1.PostgresSpec)
10931093
constants.ZalandoDNSNameAnnotation: dnsName,
10941094
constants.ElbTimeoutAnnotationName: constants.ElbTimeoutAnnotationValue,
10951095
}
1096+
1097+
if len(c.OpConfig.CustomServiceAnnotations) != 0 {
1098+
c.logger.Debugf("There are custom annotations defined, creating them.")
1099+
for customAnnotationKey, customAnnotationValue := range c.OpConfig.CustomServiceAnnotations {
1100+
annotations[customAnnotationKey] = customAnnotationValue
1101+
}
1102+
}
10961103
} else if role == Replica {
10971104
// before PR #258, the replica service was only created if allocated a LB
10981105
// now we always create the service but warn if the LB is absent

pkg/controller/operator_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur
6767
result.DbHostedZone = fromCRD.LoadBalancer.DbHostedZone
6868
result.EnableMasterLoadBalancer = fromCRD.LoadBalancer.EnableMasterLoadBalancer
6969
result.EnableReplicaLoadBalancer = fromCRD.LoadBalancer.EnableReplicaLoadBalancer
70+
result.CustomServiceAnnotations = fromCRD.LoadBalancer.CustomServiceAnnotations
7071
result.MasterDNSNameFormat = fromCRD.LoadBalancer.MasterDNSNameFormat
7172
result.ReplicaDNSNameFormat = fromCRD.LoadBalancer.ReplicaDNSNameFormat
7273

pkg/util/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type Config struct {
9393
EnableAdminRoleForUsers bool `name:"enable_admin_role_for_users" default:"true"`
9494
EnableMasterLoadBalancer bool `name:"enable_master_load_balancer" default:"true"`
9595
EnableReplicaLoadBalancer bool `name:"enable_replica_load_balancer" default:"false"`
96+
CustomServiceAnnotations map[string]string `name:"custom_service_annotations"`
9697
// deprecated and kept for backward compatibility
9798
EnableLoadBalancer *bool `name:"enable_load_balancer"`
9899
MasterDNSNameFormat StringTemplate `name:"master_dns_name_format" default:"{cluster}.{team}.{hostedzone}"`

run_operator_locally.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function clean_up(){
5656
fi
5757

5858
if [[ -e "$PATH_TO_LOCAL_OPERATOR_MANIFEST" ]]; then
59-
rm --verbose "$PATH_TO_LOCAL_OPERATOR_MANIFEST"
59+
rm -v "$PATH_TO_LOCAL_OPERATOR_MANIFEST"
6060
fi
6161

6262
# the kubectl process does the port-forwarding between operator and local ports
@@ -70,7 +70,7 @@ function clean_up(){
7070
if kill "$pid" > /dev/null 2>&1; then
7171
echo "Kill the kubectl process responsible for port forwarding for minikube so that we can re-use the same ports for forwarding later..."
7272
fi
73-
rm --verbose "$PATH_TO_PORT_FORWARED_KUBECTL_PID"
73+
rm -v "$PATH_TO_PORT_FORWARED_KUBECTL_PID"
7474

7575
fi
7676
}
@@ -121,7 +121,7 @@ function deploy_self_built_image() {
121121
# update the tag in the postgres operator conf
122122
# since the image with this tag already exists on the machine,
123123
# docker should not attempt to fetch it from the registry due to imagePullPolicy
124-
sed --expression "s/\(image\:.*\:\).*$/\1$TAG/; s/smoke-tested-//" manifests/postgres-operator.yaml > "$PATH_TO_LOCAL_OPERATOR_MANIFEST"
124+
sed -e "s/\(image\:.*\:\).*$/\1$TAG/; s/smoke-tested-//" manifests/postgres-operator.yaml > "$PATH_TO_LOCAL_OPERATOR_MANIFEST"
125125

126126
retry "kubectl create -f \"$PATH_TO_LOCAL_OPERATOR_MANIFEST\"" "attempt to create $PATH_TO_LOCAL_OPERATOR_MANIFEST resource"
127127
}

0 commit comments

Comments
 (0)