-
Notifications
You must be signed in to change notification settings - Fork 31
K8SPS-400: custom options for xtrabackup, xbstream, xbcloud #986
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
Changes from 6 commits
e3a0944
8415784
fb6e2fa
ba85f8a
85fc670
853fa77
75cdf5a
ea3f7d5
380e8ce
a7d5688
f22ef3b
809baaa
0b37dd2
9a18175
baa83ce
6517e4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ import ( | |
|
||
"github.com/percona/percona-server-mysql-operator/pkg/naming" | ||
"github.com/percona/percona-server-mysql-operator/pkg/platform" | ||
"github.com/percona/percona-server-mysql-operator/pkg/util" | ||
"github.com/percona/percona-server-mysql-operator/pkg/version" | ||
) | ||
|
||
|
@@ -279,6 +280,60 @@ type BackupStorageSpec struct { | |
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"` | ||
RuntimeClassName *string `json:"runtimeClassName,omitempty"` | ||
VerifyTLS *bool `json:"verifyTLS,omitempty"` | ||
ContainerOptions *BackupContainerOptions `json:"containerOptions,omitempty"` | ||
} | ||
|
||
type BackupContainerOptions struct { | ||
Env []corev1.EnvVar `json:"env,omitempty"` | ||
Args BackupContainerArgs `json:"args"` | ||
} | ||
|
||
func (b *BackupContainerOptions) GetEnv() []corev1.EnvVar { | ||
if b == nil { | ||
return nil | ||
} | ||
return util.MergeEnvLists(b.Env, b.Args.Env()) | ||
} | ||
|
||
func (b *BackupContainerOptions) GetEnvVar(cluster *PerconaServerMySQL, storage *BackupStorageSpec) []corev1.EnvVar { | ||
if b != nil { | ||
return b.GetEnv() | ||
} | ||
|
||
if storage == nil || storage.ContainerOptions == nil { | ||
return nil | ||
} | ||
|
||
return storage.ContainerOptions.GetEnvVar(nil, nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to understand the logic here. Essentially, the cluster argument is not needed. For nil storage, we call the same function, and we return essentially nil. Why not just
Essentially I'm missing why storage is passed as an argument. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
type BackupContainerArgs struct { | ||
Xtrabackup []string `json:"xtrabackup,omitempty"` | ||
Xbcloud []string `json:"xbcloud,omitempty"` | ||
Xbstream []string `json:"xbstream,omitempty"` | ||
} | ||
|
||
func (b *BackupContainerArgs) Env() []corev1.EnvVar { | ||
envs := []corev1.EnvVar{} | ||
if len(b.Xtrabackup) > 0 { | ||
envs = append(envs, corev1.EnvVar{ | ||
Name: "XB_EXTRA_ARGS", | ||
Value: strings.Join(b.Xtrabackup, " "), | ||
}) | ||
} | ||
if len(b.Xbcloud) > 0 { | ||
envs = append(envs, corev1.EnvVar{ | ||
Name: "XBCLOUD_EXTRA_ARGS", | ||
Value: strings.Join(b.Xbcloud, " "), | ||
}) | ||
} | ||
if len(b.Xbstream) > 0 { | ||
envs = append(envs, corev1.EnvVar{ | ||
Name: "XBSTREAM_EXTRA_ARGS", | ||
Value: strings.Join(b.Xbstream, " "), | ||
}) | ||
} | ||
return envs | ||
} | ||
|
||
type BackupStorageS3Spec struct { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,11 @@ import ( | |
"syscall" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
"golang.org/x/sync/errgroup" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
|
||
"github.com/pkg/errors" | ||
|
||
apiv1alpha1 "github.com/percona/percona-server-mysql-operator/api/v1alpha1" | ||
"github.com/percona/percona-server-mysql-operator/pkg/mysql" | ||
xb "github.com/percona/percona-server-mysql-operator/pkg/xtrabackup" | ||
|
@@ -148,8 +147,8 @@ func getNamespace() (string, error) { | |
return string(ns), nil | ||
} | ||
|
||
func xtrabackupArgs(user, pass string) []string { | ||
return []string{ | ||
func xtrabackupArgs(user, pass string, conf *xb.BackupConfig) []string { | ||
args := []string{ | ||
"--backup", | ||
"--stream=xbstream", | ||
"--safe-slave-backup", | ||
|
@@ -158,6 +157,10 @@ func xtrabackupArgs(user, pass string) []string { | |
fmt.Sprintf("--user=%s", user), | ||
fmt.Sprintf("--password=%s", pass), | ||
} | ||
if conf != nil && conf.ContainerOptions != nil { | ||
args = append(args, conf.ContainerOptions.Args.Xtrabackup...) | ||
} | ||
return args | ||
} | ||
|
||
func backupHandler(w http.ResponseWriter, req *http.Request) { | ||
|
@@ -381,6 +384,16 @@ func createBackupHandler(w http.ResponseWriter, req *http.Request) { | |
} | ||
} | ||
|
||
if backupConf.ContainerOptions != nil { | ||
for _, env := range backupConf.ContainerOptions.Env { | ||
if err := os.Setenv(env.Name, env.Value); err != nil { | ||
log.Error(err, "failed to set env") | ||
http.Error(w, "failed to set env", http.StatusInternalServerError) | ||
return | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't it be better to set these env vars for specific commands? like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
w.Header().Set("Content-Type", "application/octet-stream") | ||
w.Header().Set("Connection", "keep-alive") | ||
|
||
|
@@ -393,7 +406,7 @@ func createBackupHandler(w http.ResponseWriter, req *http.Request) { | |
} | ||
g, gCtx := errgroup.WithContext(req.Context()) | ||
|
||
xtrabackup := exec.CommandContext(gCtx, "xtrabackup", xtrabackupArgs(string(backupUser), backupPass)...) | ||
xtrabackup := exec.CommandContext(gCtx, "xtrabackup", xtrabackupArgs(string(backupUser), backupPass, &backupConf)...) | ||
|
||
xbOut, err := xtrabackup.StdoutPipe() | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cluster option here is not used in the function, maybe we can remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ea3f7d5