Skip to content

Commit b1887ac

Browse files
committed
Allow additional service configuration for MysqlCluster
1 parent 0e3e443 commit b1887ac

File tree

10 files changed

+92
-0
lines changed

10 files changed

+92
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ 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
1415
### Changed
1516
* Allow setting pod security context when deploying with Helm
1617
* Use [distroless](https://github.com/GoogleContainerTools/distroless) as base image for orchestrator container

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6178,6 +6178,20 @@ spec:
61786178
description: Set a custom offset for Server IDs. ServerID for each
61796179
node will be the index of the statefulset, plus offset
61806180
type: integer
6181+
serviceSpec:
6182+
description: Service extra specification
6183+
properties:
6184+
annotations:
6185+
additionalProperties:
6186+
type: string
6187+
description: Additional annotations to append to 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
61816195
tmpfsSize:
61826196
anyOf:
61836197
- type: integer

pkg/apis/mysql/v1alpha1/mysqlcluster_types.go

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

110+
// Service extra specification
111+
// +optional
112+
ServiceSpec ServiceSpec `json:"serviceSpec,omitempty"`
113+
110114
// TmpfsSize if specified, mounts a tmpfs of this size into /tmp
111115
// DEPRECATED: use instead PodSpec.Volumes and PodSpec.VolumeMounts
112116
// +optional
@@ -241,6 +245,17 @@ type VolumeSpec struct {
241245
PersistentVolumeClaim *core.PersistentVolumeClaimSpec `json:"persistentVolumeClaim,omitempty"`
242246
}
243247

248+
// ServiceSpeci s the desired spec for addition configuration of MysqlCluster services
249+
type ServiceSpec struct {
250+
// ServiceType defines a type for Services: ClusterIP, Loadbalancer, etc.
251+
// +optional
252+
ServiceType string `json:"type,omitempty"`
253+
254+
// Additional annotations to append to MysqlCluster's services
255+
// +optional
256+
Annotations map[string]string `json:"annotations,omitempty"`
257+
}
258+
244259
// QueryLimits represents the pt-kill parameters, more info can be found
245260
// here: https://www.percona.com/doc/percona-toolkit/LATEST/pt-kill.html
246261
type QueryLimits struct {

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

Lines changed: 23 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/headless_service.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ 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+
4149
// add general labels to this service
4250
service.Labels = map[string]string{
4351
"app.kubernetes.io/name": "mysql",

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ func NewHealthyReplicasSVCSyncer(c client.Client, scheme *runtime.Scheme, cluste
3636
}
3737

3838
return syncer.NewObjectSyncer("HealthyReplicasSVC", cluster.Unwrap(), service, c, func() error {
39+
// set service type
40+
service.Spec.Type = cluster.Spec.ServiceSpec.ServiceType
41+
42+
// set annotations
43+
if len(cluster.Spec.ServiceSpec.Annotations) > 0 {
44+
service.ObjectMeta.Annotations = cluster.Spec.ServiceSpec.Annotations
45+
}
46+
3947
// set service labels
4048
service.Labels = cluster.GetLabels()
4149
service.Labels["mysql.presslabs.org/service-type"] = "ready-replicas"

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ 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+
4048
// set service labels
4149
service.Labels = cluster.GetLabels()
4250
service.Labels["mysql.presslabs.org/service-type"] = "ready-nodes"

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

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

3838
return syncer.NewObjectSyncer("MasterSVC", cluster.Unwrap(), service, c, func() error {
39+
// set service type
40+
service.Spec.Type = cluster.Spec.ServiceSpec.ServiceType
41+
42+
// set annotations
43+
if len(cluster.Spec.ServiceSpec.Annotations) > 0 {
44+
service.ObjectMeta.Annotations = cluster.Spec.ServiceSpec.Annotations
45+
}
46+
3947
// set service labels
4048
service.Labels = cluster.GetLabels()
4149
service.Labels["mysql.presslabs.org/service-type"] = "master"

pkg/internal/mysqlcluster/defaults.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ func (cluster *MysqlCluster) SetDefaults(opt *options.Options) {
7979
}
8080
}
8181

82+
// set default service type
83+
if cluster.Spec.ServiceSpec.ServiceType == "" {
84+
cluster.Spec.ServiceSpec.ServiceType = "ClusterIP"
85+
}
86+
8287
// configure mysql based on:
8388
// https://www.percona.com/blog/2018/03/26/mysql-8-0-innodb_dedicated_server-variable-optimizes-innodb/
8489

pkg/internal/mysqlcluster/mysqlcluster_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ 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.ServiceSpec.ServiceType).To(Equal("ClusterIP"))
7880
})
7981

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

0 commit comments

Comments
 (0)