Skip to content

Commit 067b014

Browse files
committed
Support additional configuration for master / replicas services
1 parent 0e3e443 commit 067b014

File tree

8 files changed

+122
-0
lines changed

8 files changed

+122
-0
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1111
provisioners wich don't support fsGroup in security context (fixes #615)
1212
* Add `appSecretLabels`, `appSecretAnnotations`, `backupSecretLabels`, `backupSecretAnnotations` to provide
1313
custom labels and annotations to created app and backup secrets
14+
* Add ability to provision LoadBalancers for master/replica services
15+
* Support specifying additional annotations for master/replica services
1416
### Changed
1517
* Allow setting pod security context when deploying with Helm
1618
* Use [distroless](https://github.com/GoogleContainerTools/distroless) as base image for orchestrator container

config/crd/bases/mysql.presslabs.org_mysqlclusters.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ spec:
5151
description: 'MysqlClusterSpec defines the desired state of MysqlCluster
5252
nolint: maligned'
5353
properties:
54+
MasterServiceSpec:
55+
description: Master service extra specification
56+
properties:
57+
annotations:
58+
additionalProperties:
59+
type: string
60+
description: Annotations allow to specify annotations for MysqlCluster's
61+
services
62+
type: object
63+
loadBalancer:
64+
description: LoadBalancer configures whether a service is a LoadBalancer
65+
or not.
66+
type: boolean
67+
type: object
5468
backupCompressCommand:
5569
description: BackupCompressCommand is a command to use for compressing
5670
the backup.
@@ -6161,6 +6175,20 @@ spec:
61616175
in case of a failover the cluster will be writable for at least
61626176
a few seconds.
61636177
type: boolean
6178+
replicaServiceSpec:
6179+
description: Healthy replica service extra specification
6180+
properties:
6181+
annotations:
6182+
additionalProperties:
6183+
type: string
6184+
description: Annotations allow to specify annotations for MysqlCluster's
6185+
services
6186+
type: object
6187+
loadBalancer:
6188+
description: LoadBalancer configures whether a service is a LoadBalancer
6189+
or not.
6190+
type: boolean
6191+
type: object
61646192
replicas:
61656193
description: The number of pods. This updates replicas filed Defaults
61666194
to 0

deploy/charts/mysql-operator/crds/mysql.presslabs.org_mysqlclusters.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ spec:
4646
spec:
4747
description: 'MysqlClusterSpec defines the desired state of MysqlCluster nolint: maligned'
4848
properties:
49+
MasterServiceSpec:
50+
description: Master service extra specification
51+
properties:
52+
annotations:
53+
additionalProperties:
54+
type: string
55+
description: Annotations allow to specify annotations for MysqlCluster's services
56+
type: object
57+
loadBalancer:
58+
description: LoadBalancer configures whether a service is a LoadBalancer or not.
59+
type: boolean
60+
type: object
4961
backupCompressCommand:
5062
description: BackupCompressCommand is a command to use for compressing the backup.
5163
items:
@@ -3759,6 +3771,18 @@ spec:
37593771
readOnly:
37603772
description: Makes the cluster READ ONLY. This has not a strong guarantee, in case of a failover the cluster will be writable for at least a few seconds.
37613773
type: boolean
3774+
replicaServiceSpec:
3775+
description: Healthy replica service extra specification
3776+
properties:
3777+
annotations:
3778+
additionalProperties:
3779+
type: string
3780+
description: Annotations allow to specify annotations for MysqlCluster's services
3781+
type: object
3782+
loadBalancer:
3783+
description: LoadBalancer configures whether a service is a LoadBalancer or not.
3784+
type: boolean
3785+
type: object
37623786
replicas:
37633787
description: The number of pods. This updates replicas filed Defaults to 0
37643788
format: int32

pkg/apis/mysql/v1alpha1/mysqlcluster_types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ type MysqlClusterSpec struct {
107107
// +optional
108108
VolumeSpec VolumeSpec `json:"volumeSpec,omitempty"`
109109

110+
// Master service extra specification
111+
// +optional
112+
MasterServiceSpec ServiceSpec `json:"MasterServiceSpec,omitempty"`
113+
114+
// Healthy replica service extra specification
115+
// +optional
116+
ReplicaServiceSpec ServiceSpec `json:"replicaServiceSpec,omitempty"`
117+
110118
// TmpfsSize if specified, mounts a tmpfs of this size into /tmp
111119
// DEPRECATED: use instead PodSpec.Volumes and PodSpec.VolumeMounts
112120
// +optional
@@ -241,6 +249,17 @@ type VolumeSpec struct {
241249
PersistentVolumeClaim *core.PersistentVolumeClaimSpec `json:"persistentVolumeClaim,omitempty"`
242250
}
243251

252+
// ServiceSpec s the desired spec for addition configuration of MysqlCluster services
253+
type ServiceSpec struct {
254+
// LoadBalancer configures whether a service is a LoadBalancer or not.
255+
// +optional
256+
LoadBalancer bool `json:"loadBalancer,omitempty"`
257+
258+
// Annotations allow to specify annotations for MysqlCluster's services
259+
// +optional
260+
Annotations map[string]string `json:"annotations,omitempty"`
261+
}
262+
244263
// QueryLimits represents the pt-kill parameters, more info can be found
245264
// here: https://www.percona.com/doc/percona-toolkit/LATEST/pt-kill.html
246265
type QueryLimits struct {

pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/mysqlcluster/internal/syncer/healthy_replicas_service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package mysqlcluster
1818

1919
import (
20+
"github.com/imdario/mergo"
2021
"github.com/presslabs/controller-util/syncer"
2122
core "k8s.io/api/core/v1"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -36,6 +37,16 @@ func NewHealthyReplicasSVCSyncer(c client.Client, scheme *runtime.Scheme, cluste
3637
}
3738

3839
return syncer.NewObjectSyncer("HealthyReplicasSVC", cluster.Unwrap(), service, c, func() error {
40+
// set service type
41+
if cluster.Spec.ReplicaServiceSpec.LoadBalancer {
42+
service.Spec.Type = core.ServiceTypeLoadBalancer
43+
}
44+
45+
// merge annotations
46+
if err := mergo.Merge(&service.ObjectMeta.Annotations, cluster.Spec.ReplicaServiceSpec.Annotations); err != nil {
47+
return err
48+
}
49+
3950
// set service labels
4051
service.Labels = cluster.GetLabels()
4152
service.Labels["mysql.presslabs.org/service-type"] = "ready-replicas"

pkg/controller/mysqlcluster/internal/syncer/master_service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package mysqlcluster
1818

1919
import (
20+
"github.com/imdario/mergo"
2021
"github.com/presslabs/controller-util/syncer"
2122
core "k8s.io/api/core/v1"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -36,6 +37,16 @@ func NewMasterSVCSyncer(c client.Client, scheme *runtime.Scheme, cluster *mysqlc
3637
}
3738

3839
return syncer.NewObjectSyncer("MasterSVC", cluster.Unwrap(), service, c, func() error {
40+
// set service type
41+
if cluster.Spec.MasterServiceSpec.LoadBalancer {
42+
service.Spec.Type = core.ServiceTypeLoadBalancer
43+
}
44+
45+
// merge annotations
46+
if err := mergo.Merge(&service.ObjectMeta.Annotations, cluster.Spec.MasterServiceSpec.Annotations); err != nil {
47+
return err
48+
}
49+
3950
// set service labels
4051
service.Labels = cluster.GetLabels()
4152
service.Labels["mysql.presslabs.org/service-type"] = "master"

pkg/internal/mysqlcluster/mysqlcluster_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ var _ = Describe("Test MySQL cluster wrapper", func() {
7575
Expect(cluster.Spec.MysqlConf).To(HaveKey(Equal("innodb-buffer-pool-size")))
7676
Expect(cluster.Spec.MysqlConf).To(HaveKey(Equal("innodb-log-file-size")))
7777
Expect(cluster.Spec.MysqlConf).NotTo(HaveKey(Equal("max-binlog-size")))
78+
79+
Expect(cluster.Spec.MasterServiceSpec.LoadBalancer).To(Equal(false))
80+
Expect(cluster.Spec.ReplicaServiceSpec.LoadBalancer).To(Equal(false))
7881
})
7982

8083
It("should use init MySQL container", func() {

0 commit comments

Comments
 (0)