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

feat: expose probe in mysqlcluster #882

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* `MysqlDatabase` `MysqlUser` Add delete policy
* Add `PtHeartbeatResources` in `.Spec.PodSpec` to allow the user specifying resources for pt-heartbeat.
* Set `MysqlCluter.Spec.BackupSchedule` to empty string to disable recurrent backups
* Add `MySQLLivenessProbe` `MySQLReadinessProbe` `SidecarReadinessProbe` `ExporterLivenessProbe` in `.Spec.PodSpec` to allow the user special probe

### Changed

Expand Down
356 changes: 356 additions & 0 deletions config/crd/bases/mysql.presslabs.org_mysqlclusters.yaml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions deploy/charts/mysql-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ appDatabase: ""
# appSecretAnnotations: {}

podSpec:
# mysqlReadinessProbe:
# mysqlLivenessProbe:
# sidecarReadinessProbe:
# exporterLivenessProbe:
mysqlConf:
volumeSpec:

Expand Down

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions examples/example-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,48 @@ spec:
# exec:
# command:
# - /scripts/demote-if-master
# mysqlReadinessProbe:
# exec:
# command:
# - /bin/sh
# - -c
# - test $(mysql --defaults-file=/etc/mysql/client.conf -NB -e 'SELECT COUNT(*) FROM sys_operator.status WHERE name="configured" AND value="1"') -eq 1
# failureThreshold: 3
# initialDelaySeconds: 5
# periodSeconds: 2
# successThreshold: 1
# timeoutSeconds: 5
# mysqlLivenessProbe:
# exec:
# command:
# - mysqladmin
# - --defaults-file=/etc/mysql/client.conf
# - ping
# failureThreshold: 3
# initialDelaySeconds: 600
# periodSeconds: 5
# successThreshold: 1
# timeoutSeconds: 5
# sidecarReadinessProbe:
# failureThreshold: 3
# httpGet:
# path: /health
# port: 8080
# scheme: HTTP
# initialDelaySeconds: 30
# periodSeconds: 5
# successThreshold: 1
# timeoutSeconds: 5
# exporterLivenessProbe:
# failureThreshold: 3
# httpGet:
# path: /metrics
# port: 9125
# scheme: HTTP
# initialDelaySeconds: 30
# periodSeconds: 30
# successThreshold: 1
# timeoutSeconds: 30
# nodeSelector: {}
# resources:
# requests:
Expand Down
22 changes: 13 additions & 9 deletions pkg/apis/mysql/v1alpha1/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,19 @@ type PodSpec struct {
ImagePullPolicy core.PullPolicy `json:"imagePullPolicy,omitempty"`
ImagePullSecrets []core.LocalObjectReference `json:"imagePullSecrets,omitempty"`

Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Resources core.ResourceRequirements `json:"resources,omitempty"`
Affinity *core.Affinity `json:"affinity,omitempty"`
MysqlLifecycle *core.Lifecycle `json:"mysqlLifecycle,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Tolerations []core.Toleration `json:"tolerations,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Resources core.ResourceRequirements `json:"resources,omitempty"`
Affinity *core.Affinity `json:"affinity,omitempty"`
MysqlLifecycle *core.Lifecycle `json:"mysqlLifecycle,omitempty"`
MySQLReadinessProbe *core.Probe `json:"mysqlReadinessProbe,omitempty"`
MySQLLivenessProbe *core.Probe `json:"mysqlLivenessProbe,omitempty"`
SidecarReadinessProbe *core.Probe `json:"sidecarReadinessProbe,omitempty"`
ExporterLivenessProbe *core.Probe `json:"exporterLivenessProbe,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Tolerations []core.Toleration `json:"tolerations,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`

BackupAffinity *core.Affinity `json:"backupAffinity,omitempty"`
BackupNodeSelector map[string]string `json:"backupNodeSelector,omitempty"`
Expand Down
20 changes: 20 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.

74 changes: 45 additions & 29 deletions pkg/controller/mysqlcluster/internal/syncer/statefullset.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,19 @@ func (s *sfsSyncer) ensureContainersSpec() []core.Container {
ContainerPort: MysqlPort,
})
mysql.Resources = s.ensureResources(containerMysqlName)
mysql.LivenessProbe = ensureProbe(60, 5, 5, core.Handler{
Exec: &core.ExecAction{
Command: []string{
"mysqladmin",
fmt.Sprintf("--defaults-file=%s", confClientPath),
"ping",
if probe := s.cluster.Spec.PodSpec.MySQLLivenessProbe; probe == nil {
mysql.LivenessProbe = ensureProbe(60, 5, 5, core.Handler{
Exec: &core.ExecAction{
Command: []string{
"mysqladmin",
fmt.Sprintf("--defaults-file=%s", confClientPath),
"ping",
},
},
},
})
})
} else {
mysql.LivenessProbe = probe
}

// set lifecycle hook on MySQL container
if s.cluster.Spec.PodSpec.MysqlLifecycle != nil {
Expand All @@ -404,14 +408,18 @@ func (s *sfsSyncer) ensureContainersSpec() []core.Container {
confClientPath, constants.OperatorDbName, constants.OperatorStatusTableName)

// we have to know ASAP when server is not ready to remove it from endpoints
mysql.ReadinessProbe = ensureProbe(5, 5, 2, core.Handler{
Exec: &core.ExecAction{
Command: []string{
"/bin/sh", "-c",
fmt.Sprintf(`test $(%s) -eq 1`, mysqlTestCmd),
if probe := s.cluster.Spec.PodSpec.MySQLReadinessProbe; probe == nil {
mysql.ReadinessProbe = ensureProbe(5, 5, 2, core.Handler{
Exec: &core.ExecAction{
Command: []string{
"/bin/sh", "-c",
fmt.Sprintf(`test $(%s) -eq 1`, mysqlTestCmd),
},
},
},
})
})
} else {
mysql.ReadinessProbe = probe
}

// SIDECAR container
sidecar := s.ensureContainer(containerSidecarName,
Expand All @@ -423,13 +431,17 @@ func (s *sfsSyncer) ensureContainersSpec() []core.Container {
ContainerPort: SidecarServerPort,
})
sidecar.Resources = s.ensureResources(containerSidecarName)
sidecar.ReadinessProbe = ensureProbe(30, 5, 5, core.Handler{
HTTPGet: &core.HTTPGetAction{
Path: SidecarServerProbePath,
Port: intstr.FromInt(SidecarServerPort),
Scheme: core.URISchemeHTTP,
},
})
if probe := s.cluster.Spec.PodSpec.SidecarReadinessProbe; probe == nil {
sidecar.ReadinessProbe = ensureProbe(30, 5, 5, core.Handler{
HTTPGet: &core.HTTPGetAction{
Path: SidecarServerProbePath,
Port: intstr.FromInt(SidecarServerPort),
Scheme: core.URISchemeHTTP,
},
})
} else {
sidecar.ReadinessProbe = probe
}

// METRICS container
exporterCommand := []string{
Expand All @@ -455,13 +467,17 @@ func (s *sfsSyncer) ensureContainersSpec() []core.Container {

exporter.Resources = s.ensureResources(containerExporterName)

exporter.LivenessProbe = ensureProbe(30, 30, 30, core.Handler{
HTTPGet: &core.HTTPGetAction{
Path: ExporterPath,
Port: ExporterTargetPort,
Scheme: core.URISchemeHTTP,
},
})
if probe := s.cluster.Spec.PodSpec.ExporterLivenessProbe; probe == nil {
exporter.LivenessProbe = ensureProbe(30, 30, 30, core.Handler{
HTTPGet: &core.HTTPGetAction{
Path: ExporterPath,
Port: ExporterTargetPort,
Scheme: core.URISchemeHTTP,
},
})
} else {
exporter.LivenessProbe = probe
}

// PT-HEARTBEAT container
heartbeat := s.ensureContainer(containerHeartBeatName,
Expand Down