Skip to content

Commit 3546f37

Browse files
authored
fix(tidb): unexpectedly use secret for sem config (#6573)
1 parent a5ace22 commit 3546f37

6 files changed

Lines changed: 115 additions & 2 deletions

File tree

pkg/controllers/tidb/tasks/pod.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ func newPod(cluster *v1alpha1.Cluster, tidb *v1alpha1.TiDB, g features.Gates) *c
200200
vols = append(vols, corev1.Volume{
201201
Name: v1alpha1.VolumeNameSEM,
202202
VolumeSource: corev1.VolumeSource{
203-
Secret: &corev1.SecretVolumeSource{
204-
SecretName: coreutil.SEMConfigMapName(tidb),
203+
ConfigMap: &corev1.ConfigMapVolumeSource{
204+
LocalObjectReference: corev1.LocalObjectReference{
205+
Name: coreutil.SEMConfigMapName(tidb),
206+
},
205207
},
206208
},
207209
})

tests/e2e/data/cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
const (
2727
BootstrapSQLName = "bootstrap-sql"
28+
SEMConfigName = "sem-config"
2829
)
2930

3031
func NewCluster(namespace string, patches ...ClusterPatch) *v1alpha1.Cluster {

tests/e2e/data/tidb.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,70 @@ graceful-wait-before-shutdown = 20
213213
}
214214
})
215215
}
216+
217+
func WithSEMConfig() GroupPatch[*v1alpha1.TiDBGroup] {
218+
return GroupPatchFunc[*v1alpha1.TiDBGroup](func(obj *v1alpha1.TiDBGroup) {
219+
if obj.Spec.Template.Spec.Security == nil {
220+
obj.Spec.Template.Spec.Security = &v1alpha1.TiDBSecurity{}
221+
}
222+
sec := obj.Spec.Template.Spec.Security
223+
if sec.SEM == nil {
224+
sec.SEM = &v1alpha1.SEM{}
225+
}
226+
sec.SEM.Config.Name = SEMConfigName
227+
})
228+
}
229+
230+
// SEMConfig returns a simple sem config for test
231+
func SEMConfig() string {
232+
return `
233+
{
234+
"verison": "1",
235+
"tidb_version": "8.0",
236+
"restricted_databases": [
237+
"metrics_schema"
238+
],
239+
"restricted_tables" : [
240+
{
241+
"schema": "mysql",
242+
"name": "expr_pushdown_blacklist"
243+
},
244+
{
245+
"schema": "mysql",
246+
"name": "gc_delete_range"
247+
},
248+
{
249+
"schema": "mysql",
250+
"name": "gc_delete_range_done"
251+
},
252+
{
253+
"schema": "mysql",
254+
"name": "opt_rule_blacklist"
255+
},
256+
{
257+
"schema": "mysql",
258+
"name": "tidb"
259+
},
260+
{
261+
"schema": "mysql",
262+
"name": "global_variables"
263+
},
264+
],
265+
"restricted_variables" : [
266+
{
267+
"name": "hostname",
268+
"restriction-type": "replace",
269+
"readonly": true,
270+
"value": "localhost"
271+
},
272+
],
273+
"restricted_status" : [
274+
{
275+
"name": "tidb_gc_leader_desc",
276+
"restriction-type": "hidden"
277+
}
278+
],
279+
"restricted_static_privileges_col" : ["File_priv","Shutdown_priv"]
280+
}
281+
`
282+
}

tests/e2e/framework/framework.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,26 @@ func (f *Framework) SetupBootstrapSQL(sql string) {
230230
})
231231
}
232232

233+
func (f *Framework) SetupSEMConfig(cfg string) {
234+
ginkgo.BeforeEach(func(ctx context.Context) {
235+
cm := &corev1.ConfigMap{
236+
ObjectMeta: metav1.ObjectMeta{
237+
Name: data.SEMConfigName,
238+
Namespace: f.Namespace.Name,
239+
},
240+
Data: map[string]string{
241+
v1alpha1.FileNameSEMConfig: cfg,
242+
},
243+
}
244+
ginkgo.By("Creating a sem configmap")
245+
f.Must(f.Client.Create(ctx, cm))
246+
ginkgo.DeferCleanup(func(ctx context.Context) {
247+
ginkgo.By("Delete the sem configmap")
248+
f.Must(f.Client.Delete(ctx, cm))
249+
})
250+
})
251+
}
252+
233253
func (*Framework) Must(err error) {
234254
gomega.ExpectWithOffset(1, err).To(gomega.Succeed())
235255
}

tests/e2e/label/well_known.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ var (
5353
FeatureHotReload = ginkgo.Label("f:HotReload")
5454
FeaturePDMS = ginkgo.Label("f:PDMS")
5555

56+
// Config
57+
ConfigSEM = ginkgo.Label("cfg:SEM")
58+
ConfigTLS = ginkgo.Label("cfg:TLS")
59+
ConfigAuthToken = ginkgo.Label("cfg:AuthToken")
60+
ConfigBootstrapSQL = ginkgo.Label("cfg:BootstrapSQL")
61+
ConfigHotReload = ginkgo.Label("cfg:HotReload")
62+
ConfigPDMS = ginkgo.Label("cfg:PDMS")
63+
5664
// Mode
5765
ModeDisaggregatedTiFlash = ginkgo.Label("m:DisaggregatedTiFlash")
5866

tests/e2e/tidb/tidb.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ GRANT ALL PRIVILEGES ON *.* TO '%s'@'%s';`, sub, iss, email, sub, "%")
104104
})
105105
})
106106

107+
ginkgo.Context("SEMConfig", label.P1, label.ConfigSEM, func() {
108+
f.SetupSEMConfig(data.SEMConfig())
109+
f.SetupCluster()
110+
111+
ginkgo.It("should create the TiDB cluster with sem config", func(ctx context.Context) {
112+
pdg := f.MustCreatePD(ctx)
113+
kvg := f.MustCreateTiKV(ctx)
114+
dbg := f.MustCreateTiDB(ctx, data.WithSEMConfig())
115+
116+
f.WaitForPDGroupReady(ctx, pdg)
117+
f.WaitForTiKVGroupReady(ctx, kvg)
118+
f.WaitForTiDBGroupReady(ctx, dbg)
119+
})
120+
})
121+
107122
ginkgo.Context("Scale and Update", label.P0, func() {
108123
ginkgo.It("support scale TiDB from 1 to 4", label.Scale, func(ctx context.Context) {
109124
pdg := f.MustCreatePD(ctx)

0 commit comments

Comments
 (0)