From fc4795f509eed427ea06352aba73a8ec8830988d Mon Sep 17 00:00:00 2001 From: Mathieu Ouellet Date: Mon, 19 Feb 2024 07:09:20 -0500 Subject: [PATCH] add namespace mapping action Signed-off-by: Mathieu Ouellet --- pkg/cmd/server/plugin/plugin.go | 6 +++--- ...mespace_action.go => namespace_mapping_action.go} | 12 ++++++------ ...tion_test.go => namespace_mapping_action_test.go} | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) rename pkg/restore/{namespace_action.go => namespace_mapping_action.go} (79%) rename pkg/restore/{namespace_action_test.go => namespace_mapping_action_test.go} (95%) diff --git a/pkg/cmd/server/plugin/plugin.go b/pkg/cmd/server/plugin/plugin.go index 94df151c6f..0985ef0219 100644 --- a/pkg/cmd/server/plugin/plugin.go +++ b/pkg/cmd/server/plugin/plugin.go @@ -61,7 +61,7 @@ func NewCommand(f client.Factory) *cobra.Command { RegisterRestoreItemAction("velero.io/apiservice", newAPIServiceRestoreItemAction). RegisterRestoreItemAction("velero.io/admission-webhook-configuration", newAdmissionWebhookConfigurationAction). RegisterRestoreItemAction("velero.io/secret", newSecretRestoreItemAction(f)). - RegisterRestoreItemAction("velero.io/namespaces", newNamespaceRestoreItemAction). + RegisterRestoreItemAction("velero.io/namespace-mapping", newNamespaceMappingRestoreItemAction). RegisterRestoreItemAction("velero.io/dataupload", newDataUploadRetrieveAction(f)). RegisterDeleteItemAction("velero.io/dataupload-delete", newDateUploadDeleteItemAction(f)) @@ -251,8 +251,8 @@ func newSecretRestoreItemAction(f client.Factory) plugincommon.HandlerInitialize } } -func newNamespaceRestoreItemAction(logger logrus.FieldLogger) (interface{}, error) { - return restore.NewNamespaceAction(logger), nil +func newNamespaceMappingRestoreItemAction(logger logrus.FieldLogger) (interface{}, error) { + return restore.NewNamespaceMappingAction(logger), nil } func newDataUploadRetrieveAction(f client.Factory) plugincommon.HandlerInitializer { diff --git a/pkg/restore/namespace_action.go b/pkg/restore/namespace_mapping_action.go similarity index 79% rename from pkg/restore/namespace_action.go rename to pkg/restore/namespace_mapping_action.go index b1e1d61f6a..0cee5a3227 100644 --- a/pkg/restore/namespace_action.go +++ b/pkg/restore/namespace_mapping_action.go @@ -26,22 +26,22 @@ import ( "github.com/vmware-tanzu/velero/pkg/plugin/velero" ) -// NamespaceAction handle namespace remappings -type NamespaceAction struct { +// NamespaceMappingAction handle namespace remappings +type NamespaceMappingAction struct { logger logrus.FieldLogger } -func NewNamespaceAction(logger logrus.FieldLogger) *NamespaceAction { - return &NamespaceAction{logger: logger} +func NewNamespaceMappingAction(logger logrus.FieldLogger) *NamespaceMappingAction { + return &NamespaceMappingAction{logger: logger} } -func (a *NamespaceAction) AppliesTo() (velero.ResourceSelector, error) { +func (a *NamespaceMappingAction) AppliesTo() (velero.ResourceSelector, error) { return velero.ResourceSelector{ IncludedResources: []string{"namespaces"}, }, nil } -func (a *NamespaceAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { +func (a *NamespaceMappingAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { namespaceMapping := input.Restore.Spec.NamespaceMapping if len(namespaceMapping) == 0 { return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: input.Item.UnstructuredContent()}), nil diff --git a/pkg/restore/namespace_action_test.go b/pkg/restore/namespace_mapping_action_test.go similarity index 95% rename from pkg/restore/namespace_action_test.go rename to pkg/restore/namespace_mapping_action_test.go index 9e97cc421c..91ef5089a0 100644 --- a/pkg/restore/namespace_action_test.go +++ b/pkg/restore/namespace_mapping_action_test.go @@ -31,7 +31,7 @@ import ( ) func TestNamespaceActionAppliesTo(t *testing.T) { - action := NewNamespaceAction(velerotest.NewLogger()) + action := NewNamespaceMappingAction(velerotest.NewLogger()) actual, err := action.AppliesTo() require.NoError(t, err) assert.Equal(t, velero.ResourceSelector{IncludedResources: []string{"namespaces"}}, actual) @@ -72,7 +72,7 @@ func TestNamespaceActionExecute(t *testing.T) { namespaceUnstructured, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&namespace) require.NoError(t, err) - action := NewNamespaceAction(velerotest.NewLogger()) + action := NewNamespaceMappingAction(velerotest.NewLogger()) res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: namespaceUnstructured}, ItemFromBackup: &unstructured.Unstructured{Object: namespaceUnstructured},