mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-09 17:46:09 +00:00
Merge branch 'main' into issue-fix-9659
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Include InitContainer configured as Sidecars when validating the existence of the target containers configured for the Backup Hooks
|
||||
@@ -22,7 +22,7 @@ ENV GOPROXY=${GOPROXY}
|
||||
|
||||
# kubebuilder test bundle is separated from kubebuilder. Need to setup it for CI test.
|
||||
# Using setup-envtest to download envtest binaries
|
||||
RUN go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest && \
|
||||
RUN go install sigs.k8s.io/controller-runtime/tools/setup-envtest@v0.0.0-20260305094418-8122a6266696 && \
|
||||
mkdir -p /usr/local/kubebuilder/bin && \
|
||||
ENVTEST_ASSETS_DIR=$(setup-envtest use 1.33.0 --bin-dir /usr/local/kubebuilder/bin -p path) && \
|
||||
cp -r ${ENVTEST_ASSETS_DIR}/* /usr/local/kubebuilder/bin/
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user