mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-07-08 18:52:20 +02:00
refactor: rename label builder to BuildLabels, move into labels.go
The package is already named specs, the file content is label construction, and a separate metadata package exists at internal/cnpgi/metadata; labels.go describes the file directly without the package-name collision. BuildLabels also matches the verb convention already used elsewhere in the package (BuildRole, BuildRoleBinding, BuildRoleRules). No behavior change. Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
This commit is contained in:
parent
6c8fd63181
commit
a4b0f428b8
@ -61,7 +61,7 @@ func EnsureRole(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return patchRole(ctx, c, roleKey, newRole.Rules, specs.GetRequiredLabels(cluster))
|
return patchRole(ctx, c, roleKey, newRole.Rules, specs.BuildLabels(cluster))
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnsureRoleRules updates the rules of an existing Role to match
|
// EnsureRoleRules updates the rules of an existing Role to match
|
||||||
|
|||||||
@ -28,8 +28,8 @@ import (
|
|||||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetRequiredLabels returns the labels that must be present on all plugin-managed objects for a given Cluster.
|
// BuildLabels returns the labels that must be present on all plugin-managed objects for a given Cluster.
|
||||||
func GetRequiredLabels(cluster *cnpgv1.Cluster) map[string]string {
|
func BuildLabels(cluster *cnpgv1.Cluster) map[string]string {
|
||||||
requiredLabels := map[string]string{
|
requiredLabels := map[string]string{
|
||||||
metadata.ClusterLabelName: cluster.Name,
|
metadata.ClusterLabelName: cluster.Name,
|
||||||
// Kubernetes recommended labels
|
// Kubernetes recommended labels
|
||||||
@ -29,7 +29,7 @@ import (
|
|||||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("GetRequiredLabels", func() {
|
var _ = Describe("BuildLabels", func() {
|
||||||
It("should return all expected labels for a cluster without an image", func() {
|
It("should return all expected labels for a cluster without an image", func() {
|
||||||
cluster := &cnpgv1.Cluster{
|
cluster := &cnpgv1.Cluster{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
@ -37,7 +37,7 @@ var _ = Describe("GetRequiredLabels", func() {
|
|||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
labels := GetRequiredLabels(cluster)
|
labels := BuildLabels(cluster)
|
||||||
|
|
||||||
Expect(labels).To(HaveKeyWithValue(metadata.ClusterLabelName, "my-cluster"))
|
Expect(labels).To(HaveKeyWithValue(metadata.ClusterLabelName, "my-cluster"))
|
||||||
Expect(labels).To(HaveKeyWithValue(utils.KubernetesAppLabelName, utils.AppName))
|
Expect(labels).To(HaveKeyWithValue(utils.KubernetesAppLabelName, utils.AppName))
|
||||||
@ -59,7 +59,7 @@ var _ = Describe("GetRequiredLabels", func() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
labels := GetRequiredLabels(cluster)
|
labels := BuildLabels(cluster)
|
||||||
|
|
||||||
Expect(labels).To(HaveKeyWithValue(utils.KubernetesAppVersionLabelName, "16"))
|
Expect(labels).To(HaveKeyWithValue(utils.KubernetesAppVersionLabelName, "16"))
|
||||||
Expect(labels).To(HaveKeyWithValue(utils.KubernetesAppInstanceLabelName, "pg16-cluster"))
|
Expect(labels).To(HaveKeyWithValue(utils.KubernetesAppInstanceLabelName, "pg16-cluster"))
|
||||||
@ -40,7 +40,7 @@ func BuildRole(
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Namespace: cluster.Namespace,
|
Namespace: cluster.Namespace,
|
||||||
Name: GetRBACName(cluster.Name),
|
Name: GetRBACName(cluster.Name),
|
||||||
Labels: GetRequiredLabels(cluster),
|
Labels: BuildLabels(cluster),
|
||||||
},
|
},
|
||||||
Rules: BuildRoleRules(barmanObjects),
|
Rules: BuildRoleRules(barmanObjects),
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ func BuildRoleBinding(
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Namespace: cluster.Namespace,
|
Namespace: cluster.Namespace,
|
||||||
Name: GetRBACName(cluster.Name),
|
Name: GetRBACName(cluster.Name),
|
||||||
Labels: GetRequiredLabels(cluster),
|
Labels: BuildLabels(cluster),
|
||||||
},
|
},
|
||||||
Subjects: []rbacv1.Subject{
|
Subjects: []rbacv1.Subject{
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user