Skip to content

Commit

Permalink
moved RIA execute input/output structs back to velero package
Browse files Browse the repository at this point in the history
The RIA refactoring moved velero.RestoreItemAction into a separate
(restoreitemaction) v1 package. Unfortunately, this change would require
plugins to make code changes to locate the RestoreItemActionExecuteInput
and RestoreItemActionExecuteOutput structs.

This commit restores those structs to the original velero package, leaving
just the RestoreItemAction interface in the new v1 package.

Signed-off-by: Scott Seago <sseago@redhat.com>
  • Loading branch information
sseago committed Oct 12, 2022
1 parent b5b4db2 commit 45de8a7
Show file tree
Hide file tree
Showing 40 changed files with 162 additions and 164 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/5441-sseago
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
moved RIA execute input/output structs back to velero package
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (r RestartableRestoreItemAction) AppliesTo() (velero.ResourceSelector, erro
}

// Execute restarts the plugin's process if needed, then delegates the call.
func (r *RestartableRestoreItemAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) {
func (r *RestartableRestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/vmware-tanzu/velero/pkg/plugin/framework/common"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
mocks "github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks/restoreitemaction/v1"
riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1"
)

func TestRestartableGetRestoreItemAction(t *testing.T) {
Expand Down Expand Up @@ -108,13 +107,13 @@ func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) {
},
}

input := &riav1.RestoreItemActionExecuteInput{
input := &velero.RestoreItemActionExecuteInput{
Item: pv,
ItemFromBackup: pv,
Restore: new(v1.Restore),
}

output := &riav1.RestoreItemActionExecuteOutput{
output := &velero.RestoreItemActionExecuteOutput{
UpdatedItem: &unstructured.Unstructured{
Object: map[string]interface{}{
"color": "green",
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/framework/restore_item_action_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (c *RestoreItemActionGRPCClient) AppliesTo() (velero.ResourceSelector, erro
}, nil
}

func (c *RestoreItemActionGRPCClient) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) {
func (c *RestoreItemActionGRPCClient) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) {
itemJSON, err := json.Marshal(input.Item.UnstructuredContent())
if err != nil {
return nil, errors.WithStack(err)
Expand Down Expand Up @@ -120,7 +120,7 @@ func (c *RestoreItemActionGRPCClient) Execute(input *riav1.RestoreItemActionExec
additionalItems = append(additionalItems, newItem)
}

return &riav1.RestoreItemActionExecuteOutput{
return &velero.RestoreItemActionExecuteOutput{
UpdatedItem: &updatedItem,
AdditionalItems: additionalItems,
SkipRestore: res.SkipRestore,
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/framework/restore_item_action_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s *RestoreItemActionGRPCServer) Execute(ctx context.Context, req *proto.Re
return nil, common.NewGRPCError(errors.WithStack(err))
}

executeOutput, err := impl.Execute(&riav1.RestoreItemActionExecuteInput{
executeOutput, err := impl.Execute(&velero.RestoreItemActionExecuteInput{
Item: &item,
ItemFromBackup: &itemFromBackup,
Restore: &restoreObj,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions pkg/plugin/velero/restore_item_action_shared.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package velero

import (
"k8s.io/apimachinery/pkg/runtime"

api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
)

// RestoreItemActionExecuteInput contains the input parameters for the ItemAction's Execute function.
type RestoreItemActionExecuteInput struct {
// Item is the item being restored. It is likely different from the pristine backed up version
// (metadata reset, changed by various restore item action plugins, etc.).
Item runtime.Unstructured
// ItemFromBackup is the item taken from the pristine backed up version of resource.
ItemFromBackup runtime.Unstructured
// Restore is the representation of the restore resource processed by Velero.
Restore *api.Restore
}

// RestoreItemActionExecuteOutput contains the output variables for the ItemAction's Execution function.
type RestoreItemActionExecuteOutput struct {
// UpdatedItem is the item being restored mutated by ItemAction.
UpdatedItem runtime.Unstructured

// AdditionalItems is a list of additional related items that should
// be restored.
AdditionalItems []ResourceIdentifier

// SkipRestore tells velero to stop executing further actions
// on this item, and skip the restore step. When this field's
// value is true, AdditionalItems will be ignored.
SkipRestore bool
}

// NewRestoreItemActionExecuteOutput creates a new RestoreItemActionExecuteOutput
func NewRestoreItemActionExecuteOutput(item runtime.Unstructured) *RestoreItemActionExecuteOutput {
return &RestoreItemActionExecuteOutput{
UpdatedItem: item,
}
}

// WithoutRestore returns SkipRestore for RestoreItemActionExecuteOutput
func (r *RestoreItemActionExecuteOutput) WithoutRestore() *RestoreItemActionExecuteOutput {
r.SkipRestore = true
return r
}
44 changes: 1 addition & 43 deletions pkg/plugin/velero/restoreitemaction/v1/restore_item_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ limitations under the License.
package v1

import (
"k8s.io/apimachinery/pkg/runtime"

api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
)

Expand All @@ -36,44 +33,5 @@ type RestoreItemAction interface {
// related items that should be restored, a warning (which will be logged but will not prevent
// the item from being restored) or error (which will be logged and will prevent the item
// from being restored) if applicable.
Execute(input *RestoreItemActionExecuteInput) (*RestoreItemActionExecuteOutput, error)
}

// RestoreItemActionExecuteInput contains the input parameters for the ItemAction's Execute function.
type RestoreItemActionExecuteInput struct {
// Item is the item being restored. It is likely different from the pristine backed up version
// (metadata reset, changed by various restore item action plugins, etc.).
Item runtime.Unstructured
// ItemFromBackup is the item taken from the pristine backed up version of resource.
ItemFromBackup runtime.Unstructured
// Restore is the representation of the restore resource processed by Velero.
Restore *api.Restore
}

// RestoreItemActionExecuteOutput contains the output variables for the ItemAction's Execution function.
type RestoreItemActionExecuteOutput struct {
// UpdatedItem is the item being restored mutated by ItemAction.
UpdatedItem runtime.Unstructured

// AdditionalItems is a list of additional related items that should
// be restored.
AdditionalItems []velero.ResourceIdentifier

// SkipRestore tells velero to stop executing further actions
// on this item, and skip the restore step. When this field's
// value is true, AdditionalItems will be ignored.
SkipRestore bool
}

// NewRestoreItemActionExecuteOutput creates a new RestoreItemActionExecuteOutput
func NewRestoreItemActionExecuteOutput(item runtime.Unstructured) *RestoreItemActionExecuteOutput {
return &RestoreItemActionExecuteOutput{
UpdatedItem: item,
}
}

// WithoutRestore returns SkipRestore for RestoreItemActionExecuteOutput
func (r *RestoreItemActionExecuteOutput) WithoutRestore() *RestoreItemActionExecuteOutput {
r.SkipRestore = true
return r
Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error)
}
7 changes: 3 additions & 4 deletions pkg/restore/add_pv_from_pvc_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/vmware-tanzu/velero/pkg/kuberesource"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1"
)

type AddPVFromPVCAction struct {
Expand All @@ -41,7 +40,7 @@ func (a *AddPVFromPVCAction) AppliesTo() (velero.ResourceSelector, error) {
}, nil
}

func (a *AddPVFromPVCAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) {
func (a *AddPVFromPVCAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) {
a.logger.Info("Executing AddPVFromPVCAction")

// use input.ItemFromBackup because we need to look at status fields, which have already been
Expand All @@ -54,7 +53,7 @@ func (a *AddPVFromPVCAction) Execute(input *riav1.RestoreItemActionExecuteInput)
// TODO: consolidate this logic in a helper function to share with backup_pv_action.go
if pvc.Status.Phase != corev1api.ClaimBound || pvc.Spec.VolumeName == "" {
a.logger.Info("PVC is not bound or its volume name is empty")
return &riav1.RestoreItemActionExecuteOutput{
return &velero.RestoreItemActionExecuteOutput{
UpdatedItem: input.Item,
}, nil
}
Expand All @@ -65,7 +64,7 @@ func (a *AddPVFromPVCAction) Execute(input *riav1.RestoreItemActionExecuteInput)
}

a.logger.Infof("Adding PV %s as an additional item to restore", pvc.Spec.VolumeName)
return &riav1.RestoreItemActionExecuteOutput{
return &velero.RestoreItemActionExecuteOutput{
UpdatedItem: input.Item,
AdditionalItems: []velero.ResourceIdentifier{pv},
}, nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/restore/add_pv_from_pvc_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/vmware-tanzu/velero/pkg/kuberesource"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1"
velerotest "github.com/vmware-tanzu/velero/pkg/test"
)

Expand Down Expand Up @@ -90,7 +89,7 @@ func TestAddPVFromPVCActionExecute(t *testing.T) {

action := &AddPVFromPVCAction{logger: velerotest.NewLogger()}

input := &riav1.RestoreItemActionExecuteInput{
input := &velero.RestoreItemActionExecuteInput{
Item: &unstructured.Unstructured{Object: itemData},
ItemFromBackup: &unstructured.Unstructured{Object: itemFromBackupData},
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/restore/add_pvc_from_pod_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/vmware-tanzu/velero/pkg/kuberesource"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1"
)

type AddPVCFromPodAction struct {
Expand All @@ -41,7 +40,7 @@ func (a *AddPVCFromPodAction) AppliesTo() (velero.ResourceSelector, error) {
}, nil
}

func (a *AddPVCFromPodAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) {
func (a *AddPVCFromPodAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) {
a.logger.Info("Executing AddPVCFromPodAction")

var pod corev1api.Pod
Expand All @@ -64,7 +63,7 @@ func (a *AddPVCFromPodAction) Execute(input *riav1.RestoreItemActionExecuteInput
})
}

return &riav1.RestoreItemActionExecuteOutput{
return &velero.RestoreItemActionExecuteOutput{
UpdatedItem: input.Item,
AdditionalItems: additionalItems,
}, nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/restore/add_pvc_from_pod_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

"github.com/vmware-tanzu/velero/pkg/kuberesource"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1"
velerotest "github.com/vmware-tanzu/velero/pkg/test"
)

Expand Down Expand Up @@ -101,7 +100,7 @@ func TestAddPVCFromPodActionExecute(t *testing.T) {

action := &AddPVCFromPodAction{logger: velerotest.NewLogger()}

input := &riav1.RestoreItemActionExecuteInput{
input := &velero.RestoreItemActionExecuteInput{
Item: &unstructured.Unstructured{Object: itemData},
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/restore/admissionwebhook_config_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"

"github.com/vmware-tanzu/velero/pkg/plugin/velero"
riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1"
)

// AdmissionWebhookConfigurationAction is a RestoreItemAction plugin applicable to mutatingwebhookconfiguration and
Expand All @@ -47,7 +46,7 @@ func (a *AdmissionWebhookConfigurationAction) AppliesTo() (velero.ResourceSelect

// Execute will reset the value of "sideEffects" attribute of each item in the "webhooks" list to "None" if they are invalid values for
// v1, such as "Unknown" or "Some"
func (a *AdmissionWebhookConfigurationAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) {
func (a *AdmissionWebhookConfigurationAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) {
a.logger.Info("Executing ChangeStorageClassAction")
defer a.logger.Info("Done executing ChangeStorageClassAction")

Expand All @@ -60,15 +59,15 @@ func (a *AdmissionWebhookConfigurationAction) Execute(input *riav1.RestoreItemAc
logger := a.logger.WithField("resource_name", name)
if apiVersion != "admissionregistration.k8s.io/v1" {
logger.Infof("unable to handle api version: %s, skip", apiVersion)
return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil
return velero.NewRestoreItemActionExecuteOutput(input.Item), nil
}
webhooks, ok, err := unstructured.NestedSlice(item.UnstructuredContent(), "webhooks")
if err != nil {
return nil, errors.Wrap(err, "failed to get webhooks slice from input item")
}
if !ok {
logger.Info("webhooks is not set, skip")
return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil
return velero.NewRestoreItemActionExecuteOutput(input.Item), nil
}
newWebhooks := make([]interface{}, 0)
for i, entry := range webhooks {
Expand All @@ -86,5 +85,5 @@ func (a *AdmissionWebhookConfigurationAction) Execute(input *riav1.RestoreItemAc
newWebhooks = append(newWebhooks, obj)
}
item.UnstructuredContent()["webhooks"] = newWebhooks
return riav1.NewRestoreItemActionExecuteOutput(item), nil
return velero.NewRestoreItemActionExecuteOutput(item), nil
}
4 changes: 2 additions & 2 deletions pkg/restore/admissionwebhook_config_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"

riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
velerotest "github.com/vmware-tanzu/velero/pkg/test"
)

Expand Down Expand Up @@ -163,7 +163,7 @@ func TestNewAdmissionWebhookConfigurationActionExecute(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
o := map[string]interface{}{}
json.Unmarshal([]byte(tt.itemJSON), &o)
input := &riav1.RestoreItemActionExecuteInput{
input := &velero.RestoreItemActionExecuteInput{
Item: &unstructured.Unstructured{
Object: o,
},
Expand Down
5 changes: 2 additions & 3 deletions pkg/restore/apiservice_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"k8s.io/kube-aggregator/pkg/controllers/autoregister"

"github.com/vmware-tanzu/velero/pkg/plugin/velero"
riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1"
)

type APIServiceAction struct {
Expand All @@ -43,10 +42,10 @@ func (a *APIServiceAction) AppliesTo() (velero.ResourceSelector, error) {
}, nil
}

func (a *APIServiceAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) {
func (a *APIServiceAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) {
a.logger.Info("Executing APIServiceAction")
defer a.logger.Info("Done executing APIServiceAction")

a.logger.Infof("Skipping restore of APIService as it is managed by Kubernetes")
return riav1.NewRestoreItemActionExecuteOutput(input.Item).WithoutRestore(), nil
return velero.NewRestoreItemActionExecuteOutput(input.Item).WithoutRestore(), nil
}
Loading

0 comments on commit 45de8a7

Please sign in to comment.