Compare commits

...

3 Commits

Author SHA1 Message Date
ChandonPierre
feb8dbd28e
Merge 9fd7ba5b5e into 77118ed413 2026-08-19 22:23:38 +05:30
renovate[bot]
77118ed413
chore(deps): update all cloudnative-pg daggerverse dependencies to 26cd57f (#1072)
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-08-19 13:01:46 +02:00
Chandon Pierre
9fd7ba5b5e feat: allow ObjectStore sidecar image override
The current configuration derives the sidecar image from configuration paramter `sidecar-image`: 1e13020fe5/internal/cnpgi/operator/lifecycle.go (L418)

However, this is challenging for multi-tenant Kubernetes clusters, as the plugin deployment defines the target sidecar image for all CNPG clusters within a given Kubernetes cluster.

In this PR, we add an optional `sidecarImage` field to `ObjectStore.spec.instanceSidecarConfiguration`.

This allows workloads using a specific ObjectStore to override the Barman Cloud sidecar image configured globally on the plugin deployment.

Signed-off-by: Chandon Pierre <cpierre@coreweave.com>
2026-08-03 23:23:35 -04:00
6 changed files with 203 additions and 6 deletions

View File

@ -46,7 +46,7 @@ tasks:
- wordlist-ordered
env:
# renovate: datasource=git-refs depName=spellcheck lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main
DAGGER_SPELLCHECK_SHA: 7174b66d283da487638a98b431b7707b311a9a32
DAGGER_SPELLCHECK_SHA: 26cd57fb6ad66e88c036b675b0478d38df93962d
cmds:
- >
GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/spellcheck@${DAGGER_SPELLCHECK_SHA}
@ -60,7 +60,7 @@ tasks:
desc: Check for conventional commits
env:
# renovate: datasource=git-refs depName=commitlint lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main
DAGGER_COMMITLINT_SHA: 7174b66d283da487638a98b431b7707b311a9a32
DAGGER_COMMITLINT_SHA: 26cd57fb6ad66e88c036b675b0478d38df93962d
cmds:
- >
GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/commitlint@${DAGGER_COMMITLINT_SHA}
@ -74,7 +74,7 @@ tasks:
- wordlist-ordered
env:
# renovate: datasource=git-refs depName=uncommitted lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main
DAGGER_UNCOMMITTED_SHA: 7174b66d283da487638a98b431b7707b311a9a32
DAGGER_UNCOMMITTED_SHA: 26cd57fb6ad66e88c036b675b0478d38df93962d
cmds:
- GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/uncommitted@${DAGGER_UNCOMMITTED_SHA} check-uncommitted --source . stdout
sources:
@ -86,7 +86,7 @@ tasks:
- controller-gen
env:
# renovate: datasource=git-refs depName=crd-gen-refs lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main
DAGGER_CRDGENREF_SHA: 7174b66d283da487638a98b431b7707b311a9a32
DAGGER_CRDGENREF_SHA: 26cd57fb6ad66e88c036b675b0478d38df93962d
# renovate: datasource=go depName=github.com/elastic/crd-ref-docs
CRDREFDOCS_VERSION: v0.3.0
cmds:
@ -383,7 +383,7 @@ tasks:
run: once
env:
# renovate: datasource=git-refs depName=controller-gen lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main
DAGGER_CONTROLLER_GEN_SHA: 7174b66d283da487638a98b431b7707b311a9a32
DAGGER_CONTROLLER_GEN_SHA: 26cd57fb6ad66e88c036b675b0478d38df93962d
cmds:
- >
GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/controller-gen@${DAGGER_CONTROLLER_GEN_SHA}

View File

@ -27,6 +27,11 @@ import (
// InstanceSidecarConfiguration defines the configuration for the sidecar that runs in the instance pods.
type InstanceSidecarConfiguration struct {
// SidecarImage overrides the plugin sidecar image for workloads that use this ObjectStore.
// When omitted, the image configured on the plugin deployment is used.
// +optional
SidecarImage string `json:"sidecarImage,omitempty"`
// The environment to be explicitly passed to the sidecar
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`

View File

@ -664,6 +664,11 @@ spec:
The retentionCheckInterval defines the frequency at which the
system checks and enforces retention policies.
type: integer
sidecarImage:
description: |-
SidecarImage overrides the plugin sidecar image for workloads that use this ObjectStore.
When omitted, the image configured on the plugin deployment is used.
type: string
type: object
retentionPolicy:
description: |-

View File

@ -150,10 +150,16 @@ func (impl LifecycleImplementation) reconcileJob(
return nil, err
}
image, err := impl.collectSidecarImageForRecoveryJob(ctx, pluginConfiguration)
if err != nil {
return nil, err
}
return reconcileJob(ctx, cluster, request, sidecarConfiguration{
env: env,
certificates: certificates,
resources: resources,
image: image,
})
}
@ -162,6 +168,7 @@ type sidecarConfiguration struct {
certificates []corev1.VolumeProjection
resources corev1.ResourceRequirements
additionalArgs []string
image string
}
func reconcileJob(
@ -248,11 +255,17 @@ func (impl LifecycleImplementation) reconcilePod(
return nil, err
}
image, err := impl.collectSidecarImageForPod(ctx, pluginConfiguration)
if err != nil {
return nil, err
}
return reconcileInstancePod(ctx, cluster, request, pluginConfiguration, sidecarConfiguration{
env: env,
certificates: certificates,
resources: resources,
additionalArgs: additionalArgs,
image: image,
})
}
@ -415,7 +428,10 @@ func reconcilePodSpec(
// fixed values
sidecarTemplate.Name = "plugin-barman-cloud"
sidecarTemplate.Image = viper.GetString("sidecar-image")
sidecarTemplate.Image = config.image
if sidecarTemplate.Image == "" {
sidecarTemplate.Image = viper.GetString("sidecar-image")
}
sidecarTemplate.ImagePullPolicy = cluster.Spec.ImagePullPolicy
sidecarTemplate.StartupProbe = baseProbe.DeepCopy()
sidecarTemplate.SecurityContext = &corev1.SecurityContext{

View File

@ -0,0 +1,75 @@
/*
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 operator
import (
"context"
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
)
func (impl LifecycleImplementation) collectSidecarImageForRecoveryJob(
ctx context.Context,
configuration *config.PluginConfiguration,
) (string, error) {
if len(configuration.RecoveryBarmanObjectName) == 0 {
return "", nil
}
var objectStore barmancloudv1.ObjectStore
if err := impl.Client.Get(ctx, configuration.GetRecoveryBarmanObjectKey(), &objectStore); err != nil {
return "", err
}
return objectStore.Spec.InstanceSidecarConfiguration.SidecarImage, nil
}
func (impl LifecycleImplementation) collectSidecarImageForPod(
ctx context.Context,
configuration *config.PluginConfiguration,
) (string, error) {
// Keep the same precedence used for sidecar resources and arguments.
switch {
case len(configuration.BarmanObjectName) > 0:
var objectStore barmancloudv1.ObjectStore
if err := impl.Client.Get(ctx, configuration.GetBarmanObjectKey(), &objectStore); err != nil {
return "", err
}
return objectStore.Spec.InstanceSidecarConfiguration.SidecarImage, nil
case len(configuration.RecoveryBarmanObjectName) > 0:
var objectStore barmancloudv1.ObjectStore
if err := impl.Client.Get(ctx, configuration.GetRecoveryBarmanObjectKey(), &objectStore); err != nil {
return "", err
}
return objectStore.Spec.InstanceSidecarConfiguration.SidecarImage, nil
case len(configuration.ReplicaSourceBarmanObjectName) > 0:
var objectStore barmancloudv1.ObjectStore
if err := impl.Client.Get(ctx, configuration.GetReplicaSourceBarmanObjectKey(), &objectStore); err != nil {
return "", err
}
return objectStore.Spec.InstanceSidecarConfiguration.SidecarImage, nil
default:
return "", nil
}
}

View File

@ -26,6 +26,7 @@ import (
"github.com/cloudnative-pg/cloudnative-pg/pkg/utils"
"github.com/cloudnative-pg/cnpg-i/pkg/lifecycle"
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
"github.com/spf13/viper"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
@ -517,6 +518,101 @@ var _ = Describe("LifecycleImplementation", func() {
Expect(err).To(HaveOccurred())
})
})
Describe("collectSidecarImage", func() {
makeStoreWithImageFunc := func(ns, name, image string) *barmancloudv1.ObjectStore {
return &barmancloudv1.ObjectStore{
TypeMeta: metav1.TypeMeta{Kind: "ObjectStore", APIVersion: barmancloudv1.GroupVersion.String()},
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: ns},
Spec: barmancloudv1.ObjectStoreSpec{
InstanceSidecarConfiguration: barmancloudv1.InstanceSidecarConfiguration{
SidecarImage: image,
},
},
}
}
It("uses the cluster object store image when multiple stores are configured", func(ctx SpecContext) {
ns := "test-ns"
cluster := &cnpgv1.Cluster{ObjectMeta: metav1.ObjectMeta{Name: "c", Namespace: ns}}
pc := &config.PluginConfiguration{
Cluster: cluster,
BarmanObjectName: "primary-store",
RecoveryBarmanObjectName: "recovery-store",
ReplicaSourceBarmanObjectName: "replica-store",
}
cli := buildClientFunc(
makeStoreWithImageFunc(ns, pc.BarmanObjectName, "example.com/primary:v1"),
makeStoreWithImageFunc(ns, pc.RecoveryBarmanObjectName, "example.com/recovery:v1"),
makeStoreWithImageFunc(ns, pc.ReplicaSourceBarmanObjectName, "example.com/replica:v1"),
).Build()
impl := LifecycleImplementation{Client: cli}
image, err := impl.collectSidecarImageForPod(ctx, pc)
Expect(err).NotTo(HaveOccurred())
Expect(image).To(Equal("example.com/primary:v1"))
})
It("uses the recovery object store image for recovery jobs", func(ctx SpecContext) {
ns := "test-ns"
cluster := &cnpgv1.Cluster{ObjectMeta: metav1.ObjectMeta{Name: "c", Namespace: ns}}
pc := &config.PluginConfiguration{
Cluster: cluster,
RecoveryBarmanObjectName: "recovery-store",
}
cli := buildClientFunc(
makeStoreWithImageFunc(ns, pc.RecoveryBarmanObjectName, "example.com/recovery:v1"),
).Build()
impl := LifecycleImplementation{Client: cli}
image, err := impl.collectSidecarImageForRecoveryJob(ctx, pc)
Expect(err).NotTo(HaveOccurred())
Expect(image).To(Equal("example.com/recovery:v1"))
})
It("returns an empty override when no object store is configured", func(ctx SpecContext) {
pc := &config.PluginConfiguration{Cluster: &cnpgv1.Cluster{}}
impl := LifecycleImplementation{Client: buildClientFunc().Build()}
image, err := impl.collectSidecarImageForPod(ctx, pc)
Expect(err).NotTo(HaveOccurred())
Expect(image).To(BeEmpty())
})
})
Describe("sidecar image selection", func() {
It("prefers the ObjectStore image override", func() {
spec := corev1.PodSpec{Containers: []corev1.Container{{Name: "postgres"}}}
err := reconcilePodSpec(
cluster,
&spec,
"postgres",
corev1.Container{Args: []string{"instance"}},
sidecarConfiguration{image: "example.com/override:v1"},
)
Expect(err).NotTo(HaveOccurred())
Expect(spec.InitContainers).To(HaveLen(1))
Expect(spec.InitContainers[0].Image).To(Equal("example.com/override:v1"))
})
It("falls back to the deployment sidecar image", func() {
previousImage := viper.GetString("sidecar-image")
viper.Set("sidecar-image", "example.com/global:v1")
DeferCleanup(viper.Set, "sidecar-image", previousImage)
spec := corev1.PodSpec{Containers: []corev1.Container{{Name: "postgres"}}}
err := reconcilePodSpec(
cluster,
&spec,
"postgres",
corev1.Container{Args: []string{"instance"}},
sidecarConfiguration{},
)
Expect(err).NotTo(HaveOccurred())
Expect(spec.InitContainers).To(HaveLen(1))
Expect(spec.InitContainers[0].Image).To(Equal("example.com/global:v1"))
})
})
})
var _ = Describe("Volume utilities", func() {