mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-09-04 14:12:21 +02:00
CloudNativePG is moving the bootstrap of new instances from dedicated Jobs into the instance pod itself (cloudnative-pg/cloudnative-pg#11319): the restore that used to run in a recovery Job now happens in-process inside the instance pod before PostgreSQL starts. The sidecar shipped in that pod must therefore answer the same Restore RPC the operator sends over the plugin sockets, so the instance mode now registers the restore-job hooks and advertises the restore-job service capability. A cluster that only bootstraps from an object store, without continued archiving, previously received no sidecar at all in its instance pods; under the new flow that leaves the bootstrap without a plugin socket, both for the Restore RPC and for `wal-restore` during the recovery replay. The injection condition is widened to match what the plugin configuration already considers valid, so recovery-only clusters get the sidecar too. The sidecar is dropped once the instance's bootstrap completes (cluster.Status.CurrentPrimary set), which triggers one deterministic rollout to remove it, accepted rather than engineered around since it uses the same switchover/restart machinery as any other pod-spec change. Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com> Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Co-authored-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
105 lines
3.6 KiB
Go
105 lines
3.6 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 common
|
|
|
|
import (
|
|
"fmt"
|
|
"path"
|
|
"strings"
|
|
|
|
barmanapi "github.com/cloudnative-pg/barman-cloud/pkg/api"
|
|
|
|
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
|
)
|
|
|
|
// TODO: refactor.
|
|
const (
|
|
// ScratchDataDirectory is the directory to be used for scratch data.
|
|
ScratchDataDirectory = "/controller"
|
|
|
|
// CertificatesDir location to store the certificates.
|
|
CertificatesDir = ScratchDataDirectory + "/certificates/"
|
|
|
|
// BarmanBackupEndpointCACertificateLocation is the location where the barman endpoint
|
|
// CA certificate is stored.
|
|
BarmanBackupEndpointCACertificateLocation = CertificatesDir + BarmanBackupEndpointCACertificateFileName
|
|
|
|
// BarmanBackupEndpointCACertificateFileName is the name of the file in which the barman endpoint
|
|
// CA certificate for backups is stored.
|
|
BarmanBackupEndpointCACertificateFileName = "backup-" + BarmanEndpointCACertificateFileName
|
|
|
|
// BarmanRestoreEndpointCACertificateFileName is the name of the file in which the barman endpoint
|
|
// CA certificate for restores is stored.
|
|
BarmanRestoreEndpointCACertificateFileName = "restore-" + BarmanEndpointCACertificateFileName
|
|
|
|
// BarmanEndpointCACertificateFileName is the name of the file in which the barman endpoint
|
|
// CA certificate is stored.
|
|
BarmanEndpointCACertificateFileName = "barman-ca.crt"
|
|
|
|
// PgWalVolumePgWalPath is the path of the pg_wal directory inside the WAL volume,
|
|
// used when a separate WAL storage is configured. During a restore the pg_wal
|
|
// directory is moved here and symlinked back into PGDATA.
|
|
PgWalVolumePgWalPath = "/var/lib/postgresql/wal/pg_wal"
|
|
)
|
|
|
|
// GetRestoreCABundleEnv gets the enveronment variables to be used when custom
|
|
// Object Store CA is present
|
|
func GetRestoreCABundleEnv(configuration *barmanapi.BarmanObjectStoreConfiguration) []string {
|
|
var env []string
|
|
|
|
if configuration.EndpointCA != nil && configuration.AWS != nil {
|
|
env = append(env, fmt.Sprintf("AWS_CA_BUNDLE=%s", BarmanBackupEndpointCACertificateLocation))
|
|
} else if configuration.EndpointCA != nil && configuration.Azure != nil {
|
|
env = append(env, fmt.Sprintf("REQUESTS_CA_BUNDLE=%s", BarmanBackupEndpointCACertificateLocation))
|
|
}
|
|
return env
|
|
}
|
|
|
|
// MergeEnv merges all the values inside incomingEnv into env.
|
|
func MergeEnv(env []string, incomingEnv []string) []string {
|
|
result := make([]string, len(env), len(env)+len(incomingEnv))
|
|
copy(result, env)
|
|
|
|
for _, incomingItem := range incomingEnv {
|
|
incomingKV := strings.SplitAfterN(incomingItem, "=", 2)
|
|
if len(incomingKV) != 2 {
|
|
continue
|
|
}
|
|
|
|
found := false
|
|
for idx, item := range result {
|
|
if strings.HasPrefix(item, incomingKV[0]) {
|
|
result[idx] = incomingItem
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
result = append(result, incomingItem)
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
// BuildCertificateFilePath builds the path to the barman objectStore certificate
|
|
func BuildCertificateFilePath(objectStoreName string) string {
|
|
return path.Join(metadata.BarmanCertificatesPath, objectStoreName, metadata.BarmanCertificatesFileName)
|
|
}
|