mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-07-07 02:02:21 +02:00
- Add 'namespace' structured field to the error log in Reconcile when a role reconciliation fails - Rename misleading local variable 'role' to 'roleBinding' in ensureRoleBinding to match the actual type - Add EnsureRole tests: transient Role creation error is propagated; pre-existing unrelated labels are preserved after patch - Add SetControllerReference test: returns an error when the owner does not implement runtime.Object - Add ObjectStoreReconciler tests: Role list failure and ObjectStore Get transient error both surface through the reconcile return value - Add scheme tests: AddCNPGToScheme with default and custom group/version Assisted-by: Claude Opus 4.6 Signed-off-by: Gabriele Quaresima <gabriele.quaresima@enterprisedb.com> Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Co-authored-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
117 lines
3.4 KiB
Go
117 lines
3.4 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 scheme
|
|
|
|
import (
|
|
"context"
|
|
|
|
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
"github.com/spf13/viper"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
)
|
|
|
|
var _ = Describe("AddCNPGToScheme", func() {
|
|
var s *runtime.Scheme
|
|
|
|
BeforeEach(func() {
|
|
s = runtime.NewScheme()
|
|
})
|
|
|
|
AfterEach(func() {
|
|
viper.Reset()
|
|
})
|
|
|
|
It("should register CNPG types under the default group and version", func() {
|
|
AddCNPGToScheme(context.Background(), s)
|
|
|
|
gvks, _, err := s.ObjectKinds(&cnpgv1.Cluster{})
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(gvks).To(ContainElement(schema.GroupVersionKind{
|
|
Group: cnpgv1.SchemeGroupVersion.Group,
|
|
Version: cnpgv1.SchemeGroupVersion.Version,
|
|
Kind: "Cluster",
|
|
}))
|
|
})
|
|
|
|
It("should register Backup and ScheduledBackup under the default group", func() {
|
|
AddCNPGToScheme(context.Background(), s)
|
|
|
|
gvks, _, err := s.ObjectKinds(&cnpgv1.Backup{})
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(gvks).To(ContainElement(HaveField("Group", cnpgv1.SchemeGroupVersion.Group)))
|
|
|
|
gvks, _, err = s.ObjectKinds(&cnpgv1.ScheduledBackup{})
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(gvks).To(ContainElement(HaveField("Group", cnpgv1.SchemeGroupVersion.Group)))
|
|
})
|
|
|
|
It("should register CNPG types under a custom group", func() {
|
|
viper.Set("custom-cnpg-group", "mycompany.io")
|
|
|
|
AddCNPGToScheme(context.Background(), s)
|
|
|
|
gvks, _, err := s.ObjectKinds(&cnpgv1.Cluster{})
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(gvks).To(ContainElement(schema.GroupVersionKind{
|
|
Group: "mycompany.io",
|
|
Version: cnpgv1.SchemeGroupVersion.Version,
|
|
Kind: "Cluster",
|
|
}))
|
|
// The default group must not be registered
|
|
Expect(s.Recognizes(schema.GroupVersionKind{
|
|
Group: cnpgv1.SchemeGroupVersion.Group,
|
|
Version: cnpgv1.SchemeGroupVersion.Version,
|
|
Kind: "Cluster",
|
|
})).To(BeFalse())
|
|
})
|
|
|
|
It("should register CNPG types under a custom version", func() {
|
|
viper.Set("custom-cnpg-version", "v2")
|
|
|
|
AddCNPGToScheme(context.Background(), s)
|
|
|
|
gvks, _, err := s.ObjectKinds(&cnpgv1.Cluster{})
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(gvks).To(ContainElement(schema.GroupVersionKind{
|
|
Group: cnpgv1.SchemeGroupVersion.Group,
|
|
Version: "v2",
|
|
Kind: "Cluster",
|
|
}))
|
|
})
|
|
|
|
It("should register CNPG types under both a custom group and custom version", func() {
|
|
viper.Set("custom-cnpg-group", "mycompany.io")
|
|
viper.Set("custom-cnpg-version", "v2")
|
|
|
|
AddCNPGToScheme(context.Background(), s)
|
|
|
|
gvks, _, err := s.ObjectKinds(&cnpgv1.Cluster{})
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(gvks).To(ContainElement(schema.GroupVersionKind{
|
|
Group: "mycompany.io",
|
|
Version: "v2",
|
|
Kind: "Cluster",
|
|
}))
|
|
})
|
|
})
|