Skip to content

Conversation

pooknull
Copy link
Contributor

@pooknull pooknull commented Aug 6, 2025

K8SPS-400 Powered by Pull Request Badge

https://perconadev.atlassian.net/browse/K8SPS-400

DESCRIPTION

Problem:
In our backups and restoration process we rely on xtrabackup, xbstream and xbcloud. Not always default options for these tools are optimal.

Solution:
Add containerOptions section to ps-backup, ps-restore and ps resources.

containerOptions:
  env:
  - name: VERIFY_TLS
    value: "false"
  - name: XB_USE_MEMORY
    value: "2GB"
  args:
    xtrabackup:
    - "--someflag=abc"
    - "--someotherflag=def"
    xbcloud:
    - "--someflag=abc"
    - "--someotherflag=def"
    xbstream:
    - "--someflag=abc"
    - "--someotherflag=def"

If containerOptions specified in both ps-backup/ps-restore and ps, values from ps-backup/ps-restore will be used.

Helm PR: percona/percona-helm-charts#612

CHECKLIST

Jira

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are all needed new/changed options added to the Helm Chart?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported PS version?
  • Does the change support oldest and newest supported Kubernetes version?

@pull-request-size pull-request-size bot added the size/XXL 1000+ lines label Aug 6, 2025
@pooknull pooknull added this to the v0.12.0 milestone Aug 6, 2025
Copy link
Collaborator

@hors hors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pooknull please add e2e test for it

@pooknull pooknull requested a review from hors August 20, 2025 09:18
@pooknull pooknull marked this pull request as ready for review August 20, 2025 09:23
return util.MergeEnvLists(b.Env, b.Args.Env())
}

func (b *BackupContainerOptions) GetEnvVar(cluster *PerconaServerMySQL, storage *BackupStorageSpec) []corev1.EnvVar {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return nil
}

return storage.ContainerOptions.GetEnvVar(nil, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The 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

func (b *BackupContainerOptions) GetEnvVar(cluster *PerconaServerMySQL, storage *BackupStorageSpec) []corev1.EnvVar {
	if b == nil {
		return nil
	}
return b.GetEnv()
}

Essentially I'm missing why storage is passed as an argument. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
fmt.Println("TEST", conf.ContainerOptions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep this println?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
if backupContainerOptions.Args.Xtrabackup != nil {
containerOptions.Args.Xtrabackup = backupContainerOptions.Args.Xtrabackup
fmt.Println("TEST 2", containerOptions.Args.Xtrabackup)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can drop this prinln.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
if backupContainerOptions.Args.Xtrabackup != nil {
containerOptions.Args.Xtrabackup = backupContainerOptions.Args.Xtrabackup
fmt.Println("TEST 2", containerOptions.Args.Xtrabackup)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a leftover print that we can drop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkg/util/env.go Outdated
resultList := make([]corev1.EnvVar, 0)
for _, list := range envLists {
for _, env := range list {
idx := FindEnvIndex(resultList, env.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not critical but we can use built-in slices.IndexFunc here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 387 to 395
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
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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:

xtrabackup := exec.CommandContext(gCtx, "xtrabackup", xtrabackupArgs(string(backupUser), backupPass, &backupConf)...)
env := os.Environ()
for _, e := range backupConf.ContainerOptions.Env {
    env = append(env, fmt.Sprintf("%s=%s", e.Name, e.Value)
}
xtrabackup.Env = env

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pooknull pooknull requested review from gkech and egegunes August 21, 2025 08:57
egegunes
egegunes previously approved these changes Aug 22, 2025
gkech
gkech previously approved these changes Aug 22, 2025
egegunes
egegunes previously approved these changes Aug 27, 2025
gkech
gkech previously approved these changes Aug 27, 2025
@hors hors dismissed stale reviews from gkech and egegunes via 0b37dd2 August 27, 2025 11:53
@JNKPercona
Copy link
Collaborator

Test name Status
version-service passed
async-ignore-annotations passed
auto-config passed
config passed
config-router passed
demand-backup passed
async-data-at-rest-encryption passed
gr-data-at-rest-encryption passed
gr-demand-backup passed
gr-demand-backup-haproxy passed
gr-finalizer passed
gr-haproxy passed
gr-ignore-annotations passed
gr-init-deploy passed
gr-one-pod passed
gr-recreate passed
gr-scaling passed
gr-scheduled-backup passed
gr-security-context passed
gr-self-healing passed
gr-tls-cert-manager passed
gr-users passed
haproxy passed
init-deploy passed
limits passed
monitoring passed
one-pod passed
operator-self-healing passed
recreate passed
scaling passed
scheduled-backup passed
service-per-pod passed
sidecars passed
smart-update passed
storage passed
tls-cert-manager passed
users passed
pvc-resize passed
We run 38 out of 38

commit: 6517e4e
image: perconalab/percona-server-mysql-operator:PR-986-6517e4e6

@hors hors merged commit b2c201b into main Aug 28, 2025
15 of 16 checks passed
@hors hors deleted the K8SPS-400 branch August 28, 2025 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XXL 1000+ lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants