-
Notifications
You must be signed in to change notification settings - Fork 61
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
Conversation
func (spec *PerconaPGClusterSpec) BackupsEnabled() bool { | ||
return spec.Backups.Enabled == nil || *spec.Backups.Enabled | ||
} |
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.
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)
})
}
}
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.
@@ -243,6 +244,10 @@ func (cr *PerconaPGCluster) Default() { | |||
} | |||
} | |||
|
|||
func (spec *PerconaPGClusterSpec) BackupsEnabled() bool { | |||
return spec.Backups.Enabled == nil || *spec.Backups.Enabled |
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.
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
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.
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{}
}
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.
} | ||
|
||
bcp.Status.State = v2.BackupFailed | ||
bcp.Status.Error = "Backups are not enabled in the PerconaPGCluster configuration" |
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.
Maybe we can add one more state like skipped or disabled? Technically it's not failed it's just disabled.
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.
In K8SPSMDB we also set backup state to Failed if cluster is not ready. I don't think we need to complicate things.
commit: bbbe9cc |
CHANGE DESCRIPTION
This PR allows creating a PerconaPGCluster with backups disabled. To create a cluster with backups disabled, remove
spec.backups
section fromdeploy/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
Needs Doc
) and QA (Needs QA
)?Tests
Config/Logging/Testability