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

backup: support br compatible with new TLS interface #1988

Merged
merged 6 commits into from
Mar 20, 2020
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
19 changes: 10 additions & 9 deletions cmd/backup-manager/app/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ import (
"github.com/gogo/protobuf/proto"
kvbackup "github.com/pingcap/kvproto/pkg/backup"
"github.com/pingcap/tidb-operator/cmd/backup-manager/app/constants"
"github.com/pingcap/tidb-operator/cmd/backup-manager/app/util"
backupUtil "github.com/pingcap/tidb-operator/cmd/backup-manager/app/util"
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/util"
corev1 "k8s.io/api/core/v1"
"k8s.io/klog"
)

// Options contains the input arguments to the backup command
type Options struct {
util.GenericOptions
backupUtil.GenericOptions
}

func (bo *Options) backupData(backup *v1alpha1.Backup) (string, error) {
Expand All @@ -44,10 +45,10 @@ func (bo *Options) backupData(backup *v1alpha1.Backup) (string, error) {
return "", err
}
args = append(args, fmt.Sprintf("--pd=%s-pd.%s:2379", backup.Spec.BR.Cluster, clusterNamespace))
if backup.Spec.BR.EnableTLSClient {
args = append(args, fmt.Sprintf("--ca=%s", constants.ServiceAccountCAPath))
args = append(args, fmt.Sprintf("--cert=%s", path.Join(constants.BRCertPath, corev1.TLSCertKey)))
args = append(args, fmt.Sprintf("--key=%s", path.Join(constants.BRCertPath, corev1.TLSPrivateKeyKey)))
if backup.Spec.BR.TLSCluster != nil && backup.Spec.BR.TLSCluster.Enabled {
args = append(args, fmt.Sprintf("--ca=%s", path.Join(util.ClusterClientTLSPath, corev1.ServiceAccountRootCAKey)))
args = append(args, fmt.Sprintf("--cert=%s", path.Join(util.ClusterClientTLSPath, corev1.TLSCertKey)))
args = append(args, fmt.Sprintf("--key=%s", path.Join(util.ClusterClientTLSPath, corev1.TLSPrivateKeyKey)))
}

var btype string
Expand All @@ -73,7 +74,7 @@ func (bo *Options) backupData(backup *v1alpha1.Backup) (string, error) {
// getCommitTs get backup position from `EndVersion` in BR backup meta
func getCommitTs(backup *v1alpha1.Backup) (uint64, error) {
var commitTs uint64
s, err := util.NewRemoteStorage(backup)
s, err := backupUtil.NewRemoteStorage(backup)
if err != nil {
return commitTs, err
}
Expand Down Expand Up @@ -101,7 +102,7 @@ func getCommitTs(backup *v1alpha1.Backup) (uint64, error) {

// constructOptions constructs options for BR and also return the remote path
func constructOptions(backup *v1alpha1.Backup) ([]string, string, error) {
args, remotePath, err := util.ConstructBRGlobalOptionsForBackup(backup)
args, remotePath, err := backupUtil.ConstructBRGlobalOptionsForBackup(backup)
if err != nil {
return args, remotePath, err
}
Expand All @@ -124,7 +125,7 @@ func constructOptions(backup *v1alpha1.Backup) ([]string, string, error) {
// getBackupSize get the backup data size from remote
func getBackupSize(backup *v1alpha1.Backup) (int64, error) {
var size int64
s, err := util.NewRemoteStorage(backup)
s, err := backupUtil.NewRemoteStorage(backup)
if err != nil {
return size, err
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/backup-manager/app/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (
"os/exec"
"path"

"github.com/pingcap/tidb-operator/cmd/backup-manager/app/constants"
"github.com/pingcap/tidb-operator/cmd/backup-manager/app/util"
backupUtil "github.com/pingcap/tidb-operator/cmd/backup-manager/app/util"
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/util"
corev1 "k8s.io/api/core/v1"
"k8s.io/klog"
)

type Options struct {
util.GenericOptions
backupUtil.GenericOptions
}

func (ro *Options) restoreData(restore *v1alpha1.Restore) error {
Expand All @@ -39,10 +39,10 @@ func (ro *Options) restoreData(restore *v1alpha1.Restore) error {
return err
}
args = append(args, fmt.Sprintf("--pd=%s-pd.%s:2379", restore.Spec.BR.Cluster, clusterNamespace))
if restore.Spec.BR.EnableTLSClient {
args = append(args, fmt.Sprintf("--ca=%s", constants.ServiceAccountCAPath))
args = append(args, fmt.Sprintf("--cert=%s", path.Join(constants.BRCertPath, corev1.TLSCertKey)))
args = append(args, fmt.Sprintf("--key=%s", path.Join(constants.BRCertPath, corev1.TLSPrivateKeyKey)))
if restore.Spec.BR.TLSCluster != nil && restore.Spec.BR.TLSCluster.Enabled {
args = append(args, fmt.Sprintf("--ca=%s", path.Join(util.ClusterClientTLSPath, corev1.ServiceAccountRootCAKey)))
args = append(args, fmt.Sprintf("--cert=%s", path.Join(util.ClusterClientTLSPath, corev1.TLSCertKey)))
args = append(args, fmt.Sprintf("--key=%s", path.Join(util.ClusterClientTLSPath, corev1.TLSPrivateKeyKey)))
}

var restoreType string
Expand All @@ -66,7 +66,7 @@ func (ro *Options) restoreData(restore *v1alpha1.Restore) error {
}

func constructBROptions(restore *v1alpha1.Restore) ([]string, error) {
args, err := util.ConstructBRGlobalOptionsForRestore(restore)
args, err := backupUtil.ConstructBRGlobalOptionsForRestore(restore)
if err != nil {
return nil, err
}
Expand Down
11 changes: 8 additions & 3 deletions docs/api-references/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -1546,13 +1546,17 @@ <h3 id="pingcap.com/v1alpha1.BRConfig">BRConfig
<tbody>
<tr>
<td>
<code>enableTLSClient</code></br>
<code>tlsCluster</code></br>
<em>
bool
<a href="#pingcap.com/v1alpha1.TLSCluster">
TLSCluster
</a>
</em>
</td>
<td>
<p>Whether enable TLS in TiDBCluster</p>
<em>(Optional)</em>
<p>Whether enable the TLS connection between TiDB server components
Optional: Defaults to nil</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -6652,6 +6656,7 @@ <h3 id="pingcap.com/v1alpha1.TLSCluster">TLSCluster
</h3>
<p>
(<em>Appears on:</em>
<a href="#pingcap.com/v1alpha1.BRConfig">BRConfig</a>,
<a href="#pingcap.com/v1alpha1.TidbClusterSpec">TidbClusterSpec</a>)
</p>
<p>
Expand Down
12 changes: 3 additions & 9 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6766,9 +6766,6 @@ spec:
db:
description: DB is the specific DB which will be backed-up or restored
type: string
enableTLSClient:
description: Whether enable TLS in TiDBCluster
type: boolean
logLevel:
description: LogLevel is the log level
type: string
Expand Down Expand Up @@ -6796,6 +6793,7 @@ spec:
description: TimeAgo is the history version of the backup task,
e.g. 1m, 1h
type: string
tlsCluster: {}
required:
- cluster
type: object
Expand Down Expand Up @@ -7610,9 +7608,6 @@ spec:
db:
description: DB is the specific DB which will be backed-up or restored
type: string
enableTLSClient:
description: Whether enable TLS in TiDBCluster
type: boolean
logLevel:
description: LogLevel is the log level
type: string
Expand Down Expand Up @@ -7640,6 +7635,7 @@ spec:
description: TimeAgo is the history version of the backup task,
e.g. 1m, 1h
type: string
tlsCluster: {}
required:
- cluster
type: object
Expand Down Expand Up @@ -8497,9 +8493,6 @@ spec:
description: DB is the specific DB which will be backed-up or
restored
type: string
enableTLSClient:
description: Whether enable TLS in TiDBCluster
type: boolean
logLevel:
description: LogLevel is the log level
type: string
Expand Down Expand Up @@ -8527,6 +8520,7 @@ spec:
description: TimeAgo is the history version of the backup task,
e.g. 1m, 1h
type: string
tlsCluster: {}
required:
- cluster
type: object
Expand Down
9 changes: 5 additions & 4 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.

6 changes: 4 additions & 2 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,10 @@ type BackupSpec struct {
// +k8s:openapi-gen=true
// BRConfig contains config for BR
type BRConfig struct {
// Whether enable TLS in TiDBCluster
EnableTLSClient bool `json:"enableTLSClient,omitempty"`
// Whether enable the TLS connection between TiDB server components
// Optional: Defaults to nil
// +optional
TLSCluster *TLSCluster `json:"tlsCluster,omitempty"`
// ClusterName of backup/restore cluster
Cluster string `json:"cluster"`
// Namespace of backup/restore cluster
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

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

12 changes: 8 additions & 4 deletions pkg/backup/backup/backup_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
backuputil "github.com/pingcap/tidb-operator/pkg/backup/util"
"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/label"
"github.com/pingcap/tidb-operator/pkg/util"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -276,14 +277,17 @@ func (bm *backupManager) makeBackupJob(backup *v1alpha1.Backup) (*batchv1.Job, s
backupLabel := label.NewBackup().Instance(backup.GetInstanceName()).BackupJob().Backup(name)
volumeMounts := []corev1.VolumeMount{}
volumes := []corev1.Volume{}
if backup.Spec.BR.EnableTLSClient {
if backup.Spec.BR.TLSCluster != nil && backup.Spec.BR.TLSCluster.Enabled {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "br-tls", ReadOnly: true, MountPath: constants.BRCertPath,
Name: "cluster-client-tls",
ReadOnly: true,
MountPath: util.ClusterClientTLSPath,
})
volumes = append(volumes, corev1.Volume{
Name: "br-tls", VolumeSource: corev1.VolumeSource{
Name: "cluster-client-tls",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: fmt.Sprintf("%s-client", controller.PDMemberName(backup.Spec.BR.Cluster)),
SecretName: util.ClusterClientTLSSecretName(backup.Spec.BR.Cluster),
},
},
})
Expand Down
12 changes: 8 additions & 4 deletions pkg/backup/restore/restore_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
listers "github.com/pingcap/tidb-operator/pkg/client/listers/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/label"
"github.com/pingcap/tidb-operator/pkg/util"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -260,14 +261,17 @@ func (rm *restoreManager) makeRestoreJob(restore *v1alpha1.Restore) (*batchv1.Jo
restoreLabel := label.NewBackup().Instance(restore.GetInstanceName()).RestoreJob().Restore(name)
volumeMounts := []corev1.VolumeMount{}
volumes := []corev1.Volume{}
if restore.Spec.BR.EnableTLSClient {
if restore.Spec.BR.TLSCluster != nil && restore.Spec.BR.TLSCluster.Enabled {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "br-tls", ReadOnly: true, MountPath: constants.BRCertPath,
Name: "cluster-client-tls",
ReadOnly: true,
MountPath: util.ClusterClientTLSPath,
})
volumes = append(volumes, corev1.Volume{
Name: "br-tls", VolumeSource: corev1.VolumeSource{
Name: "cluster-client-tls",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: fmt.Sprintf("%s-client", controller.PDMemberName(restore.Spec.BR.Cluster)),
SecretName: util.ClusterClientTLSSecretName(restore.Spec.BR.Cluster),
},
},
})
Expand Down