mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-09-04 22:22:21 +02:00
Archive() and the restore job hook each re-derived, on their own, whether to verify the WAL archive destination is empty, by reading a Cluster annotation and, for Archive, an on-disk marker file. That decision belongs to the operator, which already tracks both the annotation and the marker file's lifecycle. Honor cnpg-i's new WALArchiveRequest/RestoreRequest field CheckEmptyWalArchive when the operator sets it: obey it directly, without re-inspecting the marker file. Only fall back to the previous annotation-and-marker-file logic when talking to an operator that predates this field. Related: cloudnative-pg/cnpg-i#353 adds the field this depends on; cloudnative-pg/cloudnative-pg#11216 is the operator-side counterpart. Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com> Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
67 lines
2.3 KiB
Go
67 lines
2.3 KiB
Go
/*
|
|
Copyright © contributors to CloudNativePG, established as
|
|
CloudNativePG a Series of LF Projects, LLC.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package restore
|
|
|
|
import (
|
|
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
|
|
"k8s.io/utils/ptr"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("resolveRestoreEmptyWalArchiveCheck", func() {
|
|
// skipAnnotation mirrors the unexported constant in cloudnative-pg's
|
|
// pkg/utils; hard-coding the literal makes a divergence surface as a
|
|
// failing test rather than silently disabling the check.
|
|
const skipAnnotation = "cnpg.io/skipEmptyWalArchiveCheck"
|
|
|
|
clusterWith := func(annotationValue *string) *cnpgv1.Cluster {
|
|
cluster := &cnpgv1.Cluster{}
|
|
if annotationValue != nil {
|
|
cluster.Annotations = map[string]string{skipAnnotation: *annotationValue}
|
|
}
|
|
return cluster
|
|
}
|
|
|
|
When("the operator sets the decision", func() {
|
|
It("obeys true even when the annotation would skip the check", func() {
|
|
Expect(resolveRestoreEmptyWalArchiveCheck(ptr.To(true), clusterWith(ptr.To("enabled")))).To(BeTrue())
|
|
})
|
|
|
|
It("obeys false even when the annotation would keep the check on", func() {
|
|
Expect(resolveRestoreEmptyWalArchiveCheck(ptr.To(false), clusterWith(nil))).To(BeFalse())
|
|
})
|
|
})
|
|
|
|
When("the operator predates the field (nil decision)", func() {
|
|
DescribeTable(
|
|
"falls back to the Cluster annotation, never to a marker file",
|
|
func(annotationValue *string, expected bool) {
|
|
Expect(resolveRestoreEmptyWalArchiveCheck(nil, clusterWith(annotationValue))).To(Equal(expected))
|
|
},
|
|
Entry("no annotation: check runs", nil, true),
|
|
Entry("opt-out annotation: check skipped", ptr.To("enabled"), false),
|
|
Entry("unrelated annotation value: check runs", ptr.To("something-else"), true),
|
|
Entry("empty annotation value: check runs", ptr.To(""), true),
|
|
)
|
|
})
|
|
})
|