Skip to content

Commit

Permalink
add namespace mapping action
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu Ouellet <[email protected]>
  • Loading branch information
mouellet committed Feb 19, 2024
1 parent b7740d7 commit fc4795f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions pkg/cmd/server/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit fc4795f

Please sign in to comment.