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

Disable the delay check if .spec.maxDelaySeconds == 0 #516

Merged
merged 2 commits into from
Mar 16, 2023
Merged
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: 1 addition & 1 deletion api/v1beta1/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type MySQLClusterSpec struct {
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=60
// +optional
MaxDelaySeconds int `json:"maxDelaySeconds,omitempty"`
MaxDelaySeconds *int `json:"maxDelaySeconds,omitempty"`

// StartupWaitSeconds is the maximum duration to wait for `mysqld` container to start working.
// The default is 3600 seconds.
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/zz_generated.conversion.go

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

5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion api/v1beta2/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type MySQLClusterSpec struct {
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=60
// +optional
MaxDelaySeconds int `json:"maxDelaySeconds,omitempty"`
MaxDelaySeconds *int `json:"maxDelaySeconds,omitempty"`

// StartupWaitSeconds is the maximum duration to wait for `mysqld` container to start working.
// The default is 3600 seconds.
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

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

4 changes: 3 additions & 1 deletion controllers/mysql_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ func (r *MySQLClusterReconciler) makeV1AgentContainer(cluster *mocov1beta2.MySQL
WithName(constants.AgentContainerName).
WithImage(r.AgentImage)

c.WithArgs("--max-delay", fmt.Sprintf("%ds", cluster.Spec.MaxDelaySeconds))
if cluster.Spec.MaxDelaySeconds != nil {
c.WithArgs("--max-delay", fmt.Sprintf("%ds", *cluster.Spec.MaxDelaySeconds))
}
if cluster.Spec.LogRotationSchedule != "" {
c.WithArgs("--log-rotation-schedule", cluster.Spec.LogRotationSchedule)
}
Expand Down
35 changes: 34 additions & 1 deletion controllers/mysqlcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ var _ = Describe("MySQLCluster reconciler", func() {
case constants.AgentContainerName:
foundAgent = true
Expect(c.Image).To(Equal(testAgentImage))
Expect(c.Args).To(Equal([]string{"--max-delay", "60s"}))
Expect(c.Resources.Requests).To(Equal(corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m"), corev1.ResourceMemory: resource.MustParse("100Mi")}))
Expect(c.Resources.Limits).To(Equal(corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m"), corev1.ResourceMemory: resource.MustParse("100Mi")}))
case constants.SlowQueryLogAgentContainerName:
Expand Down Expand Up @@ -831,7 +832,7 @@ var _ = Describe("MySQLCluster reconciler", func() {
cluster.Spec.Replicas = 5
cluster.Spec.ReplicationSourceSecretName = nil
cluster.Spec.Collectors = []string{"engine_innodb_status", "info_schema.innodb_metrics"}
cluster.Spec.MaxDelaySeconds = 20
cluster.Spec.MaxDelaySeconds = pointer.Int(20)
cluster.Spec.StartupWaitSeconds = 3
cluster.Spec.LogRotationSchedule = "0 * * * *"
cluster.Spec.DisableSlowQueryLogContainer = true
Expand Down Expand Up @@ -986,6 +987,38 @@ var _ = Describe("MySQLCluster reconciler", func() {
}
}
Expect(foundDummyVolume).To(BeTrue())

By("updating MySQLCluster (MaxDelaySeconds=0)")
cluster = &mocov1beta2.MySQLCluster{}
err = k8sClient.Get(ctx, client.ObjectKey{Namespace: "test", Name: "test"}, cluster)
Expect(err).NotTo(HaveOccurred())

cluster.Spec.MaxDelaySeconds = pointer.Int(0)

err = k8sClient.Update(ctx, cluster)
Expect(err).NotTo(HaveOccurred())

Eventually(func() error {
c := &mocov1beta2.MySQLCluster{}
if err := k8sClient.Get(ctx, client.ObjectKey{Namespace: "test", Name: "test"}, c); err != nil {
return err
}
if c.Status.ReconcileInfo.Generation != c.Generation {
return fmt.Errorf("not yet reconciled: generation=%d", c.Status.ReconcileInfo.Generation)
}
return nil
}).Should(Succeed())

sts = &appsv1.StatefulSet{}
err = k8sClient.Get(ctx, client.ObjectKey{Namespace: "test", Name: "moco-test"}, sts)
Expect(err).NotTo(HaveOccurred())

for _, c := range sts.Spec.Template.Spec.Containers {
switch c.Name {
case constants.AgentContainerName:
Expect(c.Args).To(ContainElement("0s"))
}
}
})

It("should reconcile a pod disruption budget", func() {
Expand Down
2 changes: 1 addition & 1 deletion docs/crd_mysqlcluster_v1beta1.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ MySQLClusterSpec defines the desired state of MySQLCluster
| replicationSourceSecretName | ReplicationSourceSecretName is a `Secret` name which contains replication source info. If this field is given, the `MySQLCluster` works as an intermediate primary. | *string | false |
| collectors | Collectors is the list of collector flag names of mysqld_exporter. If this field is not empty, MOCO adds mysqld_exporter as a sidecar to collect and export mysqld metrics in Prometheus format.\n\nSee https://github.com/prometheus/mysqld_exporter/blob/master/README.md#collector-flags for flag names.\n\nExample: [\"engine_innodb_status\", \"info_schema.innodb_metrics\"] | []string | false |
| serverIDBase | ServerIDBase, if set, will become the base number of server-id of each MySQL instance of this cluster. For example, if this is 100, the server-ids will be 100, 101, 102, and so on. If the field is not given or zero, MOCO automatically sets a random positive integer. | int32 | false |
| maxDelaySeconds | MaxDelaySeconds configures the readiness probe of mysqld container. For a replica mysqld instance, if it is delayed to apply transactions over this threshold, the mysqld instance will be marked as non-ready. The default is 60 seconds. Setting this field to 0 disables the delay check in the probe. | int | false |
| maxDelaySeconds | MaxDelaySeconds configures the readiness probe of mysqld container. For a replica mysqld instance, if it is delayed to apply transactions over this threshold, the mysqld instance will be marked as non-ready. The default is 60 seconds. Setting this field to 0 disables the delay check in the probe. | *int | false |
| startupDelaySeconds | StartupWaitSeconds is the maximum duration to wait for `mysqld` container to start working. The default is 3600 seconds. | int32 | false |
| logRotationSchedule | LogRotationSchedule specifies the schedule to rotate MySQL logs. If not set, the default is to rotate logs every 5 minutes. See https://pkg.go.dev/github.com/robfig/cron/v3#hdr-CRON_Expression_Format for the field format. | string | false |
| backupPolicyName | The name of BackupPolicy custom resource in the same namespace. If this is set, MOCO creates a CronJob to take backup of this MySQL cluster periodically. | *string | true |
Expand Down
2 changes: 1 addition & 1 deletion docs/crd_mysqlcluster_v1beta2.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ MySQLClusterSpec defines the desired state of MySQLCluster
| replicationSourceSecretName | ReplicationSourceSecretName is a `Secret` name which contains replication source info. If this field is given, the `MySQLCluster` works as an intermediate primary. | *string | false |
| collectors | Collectors is the list of collector flag names of mysqld_exporter. If this field is not empty, MOCO adds mysqld_exporter as a sidecar to collect and export mysqld metrics in Prometheus format.\n\nSee https://github.com/prometheus/mysqld_exporter/blob/master/README.md#collector-flags for flag names.\n\nExample: [\"engine_innodb_status\", \"info_schema.innodb_metrics\"] | []string | false |
| serverIDBase | ServerIDBase, if set, will become the base number of server-id of each MySQL instance of this cluster. For example, if this is 100, the server-ids will be 100, 101, 102, and so on. If the field is not given or zero, MOCO automatically sets a random positive integer. | int32 | false |
| maxDelaySeconds | MaxDelaySeconds configures the readiness probe of mysqld container. For a replica mysqld instance, if it is delayed to apply transactions over this threshold, the mysqld instance will be marked as non-ready. The default is 60 seconds. Setting this field to 0 disables the delay check in the probe. | int | false |
| maxDelaySeconds | MaxDelaySeconds configures the readiness probe of mysqld container. For a replica mysqld instance, if it is delayed to apply transactions over this threshold, the mysqld instance will be marked as non-ready. The default is 60 seconds. Setting this field to 0 disables the delay check in the probe. | *int | false |
| startupWaitSeconds | StartupWaitSeconds is the maximum duration to wait for `mysqld` container to start working. The default is 3600 seconds. | int32 | false |
| logRotationSchedule | LogRotationSchedule specifies the schedule to rotate MySQL logs. If not set, the default is to rotate logs every 5 minutes. See https://pkg.go.dev/github.com/robfig/cron/v3#hdr-CRON_Expression_Format for the field format. | string | false |
| backupPolicyName | The name of BackupPolicy custom resource in the same namespace. If this is set, MOCO creates a CronJob to take backup of this MySQL cluster periodically. | *string | true |
Expand Down