Skip to content
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
24 changes: 24 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2664,6 +2664,18 @@ Kubernetes core/v1.PullPolicy
</tr>
<tr>
<td>
<code>serviceAccountName</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>ServiceAccountName is the name of the ServiceAccount to use to run TiDB initializer Pods.</p>
</td>
</tr>
<tr>
<td>
<code>permitHost</code></br>
<em>
string
Expand Down Expand Up @@ -27273,6 +27285,18 @@ Kubernetes core/v1.PullPolicy
</tr>
<tr>
<td>
<code>serviceAccountName</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>ServiceAccountName is the name of the ServiceAccount to use to run TiDB initializer Pods.</p>
</td>
</tr>
<tr>
<td>
<code>permitHost</code></br>
<em>
string
Expand Down
2 changes: 2 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63536,6 +63536,8 @@ spec:
x-kubernetes-int-or-string: true
type: object
type: object
serviceAccountName:
type: string
timezone:
type: string
tlsClientSecretName:
Expand Down
2 changes: 2 additions & 0 deletions manifests/crd/v1/pingcap.com_tidbinitializers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ spec:
x-kubernetes-int-or-string: true
type: object
type: object
serviceAccountName:
type: string
timezone:
type: string
tlsClientSecretName:
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/pingcap/v1alpha1/openapi_generated.go

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

4 changes: 4 additions & 0 deletions pkg/apis/pingcap/v1alpha1/tidbinitializer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ type TidbInitializerSpec struct {
// +optional
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`

// ServiceAccountName is the name of the ServiceAccount to use to run TiDB initializer Pods.
// +optional
ServiceAccountName string `json:"serviceAccountName,omitempty"`

// permitHost is the host which will only be allowed to connect to the TiDB.
// +optional
PermitHost *string `json:"permitHost,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions pkg/manager/member/tidb_init_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func (m *tidbInitManager) makeTiDBInitJob(ti *v1alpha1.TidbInitializer) (*batchv
},
Spec: corev1.PodSpec{
ImagePullSecrets: ti.Spec.ImagePullSecrets,
ServiceAccountName: ti.Spec.ServiceAccountName,
SecurityContext: ti.Spec.PodSecurityContext,
AutomountServiceAccountToken: pointer.BoolPtr(false),
InitContainers: []corev1.Container{
Expand Down
15 changes: 15 additions & 0 deletions pkg/manager/member/tidb_init_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ func TestMakeTiDBInitJobDisablesServiceAccountTokenAutomount(t *testing.T) {
g.Expect(*job.Spec.Template.Spec.AutomountServiceAccountToken).To(BeFalse())
}

func TestMakeTiDBInitJobUsesServiceAccountName(t *testing.T) {
g := NewGomegaWithT(t)
tim, _, indexers := newFakeTiDBInitManager()
ti := newTidbInitializerForTiDB()
ti.Spec.ServiceAccountName = "tidb-initializer"
tc := newTidbClusterForTiDB()

err := indexers.tc.Add(tc)
g.Expect(err).NotTo(HaveOccurred())

job, err := tim.makeTiDBInitJob(ti)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(job.Spec.Template.Spec.ServiceAccountName).To(Equal("tidb-initializer"))
}

func newFakeTiDBInitManager() (*tidbInitManager, *tidbMemberManager, *fakeIndexers) {
tmm, _, _, indexers := newFakeTiDBMemberManager()
indexers.job = tmm.deps.KubeInformerFactory.Batch().V1().Jobs().Informer().GetIndexer()
Expand Down
Loading