mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-13 22:23:11 +01:00
Compare commits
8 Commits
6a471b375d
...
d71ae18319
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d71ae18319 | ||
|
|
921b20c249 | ||
|
|
2cb76ef622 | ||
|
|
cdb893a70d | ||
|
|
6d2d3eb925 | ||
|
|
80dfe727ed | ||
|
|
c811749c32 | ||
|
|
1c3dd8558f |
@ -128,6 +128,7 @@ pluginConfiguration
|
|||||||
podName
|
podName
|
||||||
postgres
|
postgres
|
||||||
postgresql
|
postgresql
|
||||||
|
pprof
|
||||||
primaryUpdateStrategy
|
primaryUpdateStrategy
|
||||||
rbac
|
rbac
|
||||||
rc
|
rc
|
||||||
|
|||||||
@ -15,6 +15,7 @@ RUN go mod download
|
|||||||
COPY ../cmd/manager/main.go cmd/manager/main.go
|
COPY ../cmd/manager/main.go cmd/manager/main.go
|
||||||
COPY ../api/ api/
|
COPY ../api/ api/
|
||||||
COPY ../internal/ internal/
|
COPY ../internal/ internal/
|
||||||
|
COPY ../pkg/ pkg/
|
||||||
|
|
||||||
ENV GOCACHE=/root/.cache/go-build
|
ENV GOCACHE=/root/.cache/go-build
|
||||||
ENV GOMODCACHE=/go/pkg/mod
|
ENV GOMODCACHE=/go/pkg/mod
|
||||||
|
|||||||
@ -24,6 +24,7 @@ ENV GOMODCACHE=/go/pkg/mod
|
|||||||
COPY ../cmd/manager/main.go cmd/manager/main.go
|
COPY ../cmd/manager/main.go cmd/manager/main.go
|
||||||
COPY ../api/ api/
|
COPY ../api/ api/
|
||||||
COPY ../internal/ internal/
|
COPY ../internal/ internal/
|
||||||
|
COPY ../pkg/ pkg/
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
# the GOARCH has not a default value to allow the binary be built according to the host where the command
|
# the GOARCH has not a default value to allow the binary be built according to the host where the command
|
||||||
|
|||||||
@ -52,6 +52,13 @@ func NewCmd() *cobra.Command {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flags().String("pprof-server",
|
||||||
|
"",
|
||||||
|
"The address where pprof server should be exposed, for example: 0.0.0.0:6061. "+
|
||||||
|
"Empty string means disabled. Disabled by default",
|
||||||
|
)
|
||||||
|
_ = viper.BindPFlag("pprof-server", cmd.Flags().Lookup("pprof-server"))
|
||||||
|
|
||||||
_ = viper.BindEnv("namespace", "NAMESPACE")
|
_ = viper.BindEnv("namespace", "NAMESPACE")
|
||||||
_ = viper.BindEnv("cluster-name", "CLUSTER_NAME")
|
_ = viper.BindEnv("cluster-name", "CLUSTER_NAME")
|
||||||
_ = viper.BindEnv("pod-name", "POD_NAME")
|
_ = viper.BindEnv("pod-name", "POD_NAME")
|
||||||
|
|||||||
@ -20,13 +20,17 @@ SPDX-License-Identifier: Apache-2.0
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
barmanapi "github.com/cloudnative-pg/barman-cloud/pkg/api"
|
barmanapi "github.com/cloudnative-pg/barman-cloud/pkg/api"
|
||||||
|
"github.com/cloudnative-pg/barman-cloud/pkg/command"
|
||||||
|
|
||||||
|
apiv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
||||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
||||||
|
pluginmetadata "github.com/cloudnative-pg/plugin-barman-cloud/pkg/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: refactor.
|
// TODO: refactor.
|
||||||
@ -97,3 +101,14 @@ func MergeEnv(env []string, incomingEnv []string) []string {
|
|||||||
func BuildCertificateFilePath(objectStoreName string) string {
|
func BuildCertificateFilePath(objectStoreName string) string {
|
||||||
return path.Join(metadata.BarmanCertificatesPath, objectStoreName, metadata.BarmanCertificatesFileName)
|
return path.Join(metadata.BarmanCertificatesPath, objectStoreName, metadata.BarmanCertificatesFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContextWithProviderOptions enriches the context with cloud service provider specific options
|
||||||
|
// based on the ObjectStore resource
|
||||||
|
func ContextWithProviderOptions(ctx context.Context, objectStore apiv1.ObjectStore) context.Context {
|
||||||
|
if objectStore.GetAnnotations()[pluginmetadata.UseDefaultAzureCredentialAnnotationName] ==
|
||||||
|
pluginmetadata.UseDefaultAzureCredentialTrueValue {
|
||||||
|
return command.ContextWithDefaultAzureCredentials(ctx, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|||||||
@ -127,6 +127,8 @@ func (w WALServiceImplementation) Archive(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx = ContextWithProviderOptions(ctx, objectStore)
|
||||||
|
|
||||||
envArchive, err := barmanCredentials.EnvSetCloudCredentialsAndCertificates(
|
envArchive, err := barmanCredentials.EnvSetCloudCredentialsAndCertificates(
|
||||||
ctx,
|
ctx,
|
||||||
w.Client,
|
w.Client,
|
||||||
|
|||||||
@ -87,6 +87,8 @@ func (b BackupServiceImplementation) Backup(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx = common.ContextWithProviderOptions(ctx, objectStore)
|
||||||
|
|
||||||
if err := fileutils.EnsureDirectoryExists(postgres.BackupTemporaryDirectory); err != nil {
|
if err := fileutils.EnsureDirectoryExists(postgres.BackupTemporaryDirectory); err != nil {
|
||||||
contextLogger.Error(err, "Cannot create backup temporary directory", "err", err)
|
contextLogger.Error(err, "Cannot create backup temporary directory", "err", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@ -52,6 +52,7 @@ func Start(ctx context.Context) error {
|
|||||||
namespace := viper.GetString("namespace")
|
namespace := viper.GetString("namespace")
|
||||||
|
|
||||||
controllerOptions := ctrl.Options{
|
controllerOptions := ctrl.Options{
|
||||||
|
PprofBindAddress: viper.GetString("pprof-server"),
|
||||||
Scheme: scheme,
|
Scheme: scheme,
|
||||||
Client: client.Options{
|
Client: client.Options{
|
||||||
// Important: the caching options below are used by
|
// Important: the caching options below are used by
|
||||||
|
|||||||
@ -93,6 +93,8 @@ func (c *CatalogMaintenanceRunnable) cycle(ctx context.Context) (time.Duration,
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx = common.ContextWithProviderOptions(ctx, barmanObjectStore)
|
||||||
|
|
||||||
if err := c.maintenance(ctx, &cluster, &barmanObjectStore); err != nil {
|
if err := c.maintenance(ctx, &cluster, &barmanObjectStore); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,7 +109,7 @@ func (impl JobHookImpl) Restore(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := impl.checkBackupDestination(
|
if err := impl.checkBackupDestination(
|
||||||
ctx,
|
common.ContextWithProviderOptions(ctx, targetObjectStore),
|
||||||
configuration.Cluster,
|
configuration.Cluster,
|
||||||
&targetObjectStore.Spec.Configuration,
|
&targetObjectStore.Spec.Configuration,
|
||||||
targetObjectStore.Name,
|
targetObjectStore.Name,
|
||||||
@ -118,6 +118,8 @@ func (impl JobHookImpl) Restore(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx = common.ContextWithProviderOptions(ctx, recoveryObjectStore)
|
||||||
|
|
||||||
// Detect the backup to recover
|
// Detect the backup to recover
|
||||||
backup, env, err := loadBackupObjectFromExternalCluster(
|
backup, env, err := loadBackupObjectFromExternalCluster(
|
||||||
ctx,
|
ctx,
|
||||||
|
|||||||
2
pkg/metadata/doc.go
Normal file
2
pkg/metadata/doc.go
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Package metadata provides metadata utilities for the Barman Cloud plugin
|
||||||
|
package metadata
|
||||||
15
pkg/metadata/labels_annotations.go
Normal file
15
pkg/metadata/labels_annotations.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package metadata
|
||||||
|
|
||||||
|
// MetadataNamespace is the namespace used for the Barman Cloud plugin metadata
|
||||||
|
const MetadataNamespace = "barmancloud.cnpg.io"
|
||||||
|
|
||||||
|
const (
|
||||||
|
// UseDefaultAzureCredentialAnnotationName is an annotation that can be set
|
||||||
|
// on an ObjectStore resource to enable the authentication to Azure via DefaultAzureCredential.
|
||||||
|
// This is meant to be used with inheritFromAzureAD enabled.
|
||||||
|
UseDefaultAzureCredentialAnnotationName = MetadataNamespace + "/useDefaultAzureCredential"
|
||||||
|
|
||||||
|
// UseDefaultAzureCredentialTrueValue is the value for the annotation
|
||||||
|
// barmancloud.cnpg.io/useDefaultAzureCredential to enable the DefaultAzureCredentials auth mechanism.
|
||||||
|
UseDefaultAzureCredentialTrueValue = "true"
|
||||||
|
)
|
||||||
@ -74,3 +74,24 @@ spec:
|
|||||||
|
|
||||||
For a complete list of supported options, refer to the
|
For a complete list of supported options, refer to the
|
||||||
[official Barman Cloud documentation](https://docs.pgbarman.org/release/latest/).
|
[official Barman Cloud documentation](https://docs.pgbarman.org/release/latest/).
|
||||||
|
|
||||||
|
## Enable the pprof debug server for the sidecar
|
||||||
|
|
||||||
|
You can enable the instance sidecar's pprof debug HTTP server by adding the `--pprof-server=<address>` flag to the container's
|
||||||
|
arguments via `.spec.instanceSidecarConfiguration.additionalContainerArgs`.
|
||||||
|
|
||||||
|
Pass a bind address in the form `<host>:<port>` (for example, `0.0.0.0:6061`).
|
||||||
|
An empty value disables the server (disabled by default).
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: barmancloud.cnpg.io/v1
|
||||||
|
kind: ObjectStore
|
||||||
|
metadata:
|
||||||
|
name: my-store
|
||||||
|
spec:
|
||||||
|
instanceSidecarConfiguration:
|
||||||
|
additionalContainerArgs:
|
||||||
|
- "--pprof-server=0.0.0.0:6061"
|
||||||
|
```
|
||||||
|
|||||||
@ -233,6 +233,7 @@ Barman Cloud supports the following authentication methods:
|
|||||||
- Storage Account Name + [Access Key](https://learn.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage)
|
- Storage Account Name + [Access Key](https://learn.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage)
|
||||||
- Storage Account Name + [SAS Token](https://learn.microsoft.com/en-us/azure/storage/blobs/sas-service-create)
|
- Storage Account Name + [SAS Token](https://learn.microsoft.com/en-us/azure/storage/blobs/sas-service-create)
|
||||||
- [Azure AD Workload Identity](https://azure.github.io/azure-workload-identity/docs/introduction.html)
|
- [Azure AD Workload Identity](https://azure.github.io/azure-workload-identity/docs/introduction.html)
|
||||||
|
- [DefaultAzureCredential](https://learn.microsoft.com/en-us/azure/developer/go/sdk/authentication/credential-chains#defaultazurecredential-overview)
|
||||||
|
|
||||||
### Azure AD Workload Identity
|
### Azure AD Workload Identity
|
||||||
|
|
||||||
@ -252,6 +253,27 @@ spec:
|
|||||||
[...]
|
[...]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### DefaultAzureCredential
|
||||||
|
|
||||||
|
To authenticate using `DefaultAzureCredential`, set the annotation
|
||||||
|
`barmancloud.cnpg.io/useDefaultAzureCredential="true"` on the ObjectStore in
|
||||||
|
conjunction with the `.spec.configuration.inheritFromAzureAD` option:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: barmancloud.cnpg.io/v1
|
||||||
|
kind: ObjectStore
|
||||||
|
metadata:
|
||||||
|
name: azure-store
|
||||||
|
annotations:
|
||||||
|
barmancloud.cnpg.io/useDefaultAzureCredential: "true"
|
||||||
|
spec:
|
||||||
|
configuration:
|
||||||
|
destinationPath: "<destination path here>"
|
||||||
|
azureCredentials:
|
||||||
|
inheritFromAzureAD: true
|
||||||
|
[...]
|
||||||
|
```
|
||||||
|
|
||||||
### Access Key, SAS Token, or Connection String
|
### Access Key, SAS Token, or Connection String
|
||||||
|
|
||||||
Store credentials in a Kubernetes secret:
|
Store credentials in a Kubernetes secret:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user