Skip to content

Commit 9cbca29

Browse files
committed
fixes
1 parent 8d0043e commit 9cbca29

7 files changed

Lines changed: 18 additions & 29 deletions

File tree

api/v1/autoconfig_defaults_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ func TestCheckNSetDefaultsAutoConfig(t *testing.T) {
1818
wantLoadType: "",
1919
},
2020
"explicitly disabled keeps loadType unset": {
21-
enabled: ptr(false),
21+
enabled: new(false),
2222
wantEnabled: false,
2323
wantLoadType: "",
2424
},
2525
"explicitly enabled without loadType gets default": {
26-
enabled: ptr(true),
26+
enabled: new(true),
2727
wantEnabled: true,
2828
wantLoadType: AutoConfigLoadTypeSomeWrites,
2929
},
3030
"explicitly enabled with custom loadType is preserved": {
31-
enabled: ptr(true),
31+
enabled: new(true),
3232
loadType: AutoConfigLoadTypeHeavyWrites,
3333
wantEnabled: true,
3434
wantLoadType: AutoConfigLoadTypeHeavyWrites,
@@ -51,5 +51,3 @@ func TestCheckNSetDefaultsAutoConfig(t *testing.T) {
5151
})
5252
}
5353
}
54-
55-
func ptr(b bool) *bool { return &b }

cmd/example-gen/pkg/defaults/manual.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func ManualCluster(cr *apiv1.PerconaServerMySQL) {
3131
}
3232

3333
func mysqlDefaults(spec *apiv1.MySQLSpec) {
34-
podSpecDefaults(&spec.PodSpec, ImageMySQL, resources("2Gi", "1", "4Gi", "2"), configurationMySQL, 600, envList("BOOTSTRAP_READ_TIMEOUT", "600", "ASYNC_SOURCE_RETRY_COUNT", "3", "ASYNC_SOURCE_CONNECT_RETRY", "60"), envFromList("mysql-env-secret"))
34+
podSpecDefaults(&spec.PodSpec, ImageMySQL, resources("1Gi", "1", "2Gi", "2"), configurationMySQL, 600, envList("BOOTSTRAP_READ_TIMEOUT", "600", "ASYNC_SOURCE_RETRY_COUNT", "3", "ASYNC_SOURCE_CONNECT_RETRY", "60"), envFromList("mysql-env-secret"))
3535

3636
spec.AutoRecovery = true
3737
spec.VolumeSpec = nil

cmd/example-gen/pkg/defaults/preset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func FromPresets(cr any) error {
106106
},
107107
Resources: corev1.VolumeResourceRequirements{
108108
Requests: corev1.ResourceList{
109-
corev1.ResourceStorage: resource.MustParse("2Gi"),
109+
corev1.ResourceStorage: resource.MustParse("4Gi"),
110110
},
111111
},
112112
},

deploy/cr.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ spec:
207207
# - ReadWriteOnce
208208
resources:
209209
requests:
210-
storage: 5Gi
210+
storage: 4Gi
211211
# storageClassName: standard
212212
# configuration: |-
213213
# max_connections=250
@@ -1002,7 +1002,7 @@ spec:
10021002
# - ReadWriteOnce
10031003
# resources:
10041004
# requests:
1005-
# storage: 2Gi
1005+
# storage: 4Gi
10061006
# storageClassName: standard
10071007
# encryptionKeySecret:
10081008
# key: encryptionKey

pkg/controller/ps/mysql_autoconfig_test.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ps
22

33
import (
4-
"context"
54
"strings"
65
"testing"
76

@@ -53,7 +52,7 @@ func TestReconcileMySQLAutoConfig(t *testing.T) {
5352
t.Helper()
5453
cm := new(corev1.ConfigMap)
5554
nn := types.NamespacedName{Name: mysql.AutoConfigMapName(cr), Namespace: cr.Namespace}
56-
require.NoError(t, r.Client.Get(context.Background(), nn, cm))
55+
require.NoError(t, r.Get(t.Context(), nn, cm))
5756
return cm.Data[mysql.CustomConfigKey]
5857
}
5958

@@ -102,7 +101,7 @@ func TestReconcileMySQLAutoConfig(t *testing.T) {
102101
cr := newCR(tt.enabled, tt.version)
103102
r := newReconciler(t, cr)
104103

105-
require.NoError(t, r.reconcileMySQLAutoConfig(context.Background(), cr))
104+
require.NoError(t, r.reconcileMySQLAutoConfig(t.Context(), cr))
106105

107106
config := autoConfig(t, r, cr)
108107
assert.Contains(t, config, "innodb_buffer_pool_size=", "both paths size the buffer pool")
@@ -111,12 +110,8 @@ func TestReconcileMySQLAutoConfig(t *testing.T) {
111110
})
112111
}
113112

114-
// The redo log the calculator sizes from memory is preallocated on the data
115-
// volume at startup, and a node joining by clone needs free space for the
116-
// donor's estimate on top of its own. The reconcile trims it to fit rather
117-
// than leaving a cluster that cannot bootstrap.
118113
t.Run("a data volume smaller than the calculated redo log trims it", func(t *testing.T) {
119-
ctx := context.Background()
114+
ctx := t.Context()
120115
cr := newCR(true, "8.4")
121116
withDataVolume(cr, "2Gi")
122117
r := newReconciler(t, cr)
@@ -126,10 +121,8 @@ func TestReconcileMySQLAutoConfig(t *testing.T) {
126121
assert.Contains(t, autoConfig(t, r, cr), "innodb_redo_log_capacity=536870912")
127122
})
128123

129-
// Trimming stops at the smallest redo log MySQL accepts, so a volume below
130-
// that leaves nothing to write: the reconcile fails until the user resizes.
131124
t.Run("a data volume too small for the minimum redo log fails the reconcile", func(t *testing.T) {
132-
ctx := context.Background()
125+
ctx := t.Context()
133126
cr := newCR(true, "8.4")
134127
withDataVolume(cr, "16Mi")
135128
r := newReconciler(t, cr)
@@ -143,14 +136,12 @@ func TestReconcileMySQLAutoConfig(t *testing.T) {
143136
// No autotune fallback was written in its place.
144137
cm := new(corev1.ConfigMap)
145138
nn := types.NamespacedName{Name: mysql.AutoConfigMapName(cr), Namespace: cr.Namespace}
146-
assert.True(t, k8serrors.IsNotFound(r.Client.Get(ctx, nn, cm)),
139+
assert.True(t, k8serrors.IsNotFound(r.Get(ctx, nn, cm)),
147140
"no ConfigMap should be written when the calculated configuration does not fit")
148141
})
149142

150-
// The ConfigMap is rebuilt from the spec on every pass, so a wrong version
151-
// costs nothing more than the fallback it caused.
152143
t.Run("correcting the version restores the calculated configuration", func(t *testing.T) {
153-
ctx := context.Background()
144+
ctx := t.Context()
154145
cr := newCR(true, "5.7")
155146
r := newReconciler(t, cr)
156147

@@ -163,7 +154,7 @@ func TestReconcileMySQLAutoConfig(t *testing.T) {
163154
})
164155

165156
t.Run("correcting the version leaves no parameter of the wrong one behind", func(t *testing.T) {
166-
ctx := context.Background()
157+
ctx := t.Context()
167158
// Removed in MySQL 8.4, still emitted for 8.0 — and emitted bare, so
168159
// mysqld would refuse to boot on it.
169160
const removedIn84 = "innodb_log_file_size="

pkg/controller/ps/mysql_config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ func TestReconcileMySQLConfig(t *testing.T) {
158158
state apiv1.StatefulAppState // status.state
159159
mysqlState apiv1.StatefulAppState // status.mysql.state; defaults to ready
160160
currentConfig string
161-
autoConfig string // my.cnf in the ConfigMap; empty means no ConfigMap at all
162-
lastAppliedConfig string // JSON string on the statefulset annotation; empty means absent
163-
object []client.Object // what the API holds besides the CR, the ConfigMap and the statefulset; nil means a healthy cluster
161+
autoConfig string // my.cnf in the ConfigMap; empty means no ConfigMap at all
162+
lastAppliedConfig string // JSON string on the statefulset annotation; empty means absent
163+
object []client.Object // what the API holds besides the CR, the ConfigMap and the statefulset; nil means a healthy cluster
164164
stmtErrs map[string]string // stderr mysql answers a given statement with; drives the case on its own
165165

166166
expectedStmts []string // List of SET GLOBAL statements expected on all pods

pkg/mysql/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ func dropAliasedKeys(section *ini.Section) {
459459
}
460460

461461
func withMySQLdSection(part string) string {
462-
for _, line := range strings.Split(part, "\n") {
462+
for line := range strings.SplitSeq(part, "\n") {
463463
line = strings.TrimSpace(line)
464464
if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, ";") {
465465
continue

0 commit comments

Comments
 (0)