feat: support backup hooks on native sidecars (#9403)
Run the E2E test on kind / get-go-version (push) Failing after 51s
Run the E2E test on kind / build (push) Has been skipped
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / get-go-version (push) Successful in 10s
Main CI / Build (push) Failing after 25s
Close stale issues and PRs / stale (push) Successful in 9s
Trivy Nightly Scan / Trivy nightly scan (velero, main) (push) Failing after 1m28s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-aws, main) (push) Failing after 55s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-gcp, main) (push) Failing after 1m2s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-microsoft-azure, main) (push) Failing after 1m1s

* feat: support backup hooks on sidecars
Add support for configuring Kubernates native
Sidecars as target containrs for Backup Hooks
commands. This is purely a validation level
patch as the actual pods/exec API doesn't make
any distinction between standard and sidecar
containers.

Signed-off-by: Gabriele Fedi <gabriele.fedi@enterprisedb.com>

* test: extend unit tests

Signed-off-by: Gabriele Fedi <gabriele.fedi@enterprisedb.com>

* chore: changelog

Signed-off-by: Gabriele Fedi <gabriele.fedi@enterprisedb.com>

* style: fix linter issues

Signed-off-by: Gabriele Fedi <gabriele.fedi@enterprisedb.com>

---------

Signed-off-by: Gabriele Fedi <gabriele.fedi@enterprisedb.com>
This commit is contained in:
Gabriele Fedi
2026-04-01 14:27:18 -04:00
committed by GitHub
parent f0aa64172e
commit 5433eb3081
3 changed files with 35 additions and 5 deletions
+1
View File
@@ -0,0 +1 @@
Include InitContainer configured as Sidecars when validating the existence of the target containers configured for the Backup Hooks
+17 -4
View File
@@ -20,6 +20,7 @@ import (
"bytes"
"context"
"net/url"
"slices"
"time"
"github.com/pkg/errors"
@@ -184,10 +185,22 @@ func (e *defaultPodCommandExecutor) ExecutePodCommand(log logrus.FieldLogger, it
}
func ensureContainerExists(pod *corev1api.Pod, container string) error {
for _, c := range pod.Spec.Containers {
if c.Name == container {
return nil
}
existsAsMainContainer := slices.ContainsFunc(pod.Spec.Containers, func(c corev1api.Container) bool {
return c.Name == container
})
if existsAsMainContainer {
return nil
}
existsAsSidecar := slices.ContainsFunc(pod.Spec.InitContainers, func(c corev1api.Container) bool {
return c.RestartPolicy != nil &&
*c.RestartPolicy == corev1api.ContainerRestartPolicyAlways &&
c.Name == container
})
if existsAsSidecar {
return nil
}
return errors.Errorf("no such container: %q", container)
+17 -1
View File
@@ -35,6 +35,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/remotecommand"
"k8s.io/utils/ptr"
v1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
velerotest "github.com/vmware-tanzu/velero/pkg/test"
@@ -253,6 +254,15 @@ func TestEnsureContainerExists(t *testing.T) {
Name: "foo",
},
},
InitContainers: []corev1api.Container{
{
Name: "baz",
},
{
Name: "qux",
RestartPolicy: ptr.To(corev1api.ContainerRestartPolicyAlways),
},
},
},
}
@@ -260,7 +270,13 @@ func TestEnsureContainerExists(t *testing.T) {
require.EqualError(t, err, `no such container: "bar"`)
err = ensureContainerExists(pod, "foo")
assert.NoError(t, err)
require.NoError(t, err)
err = ensureContainerExists(pod, "baz")
require.EqualError(t, err, `no such container: "baz"`)
err = ensureContainerExists(pod, "qux")
require.NoError(t, err)
}
func TestPodCompeted(t *testing.T) {