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

Support pod SecurityContext for PD #3278

Merged
merged 10 commits into from
Sep 24, 2020
1 change: 1 addition & 0 deletions pkg/manager/member/pd_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ func getNewPDSetForTidbCluster(tc *v1alpha1.TidbCluster, cm *corev1.ConfigMap) (
if podSpec.ServiceAccountName == "" {
podSpec.ServiceAccountName = tc.Spec.ServiceAccount
}
podSpec.SecurityContext = basePDSpec.PodSecurityContext().DeepCopy()

pdSet := &apps.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Expand Down
63 changes: 63 additions & 0 deletions pkg/manager/member/pd_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ func testAdditionalVolumes(t *testing.T, additionalVolumes []corev1.Volume) func

func TestGetNewPDSetForTidbCluster(t *testing.T) {
enable := true
asNonRoot := true
tests := []struct {
name string
tc v1alpha1.TidbCluster
Expand Down Expand Up @@ -1332,6 +1333,68 @@ func TestGetNewPDSetForTidbCluster(t *testing.T) {
},
testSts: testAdditionalVolumes(t, []corev1.Volume{{Name: "test", VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}}}}),
},
{
name: "PD with PodSecurityContext",
tc: v1alpha1.TidbCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "tc",
Namespace: "ns",
},
Spec: v1alpha1.TidbClusterSpec{
PD: &v1alpha1.PDSpec{
ComponentSpec: v1alpha1.ComponentSpec{
PodSecurityContext: &corev1.PodSecurityContext{
RunAsNonRoot: &asNonRoot,
Sysctls: []corev1.Sysctl{
{
Name: "net.core.somaxconn",
Value: "32768",
},
{
Name: "net.ipv4.tcp_syncookies",
Value: "0",
},
{
Name: "net.ipv4.tcp_keepalive_time",
Value: "300",
},
{
Name: "net.ipv4.tcp_keepalive_intvl",
Value: "75",
},
},
},
},
},
TiDB: &v1alpha1.TiDBSpec{},
TiKV: &v1alpha1.TiKVSpec{},
},
},
testSts: func(sts *apps.StatefulSet) {
g := NewGomegaWithT(t)
g.Expect(sts.Spec.Template.Spec.SecurityContext).To(Equal(&corev1.PodSecurityContext{
RunAsNonRoot: &asNonRoot,
Sysctls: []corev1.Sysctl{
{
Name: "net.core.somaxconn",
Value: "32768",
},
{
Name: "net.ipv4.tcp_syncookies",
Value: "0",
},
{
Name: "net.ipv4.tcp_keepalive_time",
Value: "300",
},
{
Name: "net.ipv4.tcp_keepalive_intvl",
Value: "75",
},
},
}))
},
},
// TODO add more tests
}

Expand Down