Skip to content

Commit bce6c92

Browse files
committed
Create service account for backup schedulers.
1 parent 40dcbb6 commit bce6c92

File tree

8 files changed

+68
-4
lines changed

8 files changed

+68
-4
lines changed

cmd/mysql-helper/apptakebackup/apptakebackup.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import (
2727
tb "github.com/presslabs/mysql-operator/cmd/mysql-helper/util"
2828
)
2929

30+
const (
31+
ncatIdleTimeout = "30"
32+
)
33+
3034
func RunTakeBackupCommand(stopCh <-chan struct{}, srcHost, destBucket string) error {
3135
glog.Infof("Take backup from '%s' to bucket '%s' started...", srcHost, destBucket)
3236
destBucket = normalizeBucketUri(destBucket)
@@ -35,7 +39,7 @@ func RunTakeBackupCommand(stopCh <-chan struct{}, srcHost, destBucket string) er
3539

3640
func pushBackupFromTo(srcHost, destBucket string) error {
3741
// TODO: document each func
38-
ncat := exec.Command("ncat", "--recv-only", srcHost, tb.BackupPort)
42+
ncat := exec.Command("ncat", "-i", ncatIdleTimeout, "--recv-only", srcHost, tb.BackupPort)
3943

4044
gzip := exec.Command("gzip", "-c")
4145

hack/charts/mysql-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ keywords:
66
- percona
77
- orchestrator
88
- presslabs
9-
version: 0.1.6
9+
version: 0.1.7
1010
home: https://github.com/presslabs/mysql-operator
1111
sources:
1212
- https://github.com/presslabs/mysql-operator.git
13-
appVersion: 0.1.6
13+
appVersion: 0.1.7

hack/charts/mysql-operator/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ spec:
4747
{{- if .Values.installCRDs }}
4848
- --install-crds
4949
{{- end }}
50+
{{- if .Values.rbac.create }}
51+
- --backup-service-account-name={{ template "mysql-operator.serviceAccountName" . }}-backups
52+
{{- end }}
5053
resources:
5154
{{ toYaml .Values.resources | nindent 12 }}
5255
livenessProbe:

hack/charts/mysql-operator/templates/rbac.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,38 @@ subjects:
5656
- name: {{ template "mysql-operator.serviceAccountName" . }}
5757
namespace: {{ .Release.Namespace | quote }}
5858
kind: ServiceAccount
59+
60+
---
61+
apiVersion: rbac.authorization.k8s.io/v1beta1
62+
kind: ClusterRole
63+
metadata:
64+
name: {{ template "mysql-operator.fullname" . }}-backups
65+
labels:
66+
app: {{ template "mysql-operator.name" . }}
67+
chart: {{ template "mysql-operator.chart" . }}
68+
release: {{ .Release.Name }}
69+
heritage: {{ .Release.Service }}
70+
rules:
71+
- apiGroups: ["mysql.presslabs.org"]
72+
resources: ["mysqlbackups"]
73+
verbs: ["*"]
74+
---
75+
apiVersion: rbac.authorization.k8s.io/v1beta1
76+
kind: ClusterRoleBinding
77+
metadata:
78+
name: {{ template "mysql-operator.fullname" . }}-backups
79+
labels:
80+
app: {{ template "mysql-operator.name" . }}
81+
chart: {{ template "mysql-operator.chart" . }}
82+
release: {{ .Release.Name }}
83+
heritage: {{ .Release.Service }}
84+
roleRef:
85+
apiGroup: rbac.authorization.k8s.io
86+
kind: ClusterRole
87+
name: {{ template "mysql-operator.fullname" . }}-backups
88+
subjects:
89+
- name: {{ template "mysql-operator.serviceAccountName" . }}-backups
90+
namespace: {{ .Release.Namespace | quote }}
91+
kind: ServiceAccount
92+
5993
{{- end -}}

hack/charts/mysql-operator/templates/serviceaccount.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,16 @@ metadata:
88
chart: {{ template "mysql-operator.chart" . }}
99
release: {{ .Release.Name }}
1010
heritage: {{ .Release.Service }}
11+
12+
---
13+
apiVersion: v1
14+
kind: ServiceAccount
15+
metadata:
16+
name: {{ template "mysql-operator.serviceAccountName" . }}-backups
17+
labels:
18+
app: {{ template "mysql-operator.name" . }}
19+
chart: {{ template "mysql-operator.chart" . }}
20+
release: {{ .Release.Name }}
21+
heritage: {{ .Release.Service }}
22+
1123
{{- end }}

hack/e2e-tests/mysql-operator-values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
extraArgs:
22
- -v=3
33

4+
rbac:
5+
create: true
6+
47
orchestrator:
58
topologyPassword: password1
69
antiAffinity: soft

pkg/mysqlcluster/cron_job.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (f *cFactory) ensurePodTemplate(spec core.PodSpec) core.PodSpec {
6565
}
6666

6767
spec.RestartPolicy = core.RestartPolicyOnFailure
68+
spec.ServiceAccountName = f.opt.BackupSchedulerServiceAccountName
6869

6970
spec.Containers[0].Name = "schedule-backup"
7071
spec.Containers[0].Image = f.cluster.Spec.GetHelperImage()

pkg/util/options/options.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ type Options struct {
5353
OrchestratorTopologyPassword string
5454
OrchestratorTopologyUser string
5555

56-
JobCompleteSuccessGraceTime time.Duration
56+
JobCompleteSuccessGraceTime time.Duration
57+
BackupSchedulerServiceAccountName string
5758

5859
HttpServeAddr string
5960
}
@@ -88,6 +89,8 @@ const (
8889
defaultOrchestratorTopologyPassword = ""
8990

9091
defaultHttpServeAddr = ":80"
92+
93+
defaultBackupSchedServiceAccountName = "default"
9194
)
9295

9396
var (
@@ -120,6 +123,10 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
120123
fs.StringVar(&o.HttpServeAddr, "http-serve-addr", defaultHttpServeAddr,
121124
"The address for http server.")
122125

126+
fs.StringVar(&o.BackupSchedulerServiceAccountName, "backup-service-account-name",
127+
defaultBackupSchedServiceAccountName, "Specify the service account for backup scheduler. "+
128+
"This accounts should have permissions to create backups.")
129+
123130
}
124131

125132
var instance *Options

0 commit comments

Comments
 (0)