From 5fc8b3f4263107a82217419fbf41099d27ced414 Mon Sep 17 00:00:00 2001 From: Ming Qiu Date: Tue, 30 Jan 2024 05:44:24 +0000 Subject: [PATCH] Fix server start failure when no default BSL Signed-off-by: Ming Qiu --- pkg/cmd/server/server.go | 8 +++++++- pkg/cmd/server/server_test.go | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/server/server.go b/pkg/cmd/server/server.go index 06d164d74..da135e314 100644 --- a/pkg/cmd/server/server.go +++ b/pkg/cmd/server/server.go @@ -33,6 +33,7 @@ import ( "github.com/sirupsen/logrus" "github.com/spf13/cobra" corev1api "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -467,7 +468,12 @@ func setDefaultBackupLocation(ctx context.Context, client ctrlclient.Client, nam backupLocation := &velerov1api.BackupStorageLocation{} if err := client.Get(ctx, types.NamespacedName{Namespace: namespace, Name: defaultBackupLocation}, backupLocation); err != nil { - return errors.WithStack(err) + if apierrors.IsNotFound(err) { + logger.WithField("backupStorageLocation", defaultBackupLocation).WithError(err).Warn("Failed to set default backup storage location at server start") + return nil + } else { + return errors.WithStack(err) + } } if !backupLocation.Spec.Default { diff --git a/pkg/cmd/server/server_test.go b/pkg/cmd/server/server_test.go index e8c8c9b23..ab411c628 100644 --- a/pkg/cmd/server/server_test.go +++ b/pkg/cmd/server/server_test.go @@ -409,4 +409,13 @@ func Test_setDefaultBackupLocation(t *testing.T) { nonDefaultLocation := &velerov1api.BackupStorageLocation{} require.Nil(t, c.Get(context.Background(), client.ObjectKey{Namespace: "velero", Name: "non-default"}, nonDefaultLocation)) assert.False(t, nonDefaultLocation.Spec.Default) + + // no default location specified + c = fake.NewClientBuilder().WithScheme(scheme).Build() + err := setDefaultBackupLocation(context.Background(), c, "velero", "", logrus.New()) + assert.NoError(t, err) + + // no default location created + err = setDefaultBackupLocation(context.Background(), c, "velero", "default", logrus.New()) + assert.NoError(t, err) }