mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-11 21:23:12 +01:00
Adds support for building and publishing Docker images for both amd64 and arm64 architectures. Ensures compatibility across multiple platforms by using cross-compilation. Updates relevant configuration files for CI/CD to handle the new build process. Fixes issues related to Python version conflicts and ensures the correct directory structure in the final image. Signed-off-by: Francesco Canovai <francesco.canovai@enterprisedb.com> Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com> Signed-off-by: Jonathan Gonzalez V. <jonathan.abdiel@gmail.com> Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com> Co-authored-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com> Co-authored-by: Jonathan Gonzalez V. <jonathan.abdiel@gmail.com> Co-authored-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
106 lines
2.7 KiB
Go
106 lines
2.7 KiB
Go
package operator
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/cloudnative-pg/cnpg-i-machinery/pkg/pluginhelper/decoder"
|
|
"github.com/cloudnative-pg/cnpg-i-machinery/pkg/pluginhelper/object"
|
|
"github.com/cloudnative-pg/cnpg-i/pkg/lifecycle"
|
|
"github.com/cloudnative-pg/machinery/pkg/log"
|
|
"github.com/spf13/viper"
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
|
|
)
|
|
|
|
// LifecycleImplementation is the implementation of the lifecycle handler
|
|
type LifecycleImplementation struct {
|
|
lifecycle.UnimplementedOperatorLifecycleServer
|
|
}
|
|
|
|
// GetCapabilities exposes the lifecycle capabilities
|
|
func (impl LifecycleImplementation) GetCapabilities(
|
|
_ context.Context,
|
|
_ *lifecycle.OperatorLifecycleCapabilitiesRequest,
|
|
) (*lifecycle.OperatorLifecycleCapabilitiesResponse, error) {
|
|
return &lifecycle.OperatorLifecycleCapabilitiesResponse{
|
|
LifecycleCapabilities: []*lifecycle.OperatorLifecycleCapabilities{
|
|
{
|
|
Group: "",
|
|
Kind: "Pod",
|
|
OperationTypes: []*lifecycle.OperatorOperationType{
|
|
{
|
|
Type: lifecycle.OperatorOperationType_TYPE_CREATE,
|
|
},
|
|
{
|
|
Type: lifecycle.OperatorOperationType_TYPE_PATCH,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
// LifecycleHook is called when creating Kubernetes services
|
|
func (impl LifecycleImplementation) LifecycleHook(
|
|
ctx context.Context,
|
|
request *lifecycle.OperatorLifecycleRequest,
|
|
) (*lifecycle.OperatorLifecycleResponse, error) {
|
|
contextLogger := log.FromContext(ctx).WithName("plugin-barman-cloud-lifecycle")
|
|
|
|
operation := request.GetOperationType().GetType().Enum()
|
|
if operation == nil {
|
|
return nil, errors.New("no operation set")
|
|
}
|
|
|
|
cluster, err := decoder.DecodeClusterJSON(request.GetClusterDefinition())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pod, err := decoder.DecodePodJSON(request.GetObjectDefinition())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pluginConfiguration, err := config.NewFromCluster(cluster)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
mutatedPod := pod.DeepCopy()
|
|
err = object.InjectPluginSidecar(mutatedPod, &corev1.Container{
|
|
Name: "plugin-barman-cloud",
|
|
Image: viper.GetString("sidecar-image"),
|
|
Env: []corev1.EnvVar{
|
|
{
|
|
Name: "BARMAN_OBJECT_NAME",
|
|
Value: pluginConfiguration.BarmanObjectName,
|
|
},
|
|
{
|
|
// TODO: should we really use this one?
|
|
// should we mount an emptyDir volume just for that?
|
|
Name: "SPOOL_DIRECTORY",
|
|
Value: "/controller/wal-restore-spool",
|
|
},
|
|
},
|
|
Command: []string{
|
|
"/usr/local/bin/instance",
|
|
},
|
|
}, true)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
patch, err := object.CreatePatch(mutatedPod, pod)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
contextLogger.Debug("generated patch", "content", string(patch))
|
|
return &lifecycle.OperatorLifecycleResponse{
|
|
JsonPatch: patch,
|
|
}, nil
|
|
}
|