Skip to content

Commit

Permalink
Support additional configuration for master / replicas services
Browse files Browse the repository at this point in the history
  • Loading branch information
ynnt committed Nov 1, 2021
1 parent 0e3e443 commit 067b014
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
provisioners wich don't support fsGroup in security context (fixes #615)
* Add `appSecretLabels`, `appSecretAnnotations`, `backupSecretLabels`, `backupSecretAnnotations` to provide
custom labels and annotations to created app and backup secrets
* Add ability to provision LoadBalancers for master/replica services
* Support specifying additional annotations for master/replica services
### Changed
* Allow setting pod security context when deploying with Helm
* Use [distroless](https://github.com/GoogleContainerTools/distroless) as base image for orchestrator container
Expand Down
28 changes: 28 additions & 0 deletions config/crd/bases/mysql.presslabs.org_mysqlclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ spec:
description: 'MysqlClusterSpec defines the desired state of MysqlCluster
nolint: maligned'
properties:
MasterServiceSpec:
description: Master service extra specification
properties:
annotations:
additionalProperties:
type: string
description: Annotations allow to specify annotations for MysqlCluster's
services
type: object
loadBalancer:
description: LoadBalancer configures whether a service is a LoadBalancer
or not.
type: boolean
type: object
backupCompressCommand:
description: BackupCompressCommand is a command to use for compressing
the backup.
Expand Down Expand Up @@ -6161,6 +6175,20 @@ spec:
in case of a failover the cluster will be writable for at least
a few seconds.
type: boolean
replicaServiceSpec:
description: Healthy replica service extra specification
properties:
annotations:
additionalProperties:
type: string
description: Annotations allow to specify annotations for MysqlCluster's
services
type: object
loadBalancer:
description: LoadBalancer configures whether a service is a LoadBalancer
or not.
type: boolean
type: object
replicas:
description: The number of pods. This updates replicas filed Defaults
to 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ spec:
spec:
description: 'MysqlClusterSpec defines the desired state of MysqlCluster nolint: maligned'
properties:
MasterServiceSpec:
description: Master service extra specification
properties:
annotations:
additionalProperties:
type: string
description: Annotations allow to specify annotations for MysqlCluster's services
type: object
loadBalancer:
description: LoadBalancer configures whether a service is a LoadBalancer or not.
type: boolean
type: object
backupCompressCommand:
description: BackupCompressCommand is a command to use for compressing the backup.
items:
Expand Down Expand Up @@ -3759,6 +3771,18 @@ spec:
readOnly:
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.
type: boolean
replicaServiceSpec:
description: Healthy replica service extra specification
properties:
annotations:
additionalProperties:
type: string
description: Annotations allow to specify annotations for MysqlCluster's services
type: object
loadBalancer:
description: LoadBalancer configures whether a service is a LoadBalancer or not.
type: boolean
type: object
replicas:
description: The number of pods. This updates replicas filed Defaults to 0
format: int32
Expand Down
19 changes: 19 additions & 0 deletions pkg/apis/mysql/v1alpha1/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ type MysqlClusterSpec struct {
// +optional
VolumeSpec VolumeSpec `json:"volumeSpec,omitempty"`

// Master service extra specification
// +optional
MasterServiceSpec ServiceSpec `json:"MasterServiceSpec,omitempty"`

// Healthy replica service extra specification
// +optional
ReplicaServiceSpec ServiceSpec `json:"replicaServiceSpec,omitempty"`

// TmpfsSize if specified, mounts a tmpfs of this size into /tmp
// DEPRECATED: use instead PodSpec.Volumes and PodSpec.VolumeMounts
// +optional
Expand Down Expand Up @@ -241,6 +249,17 @@ type VolumeSpec struct {
PersistentVolumeClaim *core.PersistentVolumeClaimSpec `json:"persistentVolumeClaim,omitempty"`
}

// ServiceSpec s the desired spec for addition configuration of MysqlCluster services
type ServiceSpec struct {
// LoadBalancer configures whether a service is a LoadBalancer or not.
// +optional
LoadBalancer bool `json:"loadBalancer,omitempty"`

// Annotations allow to specify annotations for MysqlCluster's services
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
}

// QueryLimits represents the pt-kill parameters, more info can be found
// here: https://www.percona.com/doc/percona-toolkit/LATEST/pt-kill.html
type QueryLimits struct {
Expand Down
24 changes: 24 additions & 0 deletions pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package mysqlcluster

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

return syncer.NewObjectSyncer("HealthyReplicasSVC", cluster.Unwrap(), service, c, func() error {
// set service type
if cluster.Spec.ReplicaServiceSpec.LoadBalancer {
service.Spec.Type = core.ServiceTypeLoadBalancer
}

// merge annotations
if err := mergo.Merge(&service.ObjectMeta.Annotations, cluster.Spec.ReplicaServiceSpec.Annotations); err != nil {
return err
}

// set service labels
service.Labels = cluster.GetLabels()
service.Labels["mysql.presslabs.org/service-type"] = "ready-replicas"
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/mysqlcluster/internal/syncer/master_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package mysqlcluster

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

return syncer.NewObjectSyncer("MasterSVC", cluster.Unwrap(), service, c, func() error {
// set service type
if cluster.Spec.MasterServiceSpec.LoadBalancer {
service.Spec.Type = core.ServiceTypeLoadBalancer
}

// merge annotations
if err := mergo.Merge(&service.ObjectMeta.Annotations, cluster.Spec.MasterServiceSpec.Annotations); err != nil {
return err
}

// set service labels
service.Labels = cluster.GetLabels()
service.Labels["mysql.presslabs.org/service-type"] = "master"
Expand Down
3 changes: 3 additions & 0 deletions pkg/internal/mysqlcluster/mysqlcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ var _ = Describe("Test MySQL cluster wrapper", func() {
Expect(cluster.Spec.MysqlConf).To(HaveKey(Equal("innodb-buffer-pool-size")))
Expect(cluster.Spec.MysqlConf).To(HaveKey(Equal("innodb-log-file-size")))
Expect(cluster.Spec.MysqlConf).NotTo(HaveKey(Equal("max-binlog-size")))

Expect(cluster.Spec.MasterServiceSpec.LoadBalancer).To(Equal(false))
Expect(cluster.Spec.ReplicaServiceSpec.LoadBalancer).To(Equal(false))
})

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

0 comments on commit 067b014

Please sign in to comment.