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 IAM role for backup CRD #1861

Merged
merged 22 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8de010c
backup: support iam pattern for backup CRD
shuijing198799 Mar 3, 2020
dea5d41
resolve conflict
shuijing198799 Mar 4, 2020
1e9257b
Merge remote-tracking branch 'upstream/master' into yinliang/support-…
shuijing198799 Mar 5, 2020
0c5ffe5
ignore backup secret name
shuijing198799 Mar 8, 2020
5ea6b00
support KMS in operator
shuijing198799 Mar 9, 2020
d47ee66
backup: specify serviceaccount for backup and restore, put annotation…
shuijing198799 Mar 10, 2020
c4ad022
modify code
shuijing198799 Mar 10, 2020
83e6bf2
backup : fix sh
shuijing198799 Mar 10, 2020
0756ac1
remove blank
shuijing198799 Mar 10, 2020
9a5ce25
address comment
shuijing198799 Mar 10, 2020
7c1079e
add annotations example for backup and restore yaml
shuijing198799 Mar 11, 2020
a8de3d6
comment out annotations
shuijing198799 Mar 11, 2020
9ea58ca
add annotation example to schedule backup yaml
shuijing198799 Mar 11, 2020
be94fe5
add aws s3 br example
shuijing198799 Mar 11, 2020
e7cae78
remove kms only support iam
shuijing198799 Mar 11, 2020
649c916
update generator files
shuijing198799 Mar 11, 2020
a890a24
update generator files
shuijing198799 Mar 11, 2020
8286993
Merge remote-tracking branch 'upstream/master' into yinliang/support-…
shuijing198799 Mar 11, 2020
f1df1bc
add Serviceaccount in backup_clean
shuijing198799 Mar 11, 2020
f461ebf
convert host and region to normal one
shuijing198799 Mar 11, 2020
d5ee341
Merge branch 'master' into yinliang/support-iam-pattern
DanielZhangQD Mar 11, 2020
c68a2bd
Merge branch 'master' into yinliang/support-iam-pattern
sre-bot Mar 11, 2020
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
3 changes: 1 addition & 2 deletions images/tidb-backup-manager/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM pingcap/tidb-enterprise-tools:latest

ARG VERSION=v1.48.0
ARG VERSION=v1.51.0
RUN apk update && apk add ca-certificates

RUN wget -nv https://github.com/ncw/rclone/releases/download/${VERSION}/rclone-${VERSION}-linux-amd64.zip \
Expand Down
33 changes: 33 additions & 0 deletions manifests/backup/backup-aws-s3-br.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
apiVersion: pingcap.com/v1alpha1
kind: Backup
metadata:
name: demo1-backup-s3
namespace: test1
# annotations:
# iam.amazonaws.com/role: "arn:aws:iam::123456789:role"
spec:
# backupType: full
# serviceAccount: myServiceAccount
br:
cluster: myCluster
# clusterNamespce: <backup-namespace>
# enableTLSClient: true
# logLevel: info
# statusAddr: <status-addr>
# concurrency: 4
# rateLimit: 0
# timeAgo: <time>
# checksum: true
# sendCredToTikv: true
from:
host: 172.30.6.56
secretName: mySecret
# port: 4000
# user: root
s3:
provider: aws
region: us-west-2
bucket: backup
prefix: test1-demo1
# secretName: aws-secret
17 changes: 12 additions & 5 deletions manifests/backup/backup-s3-br.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@ kind: Backup
metadata:
name: demo1-backup-s3
namespace: test1
# annotations:
# iam.amazonaws.com/role: "arn:aws:iam::123456789:role"
spec:
#backupType: full
# backupType: full
shuijing198799 marked this conversation as resolved.
Show resolved Hide resolved
# serviceAccount: myServiceAccount
br:
pd: 10.233.40.168:2379
# ca: <ca>
# cert: <cert>
# key: <key>
cluster: myCluster
shuijing198799 marked this conversation as resolved.
Show resolved Hide resolved
# clusterNamespce: <backup-namespace>
# enableTLSClient: true
# logLevel: info
# statusAddr: <status-addr>
# concurrency: 4
# rateLimit: 0
# timeAgo: <time>
# checksum: true
# sendCredToTikv: true
from:
host: 172.30.6.56
secretName: mySecret
# port: 4000
# user: root
s3:
provider: ceph
endpoint: http://10.233.57.220
Expand Down
38 changes: 38 additions & 0 deletions manifests/backup/backup-schedule-aws-s3-br.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
apiVersion: pingcap.com/v1alpha1
kind: BackupSchedule
metadata:
name: demo1-backup-schedule-s3
namespace: test1
# annotations:
# iam.amazonaws.com/role: "arn:aws:iam::123456789:role"
spec:
#maxBackups: 5
#pause: true
maxReservedTime: "3h"
schedule: "*/2 * * * *"
backupTemplate:
#backupType: full
# serviceAccount: myServiceAccount
br:
cluster: myCluster
# clusterNamespce: backupNamespace
# enableTLSClient: true
# logLevel: info
# statusAddr: <status-addr>
# concurrency: 4
# rateLimit: 0
# timeAgo: <time>
# checksum: true
# sendCredToTikv: true
from:
host: 172.30.6.56
secretName: mysecret
# port: 4000
# user: root
s3:
provider: aws
region: us-west-2
bucket: backup
prefix: test1-demo1
# secretName: aws-secret
15 changes: 11 additions & 4 deletions manifests/backup/backup-schedule-s3-br.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@ kind: BackupSchedule
metadata:
name: demo1-backup-schedule-s3
namespace: test1
# annotations:
# iam.amazonaws.com/role: "arn:aws:iam::123456789:role"
shuijing198799 marked this conversation as resolved.
Show resolved Hide resolved
spec:
#maxBackups: 5
#pause: true
maxReservedTime: "3h"
schedule: "*/2 * * * *"
backupTemplate:
#backupType: full
# serviceAccount: myServiceAccount
br:
pd: 10.233.40.168:2379
# ca: <ca>
# cert: <cert>
# key: <key>
cluster: myCluster
# clusterNamespce: backupNamespace
# enableTLSClient: true
# logLevel: info
# statusAddr: <status-addr>
# concurrency: 4
# rateLimit: 0
# timeAgo: <time>
# checksum: true
# sendCredToTikv: true
from:
host: 172.30.6.56
secretName: mysecret
# port: 4000
# user: root
s3:
provider: ceph
endpoint: http://10.233.57.220
Expand Down
35 changes: 35 additions & 0 deletions manifests/backup/restore-aws-s3-br.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
apiVersion: pingcap.com/v1alpha1
kind: Restore
metadata:
name: demo1-restore-s3-br
namespace: test1
# annotations:
# iam.amazonaws.com/role: "arn:aws:iam::123456789:role"
spec:
# backupType: full
# serviceAccount: myServiceAccount
br:
cluster: myCluster
# clusterNamespce: <restore-namespace>
# enableTLSClient: true
# db: <db-name>
# table: <table-name>
# logLevel: info
# statusAddr: <status-addr>
# concurrency: 4
# rateLimit: 0
# timeAgo: <time>
# checksum: true
# sendCredToTikv: true
to:
host: 172.30.6.56
secretName: mySecret
# port: 4000
# user: root
s3:
provider: aws
region: us-west-2
bucket: backup
prefix: test1-demo1
# secretName: aws-secret
15 changes: 11 additions & 4 deletions manifests/backup/restore-s3-br.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@ kind: Restore
metadata:
name: demo1-restore-s3-br
namespace: test1
# annotations:
# iam.amazonaws.com/role: "arn:aws:iam::123456789:role"
spec:
# backupType: full
# serviceAccount: myServiceAccount
br:
pd: 10.233.40.168:2379
cluster: myCluster
# clusterNamespce: <restore-namespace>
# enableTLSClient: true
# db: <db-name>
# table: <table-name>
# ca: <ca>
# cert: <cert>
# key: <key>
# logLevel: info
# statusAddr: <status-addr>
# concurrency: 4
# rateLimit: 0
# timeAgo: <time>
# checksum: true
# sendCredToTikv: true
to:
host: 172.30.6.56
secretName: mySecret
# port: 4000
# user: root
s3:
provider: ceph
endpoint: http://10.233.57.220
Expand Down
12 changes: 9 additions & 3 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6899,8 +6899,10 @@ spec:
type: string
required:
- provider
- secretName
type: object
serviceAccount:
description: Specify service account of backup
type: string
storageClassName:
description: The storageClassName of the persistent volume for Backup
data storage. Defaults to Kubernetes default storage class.
Expand Down Expand Up @@ -7715,8 +7717,10 @@ spec:
type: string
required:
- provider
- secretName
type: object
serviceAccount:
description: Specify service account of restore
type: string
storageClassName:
description: The storageClassName of the persistent volume for Restore
data storage. Defaults to Kubernetes default storage class.
Expand Down Expand Up @@ -8620,8 +8624,10 @@ spec:
type: string
required:
- provider
- secretName
type: object
serviceAccount:
description: Specify service account of backup
type: string
storageClassName:
description: The storageClassName of the persistent volume for Backup
data storage. Defaults to Kubernetes default storage class.
Expand Down
16 changes: 15 additions & 1 deletion pkg/apis/pingcap/v1alpha1/openapi_generated.go

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

6 changes: 5 additions & 1 deletion pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ type S3StorageProvider struct {
Acl string `json:"acl,omitempty"`
// SecretName is the name of secret which stores
// S3 compliant storage access key and secret key.
SecretName string `json:"secretName"`
SecretName string `json:"secretName,omitempty"`
shuijing198799 marked this conversation as resolved.
Show resolved Hide resolved
// Prefix for the keys.
Prefix string `json:"prefix,omitempty"`
// SSE Sever-Side Encryption.
Expand Down Expand Up @@ -781,6 +781,8 @@ type BackupSpec struct {
// Affinity of backup Pods
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
// Specify service account of backup
ServiceAccount string `json:"serviceAccount,omitempty"`
}

// +k8s:openapi-gen=true
Expand Down Expand Up @@ -999,6 +1001,8 @@ type RestoreSpec struct {
// Affinity of restore Pods
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
// Specify service account of restore
ServiceAccount string `json:"serviceAccount,omitempty"`
}

// RestoreStatus represents the current status of a tidb cluster restore.
Expand Down
9 changes: 7 additions & 2 deletions pkg/backup/backup/backup_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,19 @@ func (bc *backupCleaner) makeCleanJob(backup *v1alpha1.Backup) (*batchv1.Job, st
fmt.Sprintf("--backupName=%s", name),
}

serviceAccount := constants.DefaultServiceAccountName
if backup.Spec.ServiceAccount != "" {
serviceAccount = backup.Spec.ServiceAccount
}
backupLabel := label.NewBackup().Instance(backup.GetInstanceName()).CleanJob().Backup(name)

podSpec := &corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: backupLabel.Labels(),
Labels: backupLabel.Labels(),
Annotations: backup.Annotations,
shuijing198799 marked this conversation as resolved.
Show resolved Hide resolved
},
Spec: corev1.PodSpec{
ServiceAccountName: constants.DefaultServiceAccountName,
ServiceAccountName: serviceAccount,
Containers: []corev1.Container{
{
Name: label.BackupJobLabelVal,
Expand Down
19 changes: 14 additions & 5 deletions pkg/backup/backup/backup_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func (bm *backupManager) makeExportJob(backup *v1alpha1.Backup) (*batchv1.Job, s
if err != nil {
return nil, reason, fmt.Errorf("backup %s/%s, %v", ns, name, err)
}

envVars = append(envVars, storageEnv...)
// TODO: make pvc request storage size configurable
reason, err = bm.ensureBackupPVCExist(backup)
Expand All @@ -193,14 +192,19 @@ func (bm *backupManager) makeExportJob(backup *v1alpha1.Backup) (*batchv1.Job, s
fmt.Sprintf("--storageType=%s", backuputil.GetStorageType(backup.Spec.StorageProvider)),
}

serviceAccount := constants.DefaultServiceAccountName
if backup.Spec.ServiceAccount != "" {
serviceAccount = backup.Spec.ServiceAccount
}
backupLabel := label.NewBackup().Instance(backup.GetInstanceName()).BackupJob().Backup(name)
// TODO: need add ResourceRequirement for backup job
podSpec := &corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: backupLabel.Labels(),
Labels: backupLabel.Labels(),
Annotations: backup.Annotations,
},
Spec: corev1.PodSpec{
ServiceAccountName: constants.DefaultServiceAccountName,
ServiceAccountName: serviceAccount,
Containers: []corev1.Container{
{
Name: label.BackupJobLabelVal,
Expand Down Expand Up @@ -285,12 +289,17 @@ func (bm *backupManager) makeBackupJob(backup *v1alpha1.Backup) (*batchv1.Job, s
})
}

serviceAccount := constants.DefaultServiceAccountName
if backup.Spec.ServiceAccount != "" {
serviceAccount = backup.Spec.ServiceAccount
}
podSpec := &corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: backupLabel.Labels(),
Labels: backupLabel.Labels(),
Annotations: backup.Annotations,
},
Spec: corev1.PodSpec{
ServiceAccountName: constants.DefaultServiceAccountName,
ServiceAccountName: serviceAccount,
Containers: []corev1.Container{
{
Name: label.BackupJobLabelVal,
Expand Down
Loading