Skip to content

Commit 9fc9f65

Browse files
committed
Add additional config parameters for master/replica services
1 parent 1aa1383 commit 9fc9f65

File tree

11 files changed

+76
-60
lines changed

11 files changed

+76
-60
lines changed

Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +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 `serviceSpec` for MysqlCluster CRD to provide the ability for additional service generation
14+
* Add ability to provision LoadBalancers for master/replica services
15+
* Support specifying additional annotations for master/replica services
1516
### Changed
1617
* Allow setting pod security context when deploying with Helm
1718
* 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 & 14 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
@@ -6178,20 +6206,6 @@ spec:
61786206
description: Set a custom offset for Server IDs. ServerID for each
61796207
node will be the index of the statefulset, plus offset
61806208
type: integer
6181-
serviceSpec:
6182-
description: Service extra specification
6183-
properties:
6184-
annotations:
6185-
additionalProperties:
6186-
type: string
6187-
description: Annotations allow to specify annotations for MysqlCluster's
6188-
services
6189-
type: object
6190-
type:
6191-
description: 'ServiceType defines a type for Services: ClusterIP,
6192-
Loadbalancer, etc.'
6193-
type: string
6194-
type: object
61956209
tmpfsSize:
61966210
anyOf:
61976211
- type: integer

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

Lines changed: 24 additions & 12 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
@@ -3771,18 +3795,6 @@ spec:
37713795
serverIDOffset:
37723796
description: Set a custom offset for Server IDs. ServerID for each node will be the index of the statefulset, plus offset
37733797
type: integer
3774-
serviceSpec:
3775-
description: 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-
type:
3783-
description: 'ServiceType defines a type for Services: ClusterIP, Loadbalancer, etc.'
3784-
type: string
3785-
type: object
37863798
tmpfsSize:
37873799
anyOf:
37883800
- type: integer

pkg/apis/mysql/v1alpha1/mysqlcluster_defaults.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ func SetDefaults_MysqlCluster(c *MysqlCluster) {
5656
if len(c.Spec.MinAvailable) == 0 && *c.Spec.Replicas > 1 {
5757
c.Spec.MinAvailable = defaultMinAvailable
5858
}
59-
60-
// set default service type
61-
if c.Spec.ServiceSpec.ServiceType == "" {
62-
c.Spec.ServiceSpec.ServiceType = corev1.ServiceTypeClusterIP
63-
}
6459
}
6560

6661
// SetDefaults for PodSpec

pkg/apis/mysql/v1alpha1/mysqlcluster_types.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,13 @@ type MysqlClusterSpec struct {
107107
// +optional
108108
VolumeSpec VolumeSpec `json:"volumeSpec,omitempty"`
109109

110-
// Service extra specification
110+
// Master service extra specification
111111
// +optional
112-
ServiceSpec ServiceSpec `json:"serviceSpec,omitempty"`
112+
MasterServiceSpec ServiceSpec `json:"MasterServiceSpec,omitempty"`
113+
114+
// Healthy replica service extra specification
115+
// +optional
116+
ReplicaServiceSpec ServiceSpec `json:"replicaServiceSpec,omitempty"`
113117

114118
// TmpfsSize if specified, mounts a tmpfs of this size into /tmp
115119
// DEPRECATED: use instead PodSpec.Volumes and PodSpec.VolumeMounts
@@ -247,9 +251,9 @@ type VolumeSpec struct {
247251

248252
// ServiceSpec s the desired spec for addition configuration of MysqlCluster services
249253
type ServiceSpec struct {
250-
// ServiceType defines a type for Services: ClusterIP, Loadbalancer, etc.
254+
// LoadBalancer configures whether a service is a LoadBalancer or not.
251255
// +optional
252-
ServiceType core.ServiceType `json:"type,omitempty"`
256+
LoadBalancer bool `json:"loadBalancer,omitempty"`
253257

254258
// Annotations allow to specify annotations for MysqlCluster's services
255259
// +optional

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

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ func NewHeadlessSVCSyncer(c client.Client, scheme *runtime.Scheme, cluster *mysq
3838
}
3939

4040
return syncer.NewObjectSyncer("HeadlessSVC", nil, service, c, func() error {
41-
// set service type
42-
service.Spec.Type = cluster.Spec.ServiceSpec.ServiceType
43-
44-
// set annotations
45-
if len(cluster.Spec.ServiceSpec.Annotations) > 0 {
46-
service.ObjectMeta.Annotations = cluster.Spec.ServiceSpec.Annotations
47-
}
48-
4941
// add general labels to this service
5042
service.Labels = map[string]string{
5143
"app.kubernetes.io/name": "mysql",

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ func NewHealthyReplicasSVCSyncer(c client.Client, scheme *runtime.Scheme, cluste
3737

3838
return syncer.NewObjectSyncer("HealthyReplicasSVC", cluster.Unwrap(), service, c, func() error {
3939
// set service type
40-
service.Spec.Type = cluster.Spec.ServiceSpec.ServiceType
40+
if cluster.Spec.ReplicaServiceSpec.LoadBalancer {
41+
service.Spec.Type = core.ServiceTypeLoadBalancer
42+
}
4143

4244
// set annotations
43-
if len(cluster.Spec.ServiceSpec.Annotations) > 0 {
44-
service.ObjectMeta.Annotations = cluster.Spec.ServiceSpec.Annotations
45+
if len(cluster.Spec.ReplicaServiceSpec.Annotations) > 0 {
46+
service.ObjectMeta.Annotations = cluster.Spec.ReplicaServiceSpec.Annotations
4547
}
4648

4749
// set service labels

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ func NewHealthySVCSyncer(c client.Client, scheme *runtime.Scheme, cluster *mysql
3737
}
3838

3939
return syncer.NewObjectSyncer("HealthySVC", cluster.Unwrap(), service, c, func() error {
40-
// set service type
41-
service.Spec.Type = cluster.Spec.ServiceSpec.ServiceType
42-
43-
// set annotations
44-
if len(cluster.Spec.ServiceSpec.Annotations) > 0 {
45-
service.ObjectMeta.Annotations = cluster.Spec.ServiceSpec.Annotations
46-
}
47-
4840
// set service labels
4941
service.Labels = cluster.GetLabels()
5042
service.Labels["mysql.presslabs.org/service-type"] = "ready-nodes"

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ func NewMasterSVCSyncer(c client.Client, scheme *runtime.Scheme, cluster *mysqlc
3737

3838
return syncer.NewObjectSyncer("MasterSVC", cluster.Unwrap(), service, c, func() error {
3939
// set service type
40-
service.Spec.Type = cluster.Spec.ServiceSpec.ServiceType
40+
if cluster.Spec.MasterServiceSpec.LoadBalancer {
41+
service.Spec.Type = core.ServiceTypeLoadBalancer
42+
}
4143

4244
// set annotations
43-
if len(cluster.Spec.ServiceSpec.Annotations) > 0 {
44-
service.ObjectMeta.Annotations = cluster.Spec.ServiceSpec.Annotations
45+
if len(cluster.Spec.MasterServiceSpec.Annotations) > 0 {
46+
service.ObjectMeta.Annotations = cluster.Spec.MasterServiceSpec.Annotations
4547
}
4648

4749
// set service labels

pkg/internal/mysqlcluster/mysqlcluster_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ var _ = Describe("Test MySQL cluster wrapper", func() {
7676
Expect(cluster.Spec.MysqlConf).To(HaveKey(Equal("innodb-log-file-size")))
7777
Expect(cluster.Spec.MysqlConf).NotTo(HaveKey(Equal("max-binlog-size")))
7878

79-
Expect(cluster.Spec.ServiceSpec.ServiceType).To(Equal(corev1.ServiceTypeClusterIP))
79+
Expect(cluster.Spec.MasterServiceSpec.LoadBalancer).To(Equal(false))
80+
Expect(cluster.Spec.ReplicaServiceSpec.LoadBalancer).To(Equal(false))
8081
})
8182

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

0 commit comments

Comments
 (0)