Conversation
| } | ||
|
|
||
| // K8SPG-833 | ||
| if cluster.CompareVersion("2.8.0") >= 0 { |
There was a problem hiding this comment.
should we change this compare version? I guess it is going to be releases with 2.9
There was a problem hiding this comment.
Pull request overview
This PR adds support for specifying environment variables (env / envFrom) for backup and restore workloads by introducing a containerOptions block on Percona backup/restore CRs and plumbing corresponding env/envFrom fields into the generated pgBackRest Job specs.
Changes:
- Add
containerOptions.env/containerOptions.envFromtoPerconaPGBackupandPerconaPGRestorespecs (API + CRDs + examples). - Add
Env/EnvFromfields to CrunchyPGBackRestManualBackupandPostgresClusterDataSourcetypes and propagate them into pgBackRest backup/restore Jobs. - Add/update deepcopy generation and controller tests validating env/envFrom precedence and version gating.
Reviewed changes
Copilot reviewed 15 out of 22 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/apis/postgres-operator.crunchydata.com/v1beta1/zz_generated.deepcopy.go | DeepCopy updates for new env/envFrom fields in Crunchy types. |
| pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go | Adds Env/EnvFrom to PostgresClusterDataSource (restore datasource). |
| pkg/apis/postgres-operator.crunchydata.com/v1beta1/pgbackrest_types.go | Adds Env/EnvFrom to PGBackRestManualBackup. |
| pkg/apis/pgv2.percona.com/v2/zz_generated.deepcopy.go | Adds deepcopy support for new ContainerOptions and ensures it is copied in backup/restore specs. |
| pkg/apis/pgv2.percona.com/v2/perconapgrestore_types.go | Adds containerOptions to restore spec. |
| pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go | Introduces ContainerOptions type and extends secret indexing to include manual/restore envFrom secrets. |
| pkg/apis/pgv2.percona.com/v2/perconapgbackup_types.go | Adds containerOptions to backup spec. |
| percona/controller/pgrestore/controller.go | Plumbs containerOptions env/envFrom into cluster restore spec when starting restore. |
| percona/controller/pgbackup/controller.go | Plumbs containerOptions env/envFrom into cluster manual-backup spec when starting backup. |
| internal/controller/postgrescluster/pgbackrest_test.go | Adds test coverage for env/envFrom behavior and version gating in backup/restore job generation. |
| internal/controller/postgrescluster/pgbackrest.go | Implements env/envFrom injection (with manual/restore override) into generated pgBackRest Jobs. |
| deploy/restore.yaml | Documents containerOptions usage for restores (example). |
| deploy/crd.yaml | Updates bundled CRDs to include new schema fields. |
| deploy/backup.yaml | Documents containerOptions usage for backups (example). |
| config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml | Updates Crunchy PostgresCluster CRD base schema for new env/envFrom fields. |
| config/crd/bases/pgv2.percona.com_perconapgclusters.yaml | Updates Percona PG CRD base schema for new env/envFrom-related schema blocks. |
| build/crd/percona/generated/pgv2.percona.com_perconapgrestores.yaml | Generated CRD includes containerOptions schema for restores. |
| build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml | Generated CRD updates reflecting new schema blocks. |
| build/crd/percona/generated/pgv2.percona.com_perconapgbackups.yaml | Generated CRD includes containerOptions schema for backups. |
| build/crd/crunchy/generated/postgres-operator.crunchydata.com_postgresclusters.yaml | Generated Crunchy CRD includes new env/envFrom schema for manual/restore. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // K8SPG-873 | ||
| Env []corev1.EnvVar `json:"env,omitempty"` | ||
| // K8SPG-873 |
There was a problem hiding this comment.
- Problem: The new
Env/EnvFromfields have only a ticket reference comment and are missing+optional/descriptive doc comments. - Why it matters: Controller-gen will surface this as unhelpful OpenAPI/CRD field descriptions (e.g. just "K8SPG-873"), reducing usability of
kubectl explainand generated docs. - Fix: Add proper field documentation and
// +optionalmarkers consistent with surrounding fields (e.g. describe that these env vars are added to the restore Job container).
| // K8SPG-873 | |
| Env []corev1.EnvVar `json:"env,omitempty"` | |
| // K8SPG-873 | |
| // Additional environment variables to set on the pgBackRest restore Job container. | |
| // +optional | |
| Env []corev1.EnvVar `json:"env,omitempty"` | |
| // Additional sources of environment variables for the pgBackRest restore Job container. | |
| // +optional |
| // K8SPG-873 | ||
| Env []corev1.EnvVar `json:"env,omitempty"` | ||
| // K8SPG-873 |
There was a problem hiding this comment.
- Problem: The new
Env/EnvFromfields inPGBackRestManualBackuponly include a ticket reference and omit+optionaland descriptive doc comments. - Why it matters: This generates unhelpful CRD schema descriptions and makes it unclear how these env settings are used (and by which job type).
- Fix: Add clear doc comments (e.g., "Environment variables to add to the manual backup Job container") and
// +optionalmarkers, consistent with other fields in this API type.
| // K8SPG-873 | |
| Env []corev1.EnvVar `json:"env,omitempty"` | |
| // K8SPG-873 | |
| // Env defines environment variables to add to the manual backup Job container. | |
| // +optional | |
| Env []corev1.EnvVar `json:"env,omitempty"` | |
| // EnvFrom specifies sources for environment variables to add to the manual backup Job container. | |
| // +optional |
| if postgresCluster.CompareVersion("2.9.0") >= 0 { | ||
| for i := range jobSpec.Template.Spec.Containers { | ||
| pgbackrest := postgresCluster.Spec.Backups.PGBackRest | ||
|
|
||
| if pgbackrest.Manual != nil && len(pgbackrest.Manual.Env) != 0 { | ||
| jobSpec.Template.Spec.Containers[i].Env = append(jobSpec.Template.Spec.Containers[i].Env, pgbackrest.Manual.Env...) | ||
| } else if len(pgbackrest.Env) != 0 { | ||
| jobSpec.Template.Spec.Containers[i].Env = append(jobSpec.Template.Spec.Containers[i].Env, pgbackrest.Env...) | ||
| } | ||
|
|
||
| if pgbackrest.Manual != nil && len(pgbackrest.Manual.EnvFrom) != 0 { | ||
| jobSpec.Template.Spec.Containers[i].EnvFrom = append(jobSpec.Template.Spec.Containers[i].EnvFrom, pgbackrest.Manual.EnvFrom...) | ||
| } else if len(pgbackrest.EnvFrom) != 0 { | ||
| jobSpec.Template.Spec.Containers[i].EnvFrom = append(jobSpec.Template.Spec.Containers[i].EnvFrom, pgbackrest.EnvFrom...) | ||
| } |
There was a problem hiding this comment.
- Problem:
generateBackupJobSpecIntentappliespgbackrest.Manual.Env/EnvFromto all backup jobs whenever.spec.backups.pgbackrest.manualis set, including replica-create and scheduled CronJob backups. - Why it matters: This makes manual-only environment configuration leak into other backup job types, which can change behavior and credentials unexpectedly.
- Fix: Only apply
.manual.env/.manual.envFromwhen generating a manual backup job (e.g., gate onlabels[naming.LabelPGBackRestBackup] == string(naming.BackupManual)); otherwise fall back to.pgbackrest.env/.pgbackrest.envFrom.
| jobSpec.Template.Spec.Containers[i].EnvFrom = append(jobSpec.Template.Spec.Containers[i].EnvFrom, postgresCluster.Spec.Backups.PGBackRest.EnvFrom...) | ||
| } | ||
| // K8SPG-833 | ||
| if postgresCluster.CompareVersion("2.9.0") >= 0 { |
There was a problem hiding this comment.
- Problem: The version gate for applying pgBackRest
Env/EnvFromin backup jobs was changed toCompareVersion("2.9.0"), but other pgBackRest env injection paths still use2.8.0for K8SPG-833. - Why it matters: This is inconsistent and may disable previously supported
.spec.backups.pgbackrest.env/envFromfor clusters labeled2.8.x. - Fix: Align the version threshold with the rest of the codebase (or separate the gate: keep global pgBackRest env at
2.8.0and gate the new manual override independently).
| if postgresCluster.CompareVersion("2.9.0") >= 0 { | |
| if postgresCluster.CompareVersion("2.8.0") >= 0 { |
commit: 38fc9f3 |
mayankshah1607
left a comment
There was a problem hiding this comment.
Please resolve conflicts
https://perconadev.atlassian.net/browse/K8SPG-873
DESCRIPTION
This PR adds
.containerOptions.envand.containerOptions.envFromfields to our backup and restore resourcesCHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
Config/Logging/Testability