|
| 1 | +/* |
| 2 | +Copyright © contributors to CloudNativePG, established as |
| 3 | +CloudNativePG a Series of LF Projects, LLC. |
| 4 | +
|
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +
|
| 17 | +SPDX-License-Identifier: Apache-2.0 |
| 18 | +*/ |
| 19 | + |
| 20 | +package specs |
| 21 | + |
| 22 | +import ( |
| 23 | + cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" |
| 24 | + "github.com/cloudnative-pg/cloudnative-pg/pkg/utils" |
| 25 | + . "github.com/onsi/ginkgo/v2" |
| 26 | + . "github.com/onsi/gomega" |
| 27 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 28 | + |
| 29 | + "github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata" |
| 30 | +) |
| 31 | + |
| 32 | +var _ = Describe("GetRequiredLabels", func() { |
| 33 | + It("should return all expected labels for a cluster without an image", func() { |
| 34 | + cluster := &cnpgv1.Cluster{ |
| 35 | + ObjectMeta: metav1.ObjectMeta{ |
| 36 | + Name: "my-cluster", |
| 37 | + Namespace: "default", |
| 38 | + }, |
| 39 | + } |
| 40 | + labels := GetRequiredLabels(cluster) |
| 41 | + |
| 42 | + Expect(labels).To(HaveKeyWithValue(metadata.ClusterLabelName, "my-cluster")) |
| 43 | + Expect(labels).To(HaveKeyWithValue(utils.KubernetesAppLabelName, utils.AppName)) |
| 44 | + Expect(labels).To(HaveKeyWithValue(utils.KubernetesAppInstanceLabelName, "my-cluster")) |
| 45 | + Expect(labels).To(HaveKeyWithValue(utils.KubernetesAppManagedByLabelName, "plugin-barman-cloud")) |
| 46 | + Expect(labels).To(HaveKeyWithValue(utils.KubernetesAppComponentLabelName, utils.DatabaseComponentName)) |
| 47 | + Expect(labels).To(HaveLen(6)) |
| 48 | + }) |
| 49 | + |
| 50 | + It("should use the major version from the image catalog ref", func() { |
| 51 | + cluster := &cnpgv1.Cluster{ |
| 52 | + ObjectMeta: metav1.ObjectMeta{ |
| 53 | + Name: "pg16-cluster", |
| 54 | + Namespace: "default", |
| 55 | + }, |
| 56 | + Spec: cnpgv1.ClusterSpec{ |
| 57 | + ImageCatalogRef: &cnpgv1.ImageCatalogRef{ |
| 58 | + Major: 16, |
| 59 | + }, |
| 60 | + }, |
| 61 | + } |
| 62 | + labels := GetRequiredLabels(cluster) |
| 63 | + |
| 64 | + Expect(labels).To(HaveKeyWithValue(utils.KubernetesAppVersionLabelName, "16")) |
| 65 | + Expect(labels).To(HaveKeyWithValue(utils.KubernetesAppInstanceLabelName, "pg16-cluster")) |
| 66 | + }) |
| 67 | +}) |
0 commit comments