Skip to content

K8SPG-710: Make spec.backups optional #1021

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

Merged
merged 11 commits into from
Apr 14, 2025
Merged

K8SPG-710: Make spec.backups optional #1021

merged 11 commits into from
Apr 14, 2025

Conversation

egegunes
Copy link
Contributor

@egegunes egegunes commented Jan 24, 2025

K8SPG-710 Powered by Pull Request Badge

CHANGE DESCRIPTION

This PR allows creating a PerconaPGCluster with backups disabled. To create a cluster with backups disabled, remove spec.backups section from deploy/cr.yaml and apply.

If you want to disable backups in a running cluster, you need to annotate PerconaPGCluster with pgv2.percona.com/authorizeBackupRemoval: true otherwise operator won't reconcile cluster and backup related objects won't be removed.

Once backups are disabled, operator will delete repo-host PVC. So any backups stored in that PVC will be deleted. Backups in cloud storages won't be deleted.

Helm chart PR: percona/percona-helm-charts#516

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 PG version?
  • Does the change support oldest and newest supported Kubernetes version?

@egegunes egegunes added this to the 2.7.0 milestone Mar 31, 2025
@egegunes egegunes changed the title K8SPG-710: Make spec.backups.pgbackrest optional K8SPG-710: Make spec.backups optional Apr 1, 2025
@egegunes egegunes marked this pull request as ready for review April 1, 2025 10:11
@egegunes egegunes marked this pull request as draft April 2, 2025 15:31
@egegunes egegunes marked this pull request as ready for review April 7, 2025 09:20
Comment on lines 247 to 249
func (spec *PerconaPGClusterSpec) BackupsEnabled() bool {
return spec.Backups.Enabled == nil || *spec.Backups.Enabled
}
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 we should document here that this works like that because backups were enabled by default before these changes, by looking it with fresh eyes, seems like inconsistency/bug.

I think we can also add a unit test like the following

func TestPerconaPGCluster_BackupsEnabled(t *testing.T) {
	trueVal := true
	falseVal := false

	tests := map[string]struct {
		spec     PerconaPGClusterSpec
		expected bool
	}{

		"Enabled is nil - should return true <explain reason maybe>": {
			spec:     PerconaPGClusterSpec{Backups: Backups{Enabled: nil}},
			expected: true,
		},
		"Enabled is true, should return true": {
			spec:     PerconaPGClusterSpec{Backups: Backups{Enabled: &trueVal}},
			expected: true,
		},
		"Enabled is false - should return false": {
			spec:     PerconaPGClusterSpec{Backups: Backups{Enabled: &falseVal}},
			expected: false,
		},
	}

	for name, tt := range tests {
		t.Run(name, func(t *testing.T) {
			actual := tt.spec.BackupsEnabled()
			assert.Equal(t, tt.expected, actual)
		})
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -243,6 +244,10 @@ func (cr *PerconaPGCluster) Default() {
}
}

func (spec *PerconaPGClusterSpec) BackupsEnabled() bool {
return spec.Backups.Enabled == nil || *spec.Backups.Enabled
Copy link
Contributor

@gkech gkech Apr 8, 2025

Choose a reason for hiding this comment

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

I think that given that we introduce this function, we should first add this function with Backups receiver since it is its own responsibility to determine if it is enabled or not, and then this new function can be used here because PerconaPGClusterSpec knows Backups

Copy link
Contributor

@gkech gkech Apr 8, 2025

Choose a reason for hiding this comment

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

we can then use this new function with the backups receiver, here

func (b Backups) ToCrunchy(version string) crunchyv1beta1.Backups {
	if b.Enabled != nil && !*b.Enabled {
		return crunchyv1beta1.Backups{}
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@egegunes egegunes requested a review from gkech April 10, 2025 13:02
}

bcp.Status.State = v2.BackupFailed
bcp.Status.Error = "Backups are not enabled in the PerconaPGCluster configuration"
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 add one more state like skipped or disabled? Technically it's not failed it's just disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In K8SPSMDB we also set backup state to Failed if cluster is not ready. I don't think we need to complicate things.

@JNKPercona
Copy link
Collaborator

Test name Status
backup-enable-disable passed
custom-extensions passed
custom-tls passed
demand-backup passed
finalizers passed
init-deploy passed
monitoring passed
monitoring-pmm3 passed
one-pod passed
operator-self-healing passed
pitr passed
scaling passed
scheduled-backup passed
self-healing passed
sidecars passed
start-from-backup passed
tablespaces passed
telemetry-transfer passed
upgrade-consistency passed
upgrade-minor passed
users passed
We run 21 out of 21

commit: bbbe9cc
image: perconalab/percona-postgresql-operator:PR-1021-bbbe9ccaf

@hors hors merged commit 53693c4 into main Apr 14, 2025
18 checks passed
@hors hors deleted the K8SPG-710 branch April 14, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants