Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow additional service configuration for MysqlCluster #747

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
40 changes: 40 additions & 0 deletions config/crd/bases/mysql.presslabs.org_mysqlclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ spec:
items:
type: string
type: array
masterServiceSpec:
description: Master service extra specification
properties:
allowedSourceRanges:
description: AllowedSourceRanges sets a list of CIDR blocks allowed
to access the cluster using LoadBalancer service.
items:
type: string
type: array
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
maxSlaveLatency:
description: MaxSlaveLatency represents the allowed latency for a
slave node in seconds. If set then the node with a latency grater
Expand Down Expand Up @@ -6161,6 +6181,26 @@ 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:
allowedSourceRanges:
description: AllowedSourceRanges sets a list of CIDR blocks allowed
to access the cluster using LoadBalancer service.
items:
type: string
type: array
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 @@ -87,6 +87,23 @@ spec:
items:
type: string
type: array
masterServiceSpec:
description: Master service extra specification
properties:
allowedSourceRanges:
description: AllowedSourceRanges sets a list of CIDR blocks allowed to access the cluster using LoadBalancer service.
items:
type: string
type: array
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
maxSlaveLatency:
description: MaxSlaveLatency represents the allowed latency for a slave node in seconds. If set then the node with a latency grater than this is removed from service.
format: int64
Expand Down Expand Up @@ -3759,6 +3776,23 @@ 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:
allowedSourceRanges:
description: AllowedSourceRanges sets a list of CIDR blocks allowed to access the cluster using LoadBalancer service.
items:
type: string
type: array
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
23 changes: 23 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,21 @@ type VolumeSpec struct {
PersistentVolumeClaim *core.PersistentVolumeClaimSpec `json:"persistentVolumeClaim,omitempty"`
}

// ServiceSpec is 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"`

// AllowedSourceRanges sets a list of CIDR blocks allowed to access the cluster using LoadBalancer service.
// +optional
AllowedSourceRanges []string `json:"allowedSourceRanges,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
29 changes: 29 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,17 @@ 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
service.Spec.LoadBalancerSourceRanges = cluster.Spec.ReplicaServiceSpec.AllowedSourceRanges
}

// 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
12 changes: 12 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,17 @@ 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
service.Spec.LoadBalancerSourceRanges = cluster.Spec.MasterServiceSpec.AllowedSourceRanges
}

// 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