mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-07-06 17:52:21 +02:00
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [golangci/golangci-lint](https://redirect.github.com/golangci/golangci-lint) | minor | `v2.11.4` → `v2.12.0` | --- ### Release Notes <details> <summary>golangci/golangci-lint (golangci/golangci-lint)</summary> ### [`v2.12.0`](https://redirect.github.com/golangci/golangci-lint/blob/HEAD/CHANGELOG.md#v2120) [Compare Source](https://redirect.github.com/golangci/golangci-lint/compare/v2.11.4...v2.12.0) *Released on 2026-05-01* 1. New linters - Add `clickhouselint` linter <https://github.com/ClickHouse/clickhouse-go-linter> 2. Linters new features or changes - `dupl`: from [`f665c8d`](https://redirect.github.com/golangci/golangci-lint/commit/f665c8d69b32) to [`c99c5cf`](https://redirect.github.com/golangci/golangci-lint/commit/c99c5cf5c202) (extended detection) - `funcorder`: from 0.5.0 to 0.6.0 (new option: `function`) - `goconst`: add an option to ignore strings from tests - `goconst`: from 1.8.2 to 1.10.0 (extended detection) - `gomodguard_v2`: from 1.4.1 to 2.1.0 (major version with new configuration) - `gosec`: from [`619ce21`](https://redirect.github.com/golangci/golangci-lint/commit/619ce2117e08) to 2.26.1 (new checks: `G124`, `G708`, `G709`, `G710`) - `govet`: add `inline` analyzer - `makezero`: from 2.1.0 to 2.2.1 (support slice type aliases) - `paralleltest`: expose `checkcleanup` option - `sloglint`: from 0.11.1 to 0.12.0 (new options: `allowed-keys`, `custom-funcs`) - `wsl_v5`: from 5.6.0 to 5.8.0 (new option: `cuddle-max-statements`; new checks: `after-decl`, `after-defer`, `after-expr`, `after-go`, `cuddle-group`) 3. Linters bug fixes - `forbidigo`: from 2.3.0 to 2.3.1 - `godot`: from 1.5.4 to 1.5.6 - `govet-modernize`: from 0.43.0 to 0.44.0 - `ireturn`: from 0.4.0 to 0.4.1 - `rowserrcheck`: from 1.1.1 to [`c5f79b8`](https://redirect.github.com/golangci/golangci-lint/commit/c5f79b8) 4. Misc. - Decrease cache entropy - Embed the JSON schema in the binary - Filter env vars when cloning the repository with the `custom` command </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Never, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/cloudnative-pg/plugin-barman-cloud). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xNTkuMiIsInVwZGF0ZWRJblZlciI6IjQzLjE1OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJhdXRvbWF0ZWQiLCJuby1pc3N1ZSJdfQ==--> --------- Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Leonardo Cecchi <leonardo.cecchi@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Leonardo Cecchi <leonardo.cecchi@gmail.com>
156 lines
3.8 KiB
Go
156 lines
3.8 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 specs
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
|
|
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
|
|
"github.com/cloudnative-pg/machinery/pkg/stringset"
|
|
rbacv1 "k8s.io/api/rbac/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
|
)
|
|
|
|
// BuildRole builds the Role object for this cluster
|
|
func BuildRole(
|
|
cluster *cnpgv1.Cluster,
|
|
barmanObjects []barmancloudv1.ObjectStore,
|
|
) *rbacv1.Role {
|
|
return &rbacv1.Role{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Namespace: cluster.Namespace,
|
|
Name: GetRBACName(cluster.Name),
|
|
Labels: BuildLabels(cluster),
|
|
},
|
|
Rules: BuildRoleRules(barmanObjects),
|
|
}
|
|
}
|
|
|
|
// BuildRoleRules builds the RBAC PolicyRules for the given ObjectStores.
|
|
//
|
|
//nolint:goconst
|
|
func BuildRoleRules(barmanObjects []barmancloudv1.ObjectStore) []rbacv1.PolicyRule {
|
|
secretsSet := stringset.New()
|
|
barmanObjectsSet := stringset.New()
|
|
|
|
for _, barmanObject := range barmanObjects {
|
|
barmanObjectsSet.Put(barmanObject.Name)
|
|
for _, secret := range CollectSecretNamesFromCredentials(&barmanObject.Spec.Configuration.BarmanCredentials) {
|
|
secretsSet.Put(secret)
|
|
}
|
|
}
|
|
|
|
return []rbacv1.PolicyRule{
|
|
{
|
|
APIGroups: []string{
|
|
barmancloudv1.GroupVersion.Group,
|
|
},
|
|
Verbs: []string{
|
|
"get",
|
|
"watch",
|
|
"list",
|
|
},
|
|
Resources: []string{
|
|
"objectstores",
|
|
},
|
|
ResourceNames: barmanObjectsSet.ToSortedList(),
|
|
},
|
|
{
|
|
APIGroups: []string{
|
|
barmancloudv1.GroupVersion.Group,
|
|
},
|
|
Verbs: []string{
|
|
"update",
|
|
},
|
|
Resources: []string{
|
|
"objectstores/status",
|
|
},
|
|
ResourceNames: barmanObjectsSet.ToSortedList(),
|
|
},
|
|
{
|
|
APIGroups: []string{
|
|
"",
|
|
},
|
|
Resources: []string{
|
|
"secrets",
|
|
},
|
|
Verbs: []string{
|
|
"get",
|
|
"watch",
|
|
"list",
|
|
},
|
|
ResourceNames: secretsSet.ToSortedList(),
|
|
},
|
|
}
|
|
}
|
|
|
|
// ObjectStoreNamesFromRole extracts the ObjectStore names referenced
|
|
// by a plugin-managed Role. It finds the objectstores rule
|
|
// semantically (by APIGroup and Resource, not by index) and returns
|
|
// a copy of its ResourceNames. Returns nil if no matching rule is
|
|
// found.
|
|
func ObjectStoreNamesFromRole(role *rbacv1.Role) []string {
|
|
for _, rule := range role.Rules {
|
|
if len(rule.APIGroups) == 1 &&
|
|
rule.APIGroups[0] == barmancloudv1.GroupVersion.Group &&
|
|
len(rule.Resources) == 1 &&
|
|
rule.Resources[0] == "objectstores" {
|
|
return slices.Clone(rule.ResourceNames)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// BuildRoleBinding builds the role binding object for this cluster
|
|
func BuildRoleBinding(
|
|
cluster *cnpgv1.Cluster,
|
|
) *rbacv1.RoleBinding {
|
|
return &rbacv1.RoleBinding{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Namespace: cluster.Namespace,
|
|
Name: GetRBACName(cluster.Name),
|
|
Labels: BuildLabels(cluster),
|
|
},
|
|
Subjects: []rbacv1.Subject{
|
|
{
|
|
Kind: "ServiceAccount",
|
|
APIGroup: "",
|
|
Name: cluster.Name,
|
|
Namespace: cluster.Namespace,
|
|
},
|
|
},
|
|
RoleRef: rbacv1.RoleRef{
|
|
APIGroup: "rbac.authorization.k8s.io",
|
|
Kind: "Role",
|
|
Name: GetRBACName(cluster.Name),
|
|
},
|
|
}
|
|
}
|
|
|
|
// GetRBACName returns the name of the RBAC entities for the
|
|
// barman cloud plugin
|
|
func GetRBACName(clusterName string) string {
|
|
return fmt.Sprintf("%s-barman-cloud", clusterName)
|
|
}
|