diff --git a/.gitignore b/.gitignore index 18482277e2..a741e968b8 100644 --- a/.gitignore +++ b/.gitignore @@ -46,7 +46,7 @@ _tiltbuild tilt-resources/tilt-settings.json tilt-resources/velero_v1_backupstoragelocation.yaml tilt-resources/deployment.yaml -tilt-resources/restic.yaml +tilt-resources/node-agent.yaml tilt-resources/cloud test/e2e/report.xml diff --git a/MAINTAINERS.md b/MAINTAINERS.md index f62eb0f94f..7dc98011ac 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -30,9 +30,10 @@ | Feature Area | Lead | | ----------------------------- | :---------------------: | -| Architect | Dave Smith-Uchida (dsu-igeek) | -| Technical Lead | Daniel Jiang (reasonerjt) | +| Architect | Dave Smith-Uchida [dsu-igeek](https://github.com/dsu-igeek) | +| Technical Lead | Daniel Jiang [reasonerjt](https://github.com/reasonerjt) | | Kubernetes CSI Liaison | | | Deployment | | -| Community Management | Orlin Vasilev (OrlinVasilev) | -| Product Management | Eleanor Millman (eleanor-millman) | +| Community Management | Orlin Vasilev [OrlinVasilev](https://github.com/OrlinVasilev) | +| Product Management | Pradeep Kumar Chaturvedi [pradeepkchaturvedi](https://github.com/pradeepkchaturvedi) | + diff --git a/Tiltfile b/Tiltfile index 0d9a642632..2a7d97eb41 100644 --- a/Tiltfile +++ b/Tiltfile @@ -17,7 +17,7 @@ k8s_yaml([ # default values settings = { "default_registry": "docker.io/velero", - "enable_restic": False, + "use_node_agent": False, "enable_debug": False, "debug_continue_on_start": True, # Continue the velero process by default when in debug mode "create_backup_locations": False, @@ -34,9 +34,9 @@ k8s_yaml(kustomize('tilt-resources')) k8s_yaml('tilt-resources/deployment.yaml') if settings.get("enable_debug"): k8s_resource('velero', port_forwards = '2345') - # TODO: Need to figure out how to apply port forwards for all restic pods -if settings.get("enable_restic"): - k8s_yaml('tilt-resources/restic.yaml') + # TODO: Need to figure out how to apply port forwards for all node-agent pods +if settings.get("use_node_agent"): + k8s_yaml('tilt-resources/node-agent.yaml') if settings.get("create_backup_locations"): k8s_yaml('tilt-resources/velero_v1_backupstoragelocation.yaml') if settings.get("setup-minio"): diff --git a/changelogs/unreleased/5390-lyndon b/changelogs/unreleased/5390-lyndon new file mode 100644 index 0000000000..091b074c7b --- /dev/null +++ b/changelogs/unreleased/5390-lyndon @@ -0,0 +1 @@ +Rename Velero daemonset from "restic" to "node-agent" \ No newline at end of file diff --git a/changelogs/unreleased/5429-reasonerjt b/changelogs/unreleased/5429-reasonerjt new file mode 100644 index 0000000000..2fdd8fe8d8 --- /dev/null +++ b/changelogs/unreleased/5429-reasonerjt @@ -0,0 +1 @@ +Skip the exclusion check for additional resources returned by BIA \ No newline at end of file diff --git a/changelogs/unreleased/5441-sseago b/changelogs/unreleased/5441-sseago new file mode 100644 index 0000000000..fd8f7b7d21 --- /dev/null +++ b/changelogs/unreleased/5441-sseago @@ -0,0 +1 @@ +moved RIA execute input/output structs back to velero package diff --git a/design/CLI/PoC/overlays/plugins/restic.yaml b/design/CLI/PoC/overlays/plugins/node-agent.yaml similarity index 93% rename from design/CLI/PoC/overlays/plugins/restic.yaml rename to design/CLI/PoC/overlays/plugins/node-agent.yaml index 576ea2ff50..dbb4ce18db 100644 --- a/design/CLI/PoC/overlays/plugins/restic.yaml +++ b/design/CLI/PoC/overlays/plugins/node-agent.yaml @@ -5,22 +5,22 @@ metadata: creationTimestamp: null labels: component: velero - name: restic + name: node-agent namespace: velero spec: selector: matchLabels: - name: restic + name: node-agent template: metadata: creationTimestamp: null labels: component: velero - name: restic + name: node-agent spec: containers: - args: - - restic + - node-agent - server command: - /velero @@ -43,7 +43,7 @@ spec: value: /credentials/cloud image: velero/velero:latest imagePullPolicy: Always - name: restic + name: node-agent resources: {} volumeMounts: - mountPath: /host_pods diff --git a/pkg/backup/backup.go b/pkg/backup/backup.go index 0b00417fdd..ba20ed0d4a 100644 --- a/pkg/backup/backup.go +++ b/pkg/backup/backup.go @@ -416,7 +416,7 @@ func (kb *kubernetesBackupper) BackupWithResolvers(log logrus.FieldLogger, } func (kb *kubernetesBackupper) backupItem(log logrus.FieldLogger, gr schema.GroupResource, itemBackupper *itemBackupper, unstructured *unstructured.Unstructured, preferredGVR schema.GroupVersionResource) bool { - backedUpItem, err := itemBackupper.backupItem(log, unstructured, gr, preferredGVR) + backedUpItem, err := itemBackupper.backupItem(log, unstructured, gr, preferredGVR, false) if aggregate, ok := err.(kubeerrs.Aggregate); ok { log.WithField("name", unstructured.GetName()).Infof("%d errors encountered backup up item", len(aggregate.Errors())) // log each error separately so we get error location info in the log, and an diff --git a/pkg/backup/item_backupper.go b/pkg/backup/item_backupper.go index 879f4d70c5..0e24fb32cf 100644 --- a/pkg/backup/item_backupper.go +++ b/pkg/backup/item_backupper.go @@ -24,6 +24,8 @@ import ( "strings" "time" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "github.com/pkg/errors" "github.com/sirupsen/logrus" corev1api "k8s.io/api/core/v1" @@ -47,6 +49,11 @@ import ( "github.com/vmware-tanzu/velero/pkg/volume" ) +const ( + mustIncludeAdditionalItemAnnotation = "backup.velero.io/must-include-additional-items" + excludeFromBackupLabel = "velero.io/exclude-from-backup" +) + // itemBackupper can back up individual items to a tar writer. type itemBackupper struct { backupRequest *Request @@ -61,16 +68,11 @@ type itemBackupper struct { snapshotLocationVolumeSnapshotters map[string]vsv1.VolumeSnapshotter } -const ( - // veleroExcludeFromBackupLabel labeled item should be exclude by velero in backup job. - veleroExcludeFromBackupLabel = "velero.io/exclude-from-backup" -) - // backupItem backs up an individual item to tarWriter. The item may be excluded based on the // namespaces IncludesExcludes list. // In addition to the error return, backupItem also returns a bool indicating whether the item // was actually backed up. -func (ib *itemBackupper) backupItem(logger logrus.FieldLogger, obj runtime.Unstructured, groupResource schema.GroupResource, preferredGVR schema.GroupVersionResource) (bool, error) { +func (ib *itemBackupper) backupItem(logger logrus.FieldLogger, obj runtime.Unstructured, groupResource schema.GroupResource, preferredGVR schema.GroupVersionResource, mustInclude bool) (bool, error) { metadata, err := meta.Accessor(obj) if err != nil { return false, err @@ -83,28 +85,30 @@ func (ib *itemBackupper) backupItem(logger logrus.FieldLogger, obj runtime.Unstr log = log.WithField("resource", groupResource.String()) log = log.WithField("namespace", namespace) - if metadata.GetLabels()[veleroExcludeFromBackupLabel] == "true" { - log.Infof("Excluding item because it has label %s=true", veleroExcludeFromBackupLabel) - return false, nil - } - - // NOTE: we have to re-check namespace & resource includes/excludes because it's possible that - // backupItem can be invoked by a custom action. - if namespace != "" && !ib.backupRequest.NamespaceIncludesExcludes.ShouldInclude(namespace) { - log.Info("Excluding item because namespace is excluded") - return false, nil - } - - // NOTE: we specifically allow namespaces to be backed up even if IncludeClusterResources is - // false. - if namespace == "" && groupResource != kuberesource.Namespaces && ib.backupRequest.Spec.IncludeClusterResources != nil && !*ib.backupRequest.Spec.IncludeClusterResources { - log.Info("Excluding item because resource is cluster-scoped and backup.spec.includeClusterResources is false") - return false, nil - } + if mustInclude { + log.Infof("Skipping the exclusion checks for this resource") + } else { + if metadata.GetLabels()[excludeFromBackupLabel] == "true" { + log.Infof("Excluding item because it has label %s=true", excludeFromBackupLabel) + return false, nil + } + // NOTE: we have to re-check namespace & resource includes/excludes because it's possible that + // backupItem can be invoked by a custom action. + if namespace != "" && !ib.backupRequest.NamespaceIncludesExcludes.ShouldInclude(namespace) { + log.Info("Excluding item because namespace is excluded") + return false, nil + } + // NOTE: we specifically allow namespaces to be backed up even if IncludeClusterResources is + // false. + if namespace == "" && groupResource != kuberesource.Namespaces && ib.backupRequest.Spec.IncludeClusterResources != nil && !*ib.backupRequest.Spec.IncludeClusterResources { + log.Info("Excluding item because resource is cluster-scoped and backup.spec.includeClusterResources is false") + return false, nil + } - if !ib.backupRequest.ResourceIncludesExcludes.ShouldInclude(groupResource.String()) { - log.Info("Excluding item because resource is excluded") - return false, nil + if !ib.backupRequest.ResourceIncludesExcludes.ShouldInclude(groupResource.String()) { + log.Info("Excluding item because resource is excluded") + return false, nil + } } if metadata.GetDeletionTimestamp() != nil { @@ -320,7 +324,8 @@ func (ib *itemBackupper) executeActions( if err != nil { return nil, errors.Wrapf(err, "error executing custom action (groupResource=%s, namespace=%s, name=%s)", groupResource.String(), namespace, name) } - obj = updatedItem + u := &unstructured.Unstructured{Object: updatedItem.UnstructuredContent()} + mustInclude := u.GetAnnotations()[mustIncludeAdditionalItemAnnotation] == "true" for _, additionalItem := range additionalItemIdentifiers { gvr, resource, err := ib.discoveryHelper.ResourceFor(additionalItem.GroupResource.WithVersion("")) @@ -334,6 +339,7 @@ func (ib *itemBackupper) executeActions( } item, err := client.Get(additionalItem.Name, metav1.GetOptions{}) + if apierrors.IsNotFound(err) { log.WithFields(logrus.Fields{ "groupResource": additionalItem.GroupResource, @@ -346,12 +352,17 @@ func (ib *itemBackupper) executeActions( return nil, errors.WithStack(err) } - if _, err = ib.backupItem(log, item, gvr.GroupResource(), gvr); err != nil { + if _, err = ib.backupItem(log, item, gvr.GroupResource(), gvr, mustInclude); err != nil { return nil, err } } + // remove the annotation as it's for communication between BIA and velero server, + // we don't want the resource be restored with this annotation. + if _, ok := u.GetAnnotations()[mustIncludeAdditionalItemAnnotation]; ok { + delete(u.GetAnnotations(), mustIncludeAdditionalItemAnnotation) + } + obj = u } - return obj, nil } diff --git a/pkg/cmd/cli/debug/debug.go b/pkg/cmd/cli/debug/debug.go index e324f26312..fba0a1af35 100644 --- a/pkg/cmd/cli/debug/debug.go +++ b/pkg/cmd/cli/debug/debug.go @@ -152,7 +152,7 @@ func NewCommand(f client.Factory) *cobra.Command { c := &cobra.Command{ Use: "debug", Short: "Generate debug bundle", - Long: `Generate a tarball containing the logs of velero deployment, plugin logs, restic DaemonSet, + Long: `Generate a tarball containing the logs of velero deployment, plugin logs, node-agent DaemonSet, specs of resources created by velero server, and optionally the logs of backup and restore.`, Run: func(c *cobra.Command, args []string) { flags := c.Flags() diff --git a/pkg/cmd/cli/install/install.go b/pkg/cmd/cli/install/install.go index fe4bebea30..f9cffa48fb 100644 --- a/pkg/cmd/cli/install/install.go +++ b/pkg/cmd/cli/install/install.go @@ -55,17 +55,17 @@ type InstallOptions struct { VeleroPodMemRequest string VeleroPodCPULimit string VeleroPodMemLimit string - ResticPodCPURequest string - ResticPodMemRequest string - ResticPodCPULimit string - ResticPodMemLimit string + NodeAgentPodCPURequest string + NodeAgentPodMemRequest string + NodeAgentPodCPULimit string + NodeAgentPodMemLimit string RestoreOnly bool SecretFile string NoSecret bool DryRun bool BackupStorageConfig flag.Map VolumeSnapshotConfig flag.Map - UseRestic bool + UseNodeAgent bool Wait bool UseVolumeSnapshots bool DefaultRepoMaintenanceFrequency time.Duration @@ -95,23 +95,23 @@ func (o *InstallOptions) BindFlags(flags *pflag.FlagSet) { flags.StringVar(&o.VeleroPodMemRequest, "velero-pod-mem-request", o.VeleroPodMemRequest, `Memory request for Velero pod. A value of "0" is treated as unbounded. Optional.`) flags.StringVar(&o.VeleroPodCPULimit, "velero-pod-cpu-limit", o.VeleroPodCPULimit, `CPU limit for Velero pod. A value of "0" is treated as unbounded. Optional.`) flags.StringVar(&o.VeleroPodMemLimit, "velero-pod-mem-limit", o.VeleroPodMemLimit, `Memory limit for Velero pod. A value of "0" is treated as unbounded. Optional.`) - flags.StringVar(&o.ResticPodCPURequest, "restic-pod-cpu-request", o.ResticPodCPURequest, `CPU request for restic pod. A value of "0" is treated as unbounded. Optional.`) - flags.StringVar(&o.ResticPodMemRequest, "restic-pod-mem-request", o.ResticPodMemRequest, `Memory request for restic pod. A value of "0" is treated as unbounded. Optional.`) - flags.StringVar(&o.ResticPodCPULimit, "restic-pod-cpu-limit", o.ResticPodCPULimit, `CPU limit for restic pod. A value of "0" is treated as unbounded. Optional.`) - flags.StringVar(&o.ResticPodMemLimit, "restic-pod-mem-limit", o.ResticPodMemLimit, `Memory limit for restic pod. A value of "0" is treated as unbounded. Optional.`) + flags.StringVar(&o.NodeAgentPodCPURequest, "node-agent-pod-cpu-request", o.NodeAgentPodCPURequest, `CPU request for node-agent pod. A value of "0" is treated as unbounded. Optional.`) + flags.StringVar(&o.NodeAgentPodMemRequest, "node-agent-pod-mem-request", o.NodeAgentPodMemRequest, `Memory request for node-agent pod. A value of "0" is treated as unbounded. Optional.`) + flags.StringVar(&o.NodeAgentPodCPULimit, "node-agent-pod-cpu-limit", o.NodeAgentPodCPULimit, `CPU limit for node-agent pod. A value of "0" is treated as unbounded. Optional.`) + flags.StringVar(&o.NodeAgentPodMemLimit, "node-agent-pod-mem-limit", o.NodeAgentPodMemLimit, `Memory limit for node-agent pod. A value of "0" is treated as unbounded. Optional.`) flags.Var(&o.BackupStorageConfig, "backup-location-config", "Configuration to use for the backup storage location. Format is key1=value1,key2=value2") flags.Var(&o.VolumeSnapshotConfig, "snapshot-location-config", "Configuration to use for the volume snapshot location. Format is key1=value1,key2=value2") flags.BoolVar(&o.UseVolumeSnapshots, "use-volume-snapshots", o.UseVolumeSnapshots, "Whether or not to create snapshot location automatically. Set to false if you do not plan to create volume snapshots via a storage provider.") flags.BoolVar(&o.RestoreOnly, "restore-only", o.RestoreOnly, "Run the server in restore-only mode. Optional.") flags.BoolVar(&o.DryRun, "dry-run", o.DryRun, "Generate resources, but don't send them to the cluster. Use with -o. Optional.") - flags.BoolVar(&o.UseRestic, "use-restic", o.UseRestic, "Create restic daemonset. Optional.") + flags.BoolVar(&o.UseNodeAgent, "use-node-agent", o.UseNodeAgent, "Create Velero node-agent daemonset. Optional. Velero node-agent hosts Velero modules that need to run in one or more nodes(i.e. Restic, Kopia).") flags.BoolVar(&o.Wait, "wait", o.Wait, "Wait for Velero deployment to be ready. Optional.") flags.DurationVar(&o.DefaultRepoMaintenanceFrequency, "default-repo-maintain-frequency", o.DefaultRepoMaintenanceFrequency, "How often 'maintain' is run for backup repositories by default. Optional.") flags.DurationVar(&o.GarbageCollectionFrequency, "garbage-collection-frequency", o.GarbageCollectionFrequency, "How often the garbage collection runs for expired backups.(default 1h)") flags.Var(&o.Plugins, "plugins", "Plugin container images to install into the Velero Deployment") flags.BoolVar(&o.CRDsOnly, "crds-only", o.CRDsOnly, "Only generate CustomResourceDefinition resources. Useful for updating CRDs for an existing Velero install.") flags.StringVar(&o.CACertFile, "cacert", o.CACertFile, "File containing a certificate bundle to use when verifying TLS connections to the object store. Optional.") - flags.StringVar(&o.Features, "features", o.Features, "Comma separated list of Velero feature flags to be set on the Velero deployment and the restic daemonset, if restic is enabled") + flags.StringVar(&o.Features, "features", o.Features, "Comma separated list of Velero feature flags to be set on the Velero deployment and the node-agent daemonset, if node-agent is enabled") flags.BoolVar(&o.DefaultVolumesToFsBackup, "default-volumes-to-fs-backup", o.DefaultVolumesToFsBackup, "Bool flag to configure Velero server to use pod volume file system backup by default for all volumes on all backups. Optional.") flags.StringVar(&o.UploaderType, "uploader-type", o.UploaderType, fmt.Sprintf("The type of uploader to transfer the data of pod volumes, the supported values are '%s', '%s'", uploader.ResticType, uploader.KopiaType)) } @@ -130,10 +130,10 @@ func NewInstallOptions() *InstallOptions { VeleroPodMemRequest: install.DefaultVeleroPodMemRequest, VeleroPodCPULimit: install.DefaultVeleroPodCPULimit, VeleroPodMemLimit: install.DefaultVeleroPodMemLimit, - ResticPodCPURequest: install.DefaultResticPodCPURequest, - ResticPodMemRequest: install.DefaultResticPodMemRequest, - ResticPodCPULimit: install.DefaultResticPodCPULimit, - ResticPodMemLimit: install.DefaultResticPodMemLimit, + NodeAgentPodCPURequest: install.DefaultNodeAgentPodCPURequest, + NodeAgentPodMemRequest: install.DefaultNodeAgentPodMemRequest, + NodeAgentPodCPULimit: install.DefaultNodeAgentPodCPULimit, + NodeAgentPodMemLimit: install.DefaultNodeAgentPodMemLimit, // Default to creating a VSL unless we're told otherwise UseVolumeSnapshots: true, NoDefaultBackupLocation: false, @@ -171,7 +171,7 @@ func (o *InstallOptions) AsVeleroOptions() (*install.VeleroOptions, error) { if err != nil { return nil, err } - resticPodResources, err := kubeutil.ParseResourceRequirements(o.ResticPodCPURequest, o.ResticPodMemRequest, o.ResticPodCPULimit, o.ResticPodMemLimit) + nodeAgentPodResources, err := kubeutil.ParseResourceRequirements(o.NodeAgentPodCPURequest, o.NodeAgentPodMemRequest, o.NodeAgentPodCPULimit, o.NodeAgentPodMemLimit) if err != nil { return nil, err } @@ -186,10 +186,10 @@ func (o *InstallOptions) AsVeleroOptions() (*install.VeleroOptions, error) { PodLabels: o.PodLabels.Data(), ServiceAccountAnnotations: o.ServiceAccountAnnotations.Data(), VeleroPodResources: veleroPodResources, - ResticPodResources: resticPodResources, + NodeAgentPodResources: nodeAgentPodResources, SecretData: secretData, RestoreOnly: o.RestoreOnly, - UseRestic: o.UseRestic, + UseNodeAgent: o.UseNodeAgent, UseVolumeSnapshots: o.UseVolumeSnapshots, BSLConfig: o.BackupStorageConfig.Data(), VSLConfig: o.VolumeSnapshotConfig.Data(), @@ -216,7 +216,7 @@ A prefix within the bucket and configuration for the backup store location may a Additionally, volume snapshot information for the same provider may be supplied. All required CustomResourceDefinitions will be installed to the server, as well as the -Velero Deployment and associated Restic DaemonSet. +Velero Deployment and associated node-agent DaemonSet. The provided secret data will be created in a Secret named 'cloud-credentials'. @@ -302,8 +302,8 @@ func (o *InstallOptions) Run(c *cobra.Command, f client.Factory) error { return errors.Wrap(err, errorMsg) } - if o.UseRestic { - fmt.Println("Waiting for Velero restic daemonset to be ready.") + if o.UseNodeAgent { + fmt.Println("Waiting for node-agent daemonset to be ready.") if _, err = install.DaemonSetIsReady(dynamicFactory, o.Namespace); err != nil { return errors.Wrap(err, errorMsg) } @@ -393,8 +393,8 @@ func (o *InstallOptions) Validate(c *cobra.Command, args []string, f client.Fact } } - if o.DefaultVolumesToFsBackup && !o.UseRestic { - return errors.New("--use-restic is required when using --default-volumes-to-fs-backup") + if o.DefaultVolumesToFsBackup && !o.UseNodeAgent { + return errors.New("--use-node-agent is required when using --default-volumes-to-fs-backup") } switch { diff --git a/pkg/cmd/cli/nodeagent/node_agent.go b/pkg/cmd/cli/nodeagent/node_agent.go new file mode 100644 index 0000000000..7b0b6ebf0b --- /dev/null +++ b/pkg/cmd/cli/nodeagent/node_agent.go @@ -0,0 +1,37 @@ +/* +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 nodeagent + +import ( + "github.com/spf13/cobra" + + "github.com/vmware-tanzu/velero/pkg/client" +) + +func NewCommand(f client.Factory) *cobra.Command { + c := &cobra.Command{ + Use: "node-agent", + Short: "Work with node-agent", + Long: "Work with node-agent", + } + + c.AddCommand( + NewServerCommand(f), + ) + + return c +} diff --git a/pkg/cmd/cli/restic/server.go b/pkg/cmd/cli/nodeagent/server.go similarity index 98% rename from pkg/cmd/cli/restic/server.go rename to pkg/cmd/cli/nodeagent/server.go index e7b133ac69..fed76d1fa8 100644 --- a/pkg/cmd/cli/restic/server.go +++ b/pkg/cmd/cli/nodeagent/server.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package restic +package nodeagent import ( "context" @@ -74,15 +74,15 @@ func NewServerCommand(f client.Factory) *cobra.Command { command := &cobra.Command{ Use: "server", - Short: "Run the velero restic server", - Long: "Run the velero restic server", + Short: "Run the velero node-agent server", + Long: "Run the velero node-agent server", Hidden: true, Run: func(c *cobra.Command, args []string) { logLevel := logLevelFlag.Parse() logrus.Infof("Setting log-level to %s", strings.ToUpper(logLevel.String())) logger := logging.DefaultLogger(logLevel, formatFlag.Parse()) - logger.Infof("Starting Velero restic server %s (%s)", buildinfo.Version, buildinfo.FormattedGitSHA()) + logger.Infof("Starting Velero node-agent server %s (%s)", buildinfo.Version, buildinfo.FormattedGitSHA()) f.SetBasename(fmt.Sprintf("%s-%s", c.Parent().Name(), c.Name())) s, err := newResticServer(logger, f, defaultMetricsAddress) diff --git a/pkg/cmd/cli/restic/server_test.go b/pkg/cmd/cli/nodeagent/server_test.go similarity index 99% rename from pkg/cmd/cli/restic/server_test.go rename to pkg/cmd/cli/nodeagent/server_test.go index ff222e996f..469d5b8005 100644 --- a/pkg/cmd/cli/restic/server_test.go +++ b/pkg/cmd/cli/nodeagent/server_test.go @@ -13,7 +13,7 @@ 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 restic +package nodeagent import ( "context" diff --git a/pkg/cmd/cli/restic/restic.go b/pkg/cmd/cli/restic/restic.go index 39909c23c5..744cdbd5fa 100644 --- a/pkg/cmd/cli/restic/restic.go +++ b/pkg/cmd/cli/restic/restic.go @@ -32,7 +32,6 @@ func NewCommand(f client.Factory) *cobra.Command { c.AddCommand( repo.NewRepositoryCommand(f), - NewServerCommand(f), ) return c diff --git a/pkg/cmd/velero/velero.go b/pkg/cmd/velero/velero.go index fe712adc02..6338299c37 100644 --- a/pkg/cmd/velero/velero.go +++ b/pkg/cmd/velero/velero.go @@ -49,6 +49,8 @@ import ( runplugin "github.com/vmware-tanzu/velero/pkg/cmd/server/plugin" veleroflag "github.com/vmware-tanzu/velero/pkg/cmd/util/flag" "github.com/vmware-tanzu/velero/pkg/features" + + "github.com/vmware-tanzu/velero/pkg/cmd/cli/nodeagent" ) func NewCommand(name string) *cobra.Command { @@ -103,6 +105,7 @@ operations can also be performed as 'velero backup get' and 'velero schedule cre schedule.NewCommand(f), restore.NewCommand(f), server.NewCommand(f), + nodeagent.NewCommand(f), version.NewCommand(f), get.NewCommand(f), install.NewCommand(f), diff --git a/pkg/install/daemonset.go b/pkg/install/daemonset.go index fb88647632..7aca8c66db 100644 --- a/pkg/install/daemonset.go +++ b/pkg/install/daemonset.go @@ -43,19 +43,19 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet { } - resticArgs := []string{ - "restic", + daemonSetArgs := []string{ + "node-agent", "server", } if len(c.features) > 0 { - resticArgs = append(resticArgs, fmt.Sprintf("--features=%s", strings.Join(c.features, ","))) + daemonSetArgs = append(daemonSetArgs, fmt.Sprintf("--features=%s", strings.Join(c.features, ","))) } userID := int64(0) mountPropagationMode := corev1.MountPropagationHostToContainer daemonSet := &appsv1.DaemonSet{ - ObjectMeta: objectMeta(namespace, "restic"), + ObjectMeta: objectMeta(namespace, "node-agent"), TypeMeta: metav1.TypeMeta{ Kind: "DaemonSet", APIVersion: appsv1.SchemeGroupVersion.String(), @@ -63,13 +63,13 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet { Spec: appsv1.DaemonSetSpec{ Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ - "name": "restic", + "name": "node-agent", }, }, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: podLabels(c.labels, map[string]string{ - "name": "restic", + "name": "node-agent", }), Annotations: c.annotations, }, @@ -96,13 +96,13 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet { }, Containers: []corev1.Container{ { - Name: "restic", + Name: "node-agent", Image: c.image, ImagePullPolicy: pullPolicy, Command: []string{ "/velero", }, - Args: resticArgs, + Args: daemonSetArgs, VolumeMounts: []corev1.VolumeMount{ { diff --git a/pkg/install/daemonset_test.go b/pkg/install/daemonset_test.go index db9976fe56..4a3d9f9aa6 100644 --- a/pkg/install/daemonset_test.go +++ b/pkg/install/daemonset_test.go @@ -26,7 +26,7 @@ import ( func TestDaemonSet(t *testing.T) { ds := DaemonSet("velero") - assert.Equal(t, "restic", ds.Spec.Template.Spec.Containers[0].Name) + assert.Equal(t, "node-agent", ds.Spec.Template.Spec.Containers[0].Name) assert.Equal(t, "velero", ds.ObjectMeta.Namespace) ds = DaemonSet("velero", WithImage("velero/velero:v0.11")) diff --git a/pkg/install/install.go b/pkg/install/install.go index e163be95ef..d378716ed5 100644 --- a/pkg/install/install.go +++ b/pkg/install/install.go @@ -207,7 +207,7 @@ func DeploymentIsReady(factory client.DynamicFactory, namespace string) (bool, e return isReady, err } -// DaemonSetIsReady will poll the kubernetes API server to ensure the restic daemonset is ready, i.e. that +// DaemonSetIsReady will poll the kubernetes API server to ensure the node-agent daemonset is ready, i.e. that // pods are scheduled and available on all of the desired nodes. func DaemonSetIsReady(factory client.DynamicFactory, namespace string) (bool, error) { gvk := schema.FromAPIVersionAndKind(appsv1.SchemeGroupVersion.String(), "DaemonSet") @@ -226,7 +226,7 @@ func DaemonSetIsReady(factory client.DynamicFactory, namespace string) (bool, er var readyObservations int32 err = wait.PollImmediate(time.Second, time.Minute, func() (bool, error) { - unstructuredDaemonSet, err := c.Get("restic", metav1.GetOptions{}) + unstructuredDaemonSet, err := c.Get("node-agent", metav1.GetOptions{}) if apierrors.IsNotFound(err) { return false, nil } else if err != nil { diff --git a/pkg/install/resources.go b/pkg/install/resources.go index aa9b5f237e..ddcce46684 100644 --- a/pkg/install/resources.go +++ b/pkg/install/resources.go @@ -31,15 +31,15 @@ import ( ) var ( - DefaultVeleroPodCPURequest = "500m" - DefaultVeleroPodMemRequest = "128Mi" - DefaultVeleroPodCPULimit = "1000m" - DefaultVeleroPodMemLimit = "512Mi" - DefaultResticPodCPURequest = "500m" - DefaultResticPodMemRequest = "512Mi" - DefaultResticPodCPULimit = "1000m" - DefaultResticPodMemLimit = "1Gi" - DefaultVeleroNamespace = "velero" + DefaultVeleroPodCPURequest = "500m" + DefaultVeleroPodMemRequest = "128Mi" + DefaultVeleroPodCPULimit = "1000m" + DefaultVeleroPodMemLimit = "512Mi" + DefaultNodeAgentPodCPURequest = "500m" + DefaultNodeAgentPodMemRequest = "512Mi" + DefaultNodeAgentPodCPULimit = "1000m" + DefaultNodeAgentPodMemLimit = "1Gi" + DefaultVeleroNamespace = "velero" ) func Labels() map[string]string { @@ -218,10 +218,10 @@ type VeleroOptions struct { PodLabels map[string]string ServiceAccountAnnotations map[string]string VeleroPodResources corev1.ResourceRequirements - ResticPodResources corev1.ResourceRequirements + NodeAgentPodResources corev1.ResourceRequirements SecretData []byte RestoreOnly bool - UseRestic bool + UseNodeAgent bool UseVolumeSnapshots bool BSLConfig map[string]string VSLConfig map[string]string @@ -311,12 +311,12 @@ func AllResources(o *VeleroOptions) *unstructured.UnstructuredList { appendUnstructured(resources, deploy) - if o.UseRestic { + if o.UseNodeAgent { dsOpts := []podTemplateOption{ WithAnnotations(o.PodAnnotations), WithLabels(o.PodLabels), WithImage(o.Image), - WithResources(o.ResticPodResources), + WithResources(o.NodeAgentPodResources), WithSecret(secretPresent), } if len(o.Features) > 0 { diff --git a/pkg/nodeagent/node_agent.go b/pkg/nodeagent/node_agent.go index fcfd10931f..cf1d32fbb5 100644 --- a/pkg/nodeagent/node_agent.go +++ b/pkg/nodeagent/node_agent.go @@ -32,7 +32,7 @@ import ( const ( // daemonSet is the name of the Velero node agent daemonset. - daemonSet = "restic" + daemonSet = "node-agent" ) var ( diff --git a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action.go b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action.go index a6b595544d..28b319eca1 100644 --- a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action.go +++ b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action.go @@ -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 diff --git a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go index 55a0db2781..d16e3bb1fe 100644 --- a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go +++ b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go @@ -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) { @@ -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", diff --git a/pkg/plugin/framework/restore_item_action_client.go b/pkg/plugin/framework/restore_item_action_client.go index 35bafa0893..75490d4c2f 100644 --- a/pkg/plugin/framework/restore_item_action_client.go +++ b/pkg/plugin/framework/restore_item_action_client.go @@ -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) @@ -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, diff --git a/pkg/plugin/framework/restore_item_action_server.go b/pkg/plugin/framework/restore_item_action_server.go index 924929c975..bdc149c480 100644 --- a/pkg/plugin/framework/restore_item_action_server.go +++ b/pkg/plugin/framework/restore_item_action_server.go @@ -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, diff --git a/pkg/plugin/velero/mocks/restoreitemaction/v1/RestoreItemAction.go b/pkg/plugin/velero/mocks/restoreitemaction/v1/RestoreItemAction.go index 5bf33ed851..1bacf7b161 100644 --- a/pkg/plugin/velero/mocks/restoreitemaction/v1/RestoreItemAction.go +++ b/pkg/plugin/velero/mocks/restoreitemaction/v1/RestoreItemAction.go @@ -20,7 +20,6 @@ package v1 import ( mock "github.com/stretchr/testify/mock" velero "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) // RestoreItemAction is an autogenerated mock type for the RestoreItemAction type @@ -50,20 +49,20 @@ func (_m *RestoreItemAction) AppliesTo() (velero.ResourceSelector, error) { } // Execute provides a mock function with given fields: input -func (_m *RestoreItemAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (_m *RestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { ret := _m.Called(input) - var r0 *riav1.RestoreItemActionExecuteOutput - if rf, ok := ret.Get(0).(func(*riav1.RestoreItemActionExecuteInput) *riav1.RestoreItemActionExecuteOutput); ok { + var r0 *velero.RestoreItemActionExecuteOutput + if rf, ok := ret.Get(0).(func(*velero.RestoreItemActionExecuteInput) *velero.RestoreItemActionExecuteOutput); ok { r0 = rf(input) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*riav1.RestoreItemActionExecuteOutput) + r0 = ret.Get(0).(*velero.RestoreItemActionExecuteOutput) } } var r1 error - if rf, ok := ret.Get(1).(func(*riav1.RestoreItemActionExecuteInput) error); ok { + if rf, ok := ret.Get(1).(func(*velero.RestoreItemActionExecuteInput) error); ok { r1 = rf(input) } else { r1 = ret.Error(1) diff --git a/pkg/plugin/velero/restore_item_action_shared.go b/pkg/plugin/velero/restore_item_action_shared.go new file mode 100644 index 0000000000..2714d69ab6 --- /dev/null +++ b/pkg/plugin/velero/restore_item_action_shared.go @@ -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 +} diff --git a/pkg/plugin/velero/restoreitemaction/v1/restore_item_action.go b/pkg/plugin/velero/restoreitemaction/v1/restore_item_action.go index a50f3021f0..3398af9e1e 100644 --- a/pkg/plugin/velero/restoreitemaction/v1/restore_item_action.go +++ b/pkg/plugin/velero/restoreitemaction/v1/restore_item_action.go @@ -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" ) @@ -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) } diff --git a/pkg/restore/add_pv_from_pvc_action.go b/pkg/restore/add_pv_from_pvc_action.go index 147ad553f4..04c992357f 100644 --- a/pkg/restore/add_pv_from_pvc_action.go +++ b/pkg/restore/add_pv_from_pvc_action.go @@ -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 { @@ -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 @@ -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 } @@ -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 diff --git a/pkg/restore/add_pv_from_pvc_action_test.go b/pkg/restore/add_pv_from_pvc_action_test.go index f8b5b5aaba..b4ceb90a43 100644 --- a/pkg/restore/add_pv_from_pvc_action_test.go +++ b/pkg/restore/add_pv_from_pvc_action_test.go @@ -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" ) @@ -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}, } diff --git a/pkg/restore/add_pvc_from_pod_action.go b/pkg/restore/add_pvc_from_pod_action.go index b7bd60a34c..70f33d985d 100644 --- a/pkg/restore/add_pvc_from_pod_action.go +++ b/pkg/restore/add_pvc_from_pod_action.go @@ -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 { @@ -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 @@ -64,7 +63,7 @@ func (a *AddPVCFromPodAction) Execute(input *riav1.RestoreItemActionExecuteInput }) } - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: additionalItems, }, nil diff --git a/pkg/restore/add_pvc_from_pod_action_test.go b/pkg/restore/add_pvc_from_pod_action_test.go index 529751b379..b409e5d6ef 100644 --- a/pkg/restore/add_pvc_from_pod_action_test.go +++ b/pkg/restore/add_pvc_from_pod_action_test.go @@ -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" ) @@ -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}, } diff --git a/pkg/restore/admissionwebhook_config_action.go b/pkg/restore/admissionwebhook_config_action.go index 68fa089888..8fd5c1693e 100644 --- a/pkg/restore/admissionwebhook_config_action.go +++ b/pkg/restore/admissionwebhook_config_action.go @@ -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 @@ -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") @@ -60,7 +59,7 @@ 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 { @@ -68,7 +67,7 @@ func (a *AdmissionWebhookConfigurationAction) Execute(input *riav1.RestoreItemAc } 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 { @@ -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 } diff --git a/pkg/restore/admissionwebhook_config_action_test.go b/pkg/restore/admissionwebhook_config_action_test.go index a6548ae586..c6c31d2219 100644 --- a/pkg/restore/admissionwebhook_config_action_test.go +++ b/pkg/restore/admissionwebhook_config_action_test.go @@ -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" ) @@ -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, }, diff --git a/pkg/restore/apiservice_action.go b/pkg/restore/apiservice_action.go index 0d9568c0b8..7f817a59e0 100644 --- a/pkg/restore/apiservice_action.go +++ b/pkg/restore/apiservice_action.go @@ -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 { @@ -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 } diff --git a/pkg/restore/apiservice_action_test.go b/pkg/restore/apiservice_action_test.go index 1f9baeae92..81f4a6171c 100644 --- a/pkg/restore/apiservice_action_test.go +++ b/pkg/restore/apiservice_action_test.go @@ -25,7 +25,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" - 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" ) @@ -40,7 +40,7 @@ func TestAPIServiceActionExecuteSkipsRestore(t *testing.T) { require.NoError(t, err) action := NewAPIServiceAction(velerotest.NewLogger()) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: unstructuredAPIService}, ItemFromBackup: &unstructured.Unstructured{Object: unstructuredAPIService}, }) diff --git a/pkg/restore/change_pvc_node_selector.go b/pkg/restore/change_pvc_node_selector.go index 23a3c20c90..d281d318f7 100644 --- a/pkg/restore/change_pvc_node_selector.go +++ b/pkg/restore/change_pvc_node_selector.go @@ -28,7 +28,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/plugin/framework/common" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) // ChangePVCNodeSelectorAction updates/reset PVC's node selector @@ -62,23 +61,23 @@ func (p *ChangePVCNodeSelectorAction) AppliesTo() (velero.ResourceSelector, erro // Execute updates the pvc's selected-node annotation: // a) if node mapping found in the config map for the plugin // b) if node mentioned in annotation doesn't exist -func (p *ChangePVCNodeSelectorAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (p *ChangePVCNodeSelectorAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { p.logger.Info("Executing ChangePVCNodeSelectorAction") defer p.logger.Info("Done executing ChangePVCNodeSelectorAction") typeAcc, err := meta.TypeAccessor(input.Item) if err != nil { - return &riav1.RestoreItemActionExecuteOutput{}, err + return &velero.RestoreItemActionExecuteOutput{}, err } metadata, err := meta.Accessor(input.Item) if err != nil { - return &riav1.RestoreItemActionExecuteOutput{}, err + return &velero.RestoreItemActionExecuteOutput{}, err } annotations := metadata.GetAnnotations() if annotations == nil { - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } log := p.logger.WithFields(map[string]interface{}{ @@ -91,7 +90,7 @@ func (p *ChangePVCNodeSelectorAction) Execute(input *riav1.RestoreItemActionExec node, ok := annotations["volume.kubernetes.io/selected-node"] if !ok { log.Debug("PVC doesn't have node selector") - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } // fetch node mapping from configMap @@ -106,7 +105,7 @@ func (p *ChangePVCNodeSelectorAction) Execute(input *riav1.RestoreItemActionExec annotations["volume.kubernetes.io/selected-node"] = newNode metadata.SetAnnotations(annotations) log.Infof("Updating selected-node to %s from %s", newNode, node) - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } // configMap doesn't have node-mapping @@ -126,7 +125,7 @@ func (p *ChangePVCNodeSelectorAction) Execute(input *riav1.RestoreItemActionExec } } - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } func getNewNodeFromConfigMap(client corev1client.ConfigMapInterface, node string) (string, error) { diff --git a/pkg/restore/change_pvc_node_selector_test.go b/pkg/restore/change_pvc_node_selector_test.go index 92a6f4b311..8be3051bac 100644 --- a/pkg/restore/change_pvc_node_selector_test.go +++ b/pkg/restore/change_pvc_node_selector_test.go @@ -31,7 +31,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "github.com/vmware-tanzu/velero/pkg/builder" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" ) // TestChangePVCNodeSelectorActionExecute runs the ChangePVCNodeSelectorAction's Execute @@ -146,7 +146,7 @@ func TestChangePVCNodeSelectorActionExecute(t *testing.T) { unstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(tc.pvc) require.NoError(t, err) - input := &riav1.RestoreItemActionExecuteInput{ + input := &velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{ Object: unstructuredMap, }, diff --git a/pkg/restore/change_storageclass_action.go b/pkg/restore/change_storageclass_action.go index 3349cc7925..a02b7c484e 100644 --- a/pkg/restore/change_storageclass_action.go +++ b/pkg/restore/change_storageclass_action.go @@ -31,7 +31,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/plugin/framework/common" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) // ChangeStorageClassAction updates a PV or PVC's storage class name @@ -65,7 +64,7 @@ func (a *ChangeStorageClassAction) AppliesTo() (velero.ResourceSelector, error) // Execute updates the item's spec.storageClassName if a mapping is found // in the config map for the plugin. -func (a *ChangeStorageClassAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *ChangeStorageClassAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { a.logger.Info("Executing ChangeStorageClassAction") defer a.logger.Info("Done executing ChangeStorageClassAction") @@ -77,7 +76,7 @@ func (a *ChangeStorageClassAction) Execute(input *riav1.RestoreItemActionExecute if config == nil || len(config.Data) == 0 { a.logger.Debug("No storage class mappings found") - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } obj, ok := input.Item.(*unstructured.Unstructured) @@ -129,7 +128,7 @@ func (a *ChangeStorageClassAction) Execute(input *riav1.RestoreItemActionExecute if err != nil { return nil, err } else if !exists { - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } log.Infof("Updating item's storage class name to %s", newStorageClass) @@ -138,7 +137,7 @@ func (a *ChangeStorageClassAction) Execute(input *riav1.RestoreItemActionExecute return nil, errors.Wrap(err, "unable to set item's spec.storageClassName") } } - return riav1.NewRestoreItemActionExecuteOutput(obj), nil + return velero.NewRestoreItemActionExecuteOutput(obj), nil } func (a *ChangeStorageClassAction) isStorageClassExist(log *logrus.Entry, storageClass *string, cm *corev1.ConfigMap) (exists bool, newStorageClass string, err error) { diff --git a/pkg/restore/change_storageclass_action_test.go b/pkg/restore/change_storageclass_action_test.go index 12a663075f..65de052db2 100644 --- a/pkg/restore/change_storageclass_action_test.go +++ b/pkg/restore/change_storageclass_action_test.go @@ -32,7 +32,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "github.com/vmware-tanzu/velero/pkg/builder" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" ) // TestChangeStorageClassActionExecute runs the ChangeStorageClassAction's Execute @@ -245,7 +245,7 @@ func TestChangeStorageClassActionExecute(t *testing.T) { unstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(tc.pvOrPvcOrSTS) require.NoError(t, err) - input := &riav1.RestoreItemActionExecuteInput{ + input := &velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{ Object: unstructuredMap, }, diff --git a/pkg/restore/clusterrolebinding_action.go b/pkg/restore/clusterrolebinding_action.go index eed52ba89c..851b13f098 100644 --- a/pkg/restore/clusterrolebinding_action.go +++ b/pkg/restore/clusterrolebinding_action.go @@ -24,7 +24,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" ) // ClusterRoleBindingAction handle namespace remappings for role bindings @@ -42,10 +41,10 @@ func (a *ClusterRoleBindingAction) AppliesTo() (velero.ResourceSelector, error) }, nil } -func (a *ClusterRoleBindingAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *ClusterRoleBindingAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { namespaceMapping := input.Restore.Spec.NamespaceMapping if len(namespaceMapping) == 0 { - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: input.Item.UnstructuredContent()}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: input.Item.UnstructuredContent()}), nil } clusterRoleBinding := new(rbac.ClusterRoleBinding) @@ -64,5 +63,5 @@ func (a *ClusterRoleBindingAction) Execute(input *riav1.RestoreItemActionExecute return nil, errors.WithStack(err) } - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } diff --git a/pkg/restore/clusterrolebinding_action_test.go b/pkg/restore/clusterrolebinding_action_test.go index a68334565a..cea1c57871 100644 --- a/pkg/restore/clusterrolebinding_action_test.go +++ b/pkg/restore/clusterrolebinding_action_test.go @@ -28,7 +28,6 @@ import ( api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" "github.com/vmware-tanzu/velero/pkg/test" ) @@ -90,7 +89,7 @@ func TestClusterRoleBindingActionExecute(t *testing.T) { require.NoError(t, err) action := NewClusterRoleBindingAction(test.NewLogger()) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: roleBindingUnstructured}, ItemFromBackup: &unstructured.Unstructured{Object: roleBindingUnstructured}, Restore: &api.Restore{ diff --git a/pkg/restore/crd_v1_preserve_unknown_fields_action.go b/pkg/restore/crd_v1_preserve_unknown_fields_action.go index a9d8768056..f67d47910d 100644 --- a/pkg/restore/crd_v1_preserve_unknown_fields_action.go +++ b/pkg/restore/crd_v1_preserve_unknown_fields_action.go @@ -26,7 +26,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" ) // CRDV1PreserveUnknownFieldsAction will take a CRD and inspect it for the API version and the PreserveUnknownFields value. @@ -46,7 +45,7 @@ func (c *CRDV1PreserveUnknownFieldsAction) AppliesTo() (velero.ResourceSelector, }, nil } -func (c *CRDV1PreserveUnknownFieldsAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (c *CRDV1PreserveUnknownFieldsAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { c.logger.Info("Executing CRDV1PreserveUnknownFieldsAction") name, _, err := unstructured.NestedString(input.Item.UnstructuredContent(), "name") @@ -63,7 +62,7 @@ func (c *CRDV1PreserveUnknownFieldsAction) Execute(input *riav1.RestoreItemActio // We don't want to "fix" anything in beta CRDs at the moment, just v1 versions with preserveunknownfields = true if version != "apiextensions.k8s.io/v1" { - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, }, nil } @@ -103,7 +102,7 @@ func (c *CRDV1PreserveUnknownFieldsAction) Execute(input *riav1.RestoreItemActio return nil, errors.Wrap(err, "unable to convert crd to runtime.Unstructured") } - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: &unstructured.Unstructured{Object: res}, }, nil } diff --git a/pkg/restore/crd_v1_preserve_unknown_fields_action_test.go b/pkg/restore/crd_v1_preserve_unknown_fields_action_test.go index 3840918ad5..77045b596d 100644 --- a/pkg/restore/crd_v1_preserve_unknown_fields_action_test.go +++ b/pkg/restore/crd_v1_preserve_unknown_fields_action_test.go @@ -24,7 +24,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "github.com/vmware-tanzu/velero/pkg/builder" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" "github.com/vmware-tanzu/velero/pkg/test" ) @@ -48,6 +48,6 @@ func TestExecuteForACRDWithAnIntOnAFloat64FieldShouldWork(t *testing.T) { a := NewCRDV1PreserveUnknownFieldsAction(test.NewLogger()) - _, err = a.Execute(&riav1.RestoreItemActionExecuteInput{Item: &u}) + _, err = a.Execute(&velero.RestoreItemActionExecuteInput{Item: &u}) require.NoError(t, err) } diff --git a/pkg/restore/init_restorehook_pod_action.go b/pkg/restore/init_restorehook_pod_action.go index cb72e14d4f..f994d811de 100644 --- a/pkg/restore/init_restorehook_pod_action.go +++ b/pkg/restore/init_restorehook_pod_action.go @@ -24,7 +24,6 @@ import ( "github.com/vmware-tanzu/velero/internal/hook" "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" ) // InitRestoreHookPodAction is a RestoreItemAction plugin applicable to pods that runs @@ -46,7 +45,7 @@ func (a *InitRestoreHookPodAction) AppliesTo() (velero.ResourceSelector, error) } // Execute implements the RestoreItemAction plugin interface method. -func (a *InitRestoreHookPodAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *InitRestoreHookPodAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { a.logger.Infof("Executing InitRestoreHookPodAction") // handle any init container restore hooks for the pod restoreHooks, err := hook.GetRestoreHooksFromSpec(&input.Restore.Spec.Hooks) @@ -61,5 +60,5 @@ func (a *InitRestoreHookPodAction) Execute(input *riav1.RestoreItemActionExecute } a.logger.Infof("Returning from InitRestoreHookPodAction") - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: postHooksItem.UnstructuredContent()}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: postHooksItem.UnstructuredContent()}), nil } diff --git a/pkg/restore/init_restorehook_pod_action_test.go b/pkg/restore/init_restorehook_pod_action_test.go index 058865660a..c69d3c23f9 100644 --- a/pkg/restore/init_restorehook_pod_action_test.go +++ b/pkg/restore/init_restorehook_pod_action_test.go @@ -29,7 +29,7 @@ import ( velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/builder" "github.com/vmware-tanzu/velero/pkg/kuberesource" - 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" ) @@ -125,7 +125,7 @@ func TestInitContainerRestoreHookPodActionExecute(t *testing.T) { unstructuredPod, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&tc.obj) require.NoError(t, err) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: unstructuredPod}, ItemFromBackup: &unstructured.Unstructured{Object: unstructuredPod}, Restore: tc.restore, diff --git a/pkg/restore/job_action.go b/pkg/restore/job_action.go index 4e20f9cc92..fbaf30b249 100644 --- a/pkg/restore/job_action.go +++ b/pkg/restore/job_action.go @@ -24,7 +24,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" ) type JobAction struct { @@ -41,7 +40,7 @@ func (a *JobAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *JobAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *JobAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { job := new(batchv1api.Job) if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), job); err != nil { return nil, errors.WithStack(err) @@ -57,5 +56,5 @@ func (a *JobAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1. return nil, errors.WithStack(err) } - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } diff --git a/pkg/restore/job_action_test.go b/pkg/restore/job_action_test.go index 0b15bc47f0..606dd089d8 100644 --- a/pkg/restore/job_action_test.go +++ b/pkg/restore/job_action_test.go @@ -27,7 +27,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" ) @@ -138,7 +138,7 @@ func TestJobActionExecute(t *testing.T) { unstructuredJob, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&test.obj) require.NoError(t, err) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: unstructuredJob}, ItemFromBackup: &unstructured.Unstructured{Object: unstructuredJob}, Restore: nil, diff --git a/pkg/restore/pod_action.go b/pkg/restore/pod_action.go index 35d9d75220..d4bdc13847 100644 --- a/pkg/restore/pod_action.go +++ b/pkg/restore/pod_action.go @@ -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" ) type PodAction struct { @@ -44,7 +43,7 @@ func (a *PodAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *PodAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *PodAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { pod := new(v1.Pod) if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), pod); err != nil { return nil, errors.WithStack(err) @@ -87,7 +86,7 @@ func (a *PodAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1. if err != nil { return nil, errors.WithStack(err) } - restoreExecuteOutput := riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}) + restoreExecuteOutput := velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}) if pod.Spec.PriorityClassName != "" { a.logger.Infof("Adding priorityclass %s to AdditionalItems", pod.Spec.PriorityClassName) restoreExecuteOutput.AdditionalItems = []velero.ResourceIdentifier{ diff --git a/pkg/restore/pod_action_test.go b/pkg/restore/pod_action_test.go index c8121df673..f1aa83c1a3 100644 --- a/pkg/restore/pod_action_test.go +++ b/pkg/restore/pod_action_test.go @@ -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" ) @@ -230,7 +229,7 @@ func TestPodActionExecute(t *testing.T) { unstructuredPod, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&test.obj) require.NoError(t, err) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: unstructuredPod}, ItemFromBackup: &unstructured.Unstructured{Object: unstructuredPod}, Restore: nil, diff --git a/pkg/restore/restic_restore_action.go b/pkg/restore/restic_restore_action.go index bf7116b8b9..f2d8df9a1d 100644 --- a/pkg/restore/restic_restore_action.go +++ b/pkg/restore/restic_restore_action.go @@ -36,7 +36,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/label" "github.com/vmware-tanzu/velero/pkg/plugin/framework/common" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" "github.com/vmware-tanzu/velero/pkg/podvolume" "github.com/vmware-tanzu/velero/pkg/util/kube" ) @@ -67,7 +66,7 @@ func (a *ResticRestoreAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *ResticRestoreAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *ResticRestoreAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { a.logger.Info("Executing ResticRestoreAction") defer a.logger.Info("Done executing ResticRestoreAction") @@ -100,7 +99,7 @@ func (a *ResticRestoreAction) Execute(input *riav1.RestoreItemActionExecuteInput volumeSnapshots := podvolume.GetVolumeBackupsForPod(podVolumeBackups, &pod, podFromBackup.Namespace) if len(volumeSnapshots) == 0 { log.Debug("No restic backups found for pod") - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } log.Info("Restic backups for pod found") @@ -172,7 +171,7 @@ func (a *ResticRestoreAction) Execute(input *riav1.RestoreItemActionExecuteInput return nil, errors.Wrap(err, "unable to convert pod to runtime.Unstructured") } - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } func getCommand(log logrus.FieldLogger, config *corev1.ConfigMap) []string { diff --git a/pkg/restore/restic_restore_action_test.go b/pkg/restore/restic_restore_action_test.go index 660c1fc66c..b218f4b88d 100644 --- a/pkg/restore/restic_restore_action_test.go +++ b/pkg/restore/restic_restore_action_test.go @@ -35,7 +35,7 @@ import ( "github.com/vmware-tanzu/velero/pkg/builder" "github.com/vmware-tanzu/velero/pkg/buildinfo" velerofake "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/fake" - 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" "github.com/vmware-tanzu/velero/pkg/util/kube" ) @@ -278,7 +278,7 @@ func TestResticRestoreActionExecute(t *testing.T) { unstructuredPodFromBackup = unstructuredPod } - input := &riav1.RestoreItemActionExecuteInput{ + input := &velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{ Object: unstructuredPod, }, diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 8705ae2127..02d882d955 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -1152,7 +1152,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso } ctx.log.Infof("Executing item action for %v", &groupResource) - executeOutput, err := action.RestoreItemAction.Execute(&riav1.RestoreItemActionExecuteInput{ + executeOutput, err := action.RestoreItemAction.Execute(&velero.RestoreItemActionExecuteInput{ Item: obj, ItemFromBackup: itemFromBackup, Restore: ctx.restore, diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index f1575bc185..46ef8cdede 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -1149,17 +1149,17 @@ func (a *recordResourcesAction) AppliesTo() (velero.ResourceSelector, error) { return a.selector, nil } -func (a *recordResourcesAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *recordResourcesAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { metadata, err := meta.Accessor(input.Item) if err != nil { - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: a.additionalItems, }, err } a.ids = append(a.ids, kubeutil.NamespaceAndName(metadata)) - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: a.additionalItems, }, nil @@ -1355,12 +1355,12 @@ func TestRestoreActionsRunForCorrectItems(t *testing.T) { // function body at runtime. type pluggableAction struct { selector velero.ResourceSelector - executeFunc func(*riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) + executeFunc func(*velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) } -func (a *pluggableAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *pluggableAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { if a.executeFunc == nil { - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, }, nil } @@ -1385,7 +1385,7 @@ func TestRestoreActionModifications(t *testing.T) { // method modifies the item being passed in by calling the 'modify' function on it. modifyingActionGetter := func(modify func(*unstructured.Unstructured)) *pluggableAction { return &pluggableAction{ - executeFunc: func(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { obj, ok := input.Item.(*unstructured.Unstructured) if !ok { return nil, errors.Errorf("unexpected type %T", input.Item) @@ -1394,7 +1394,7 @@ func TestRestoreActionModifications(t *testing.T) { res := obj.DeepCopy() modify(res) - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: res, }, nil }, @@ -1532,8 +1532,8 @@ func TestRestoreActionAdditionalItems(t *testing.T) { actions: []riav1.RestoreItemAction{ &pluggableAction{ selector: velero.ResourceSelector{IncludedNamespaces: []string{"ns-1"}}, - executeFunc: func(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { - return &riav1.RestoreItemActionExecuteOutput{ + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: []velero.ResourceIdentifier{ {GroupResource: kuberesource.Pods, Namespace: "ns-2", Name: "pod-2"}, @@ -1554,8 +1554,8 @@ func TestRestoreActionAdditionalItems(t *testing.T) { apiResources: []*test.APIResource{test.Pods()}, actions: []riav1.RestoreItemAction{ &pluggableAction{ - executeFunc: func(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { - return &riav1.RestoreItemActionExecuteOutput{ + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: []velero.ResourceIdentifier{ {GroupResource: kuberesource.Pods, Namespace: "ns-2", Name: "pod-2"}, @@ -1579,8 +1579,8 @@ func TestRestoreActionAdditionalItems(t *testing.T) { apiResources: []*test.APIResource{test.Pods(), test.PVs()}, actions: []riav1.RestoreItemAction{ &pluggableAction{ - executeFunc: func(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { - return &riav1.RestoreItemActionExecuteOutput{ + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: []velero.ResourceIdentifier{ {GroupResource: kuberesource.PersistentVolumes, Name: "pv-1"}, @@ -1605,8 +1605,8 @@ func TestRestoreActionAdditionalItems(t *testing.T) { apiResources: []*test.APIResource{test.Pods(), test.PVs()}, actions: []riav1.RestoreItemAction{ &pluggableAction{ - executeFunc: func(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { - return &riav1.RestoreItemActionExecuteOutput{ + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: []velero.ResourceIdentifier{ {GroupResource: kuberesource.PersistentVolumes, Name: "pv-1"}, @@ -1631,8 +1631,8 @@ func TestRestoreActionAdditionalItems(t *testing.T) { apiResources: []*test.APIResource{test.Pods(), test.PVs()}, actions: []riav1.RestoreItemAction{ &pluggableAction{ - executeFunc: func(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { - return &riav1.RestoreItemActionExecuteOutput{ + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: []velero.ResourceIdentifier{ {GroupResource: kuberesource.PersistentVolumes, Name: "pv-1"}, diff --git a/pkg/restore/rolebinding_action.go b/pkg/restore/rolebinding_action.go index 55820c21f9..c402075a61 100644 --- a/pkg/restore/rolebinding_action.go +++ b/pkg/restore/rolebinding_action.go @@ -24,7 +24,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" ) // RoleBindingAction handle namespace remappings for role bindings @@ -42,10 +41,10 @@ func (a *RoleBindingAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *RoleBindingAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *RoleBindingAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { namespaceMapping := input.Restore.Spec.NamespaceMapping if len(namespaceMapping) == 0 { - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: input.Item.UnstructuredContent()}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: input.Item.UnstructuredContent()}), nil } roleBinding := new(rbac.RoleBinding) @@ -64,5 +63,5 @@ func (a *RoleBindingAction) Execute(input *riav1.RestoreItemActionExecuteInput) return nil, errors.WithStack(err) } - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } diff --git a/pkg/restore/rolebinding_action_test.go b/pkg/restore/rolebinding_action_test.go index 2a62cf6d0d..8995df8c6d 100644 --- a/pkg/restore/rolebinding_action_test.go +++ b/pkg/restore/rolebinding_action_test.go @@ -28,7 +28,6 @@ import ( api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" "github.com/vmware-tanzu/velero/pkg/test" ) @@ -90,7 +89,7 @@ func TestRoleBindingActionExecute(t *testing.T) { require.NoError(t, err) action := NewRoleBindingAction(test.NewLogger()) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: roleBindingUnstructured}, ItemFromBackup: &unstructured.Unstructured{Object: roleBindingUnstructured}, Restore: &api.Restore{ diff --git a/pkg/restore/service_account_action.go b/pkg/restore/service_account_action.go index 424985a26e..252d9fc576 100644 --- a/pkg/restore/service_account_action.go +++ b/pkg/restore/service_account_action.go @@ -26,7 +26,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" "github.com/vmware-tanzu/velero/pkg/util/kube" ) @@ -44,7 +43,7 @@ func (a *ServiceAccountAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *ServiceAccountAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *ServiceAccountAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { a.logger.Info("Executing ServiceAccountAction") defer a.logger.Info("Done executing ServiceAccountAction") @@ -76,5 +75,5 @@ func (a *ServiceAccountAction) Execute(input *riav1.RestoreItemActionExecuteInpu return nil, errors.Wrap(err, "unable to convert serviceaccount to runtime.Unstructured") } - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } diff --git a/pkg/restore/service_account_action_test.go b/pkg/restore/service_account_action_test.go index f8bc76fcc8..0bc976a0fa 100644 --- a/pkg/restore/service_account_action_test.go +++ b/pkg/restore/service_account_action_test.go @@ -28,7 +28,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" "github.com/vmware-tanzu/velero/pkg/test" ) @@ -91,7 +90,7 @@ func TestServiceAccountActionExecute(t *testing.T) { require.NoError(t, err) action := NewServiceAccountAction(test.NewLogger()) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: saUnstructured}, ItemFromBackup: &unstructured.Unstructured{Object: saUnstructured}, Restore: nil, diff --git a/pkg/restore/service_action.go b/pkg/restore/service_action.go index d21690182e..0b22cf0959 100644 --- a/pkg/restore/service_action.go +++ b/pkg/restore/service_action.go @@ -28,7 +28,6 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" "github.com/vmware-tanzu/velero/pkg/util/boolptr" ) @@ -48,7 +47,7 @@ func (a *ServiceAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *ServiceAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *ServiceAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { service := new(corev1api.Service) if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), service); err != nil { return nil, errors.WithStack(err) @@ -73,7 +72,7 @@ func (a *ServiceAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*ri return nil, errors.WithStack(err) } - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } func deleteNodePorts(service *corev1api.Service) error { diff --git a/pkg/restore/service_action_test.go b/pkg/restore/service_action_test.go index ccdef0729a..59fef00a15 100644 --- a/pkg/restore/service_action_test.go +++ b/pkg/restore/service_action_test.go @@ -29,7 +29,7 @@ import ( api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/builder" - 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" ) @@ -377,7 +377,7 @@ func TestServiceActionExecute(t *testing.T) { unstructuredSvc, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&test.obj) require.NoError(t, err) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: unstructuredSvc}, ItemFromBackup: &unstructured.Unstructured{Object: unstructuredSvc}, Restore: test.restore, diff --git a/test/e2e/util/velero/install.go b/test/e2e/util/velero/install.go index b40ec17216..fc0389bc55 100644 --- a/test/e2e/util/velero/install.go +++ b/test/e2e/util/velero/install.go @@ -87,7 +87,7 @@ func VeleroInstall(ctx context.Context, veleroCfg *VerleroConfig, useVolumeSnaps return errors.WithMessagef(err, "Failed to get Velero InstallOptions for plugin provider %s", veleroCfg.ObjectStoreProvider) } veleroInstallOptions.UseVolumeSnapshots = useVolumeSnapshots - veleroInstallOptions.UseRestic = !useVolumeSnapshots + veleroInstallOptions.UseNodeAgent = !useVolumeSnapshots veleroInstallOptions.Image = veleroCfg.VeleroImage veleroInstallOptions.Namespace = veleroCfg.VeleroNamespace veleroInstallOptions.UploaderType = veleroCfg.UploaderType @@ -172,8 +172,8 @@ func installVeleroServer(ctx context.Context, cli string, options *installOption if len(options.Image) > 0 { args = append(args, "--image", options.Image) } - if options.UseRestic { - args = append(args, "--use-restic") + if options.UseNodeAgent { + args = append(args, "--use-node-agent") } if options.UseVolumeSnapshots { args = append(args, "--use-volume-snapshots") @@ -222,7 +222,7 @@ func installVeleroServer(ctx context.Context, cli string, options *installOption return err } - return waitVeleroReady(ctx, namespace, options.UseRestic) + return waitVeleroReady(ctx, namespace, options.UseNodeAgent) } func createVelereResources(ctx context.Context, cli, namespace string, args []string, registryCredentialFile, resticHelperImage string) error { @@ -376,7 +376,7 @@ func toUnstructured(res interface{}) (unstructured.Unstructured, error) { return un, err } -func waitVeleroReady(ctx context.Context, namespace string, useRestic bool) error { +func waitVeleroReady(ctx context.Context, namespace string, useNodeAgent bool) error { fmt.Println("Waiting for Velero deployment to be ready.") // when doing upgrade by the "kubectl apply" the command "kubectl wait --for=condition=available deployment/velero -n velero --timeout=600s" returns directly // use "rollout status" instead to avoid this. For more detail information, refer to https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#complete-deployment @@ -386,25 +386,25 @@ func waitVeleroReady(ctx context.Context, namespace string, useRestic bool) erro return errors.Wrapf(err, "fail to wait for the velero deployment ready, stdout=%s, stderr=%s", stdout, stderr) } - if useRestic { - fmt.Println("Waiting for Velero restic daemonset to be ready.") + if useNodeAgent { + fmt.Println("Waiting for node-agent daemonset to be ready.") err := wait.PollImmediate(5*time.Second, 1*time.Minute, func() (bool, error) { - stdout, stderr, err := velerexec.RunCommand(exec.CommandContext(ctx, "kubectl", "get", "daemonset/restic", + stdout, stderr, err := velerexec.RunCommand(exec.CommandContext(ctx, "kubectl", "get", "daemonset/node-agent", "-o", "json", "-n", namespace)) if err != nil { - return false, errors.Wrapf(err, "failed to get the restic daemonset, stdout=%s, stderr=%s", stdout, stderr) + return false, errors.Wrapf(err, "failed to get the node-agent daemonset, stdout=%s, stderr=%s", stdout, stderr) } - restic := &apps.DaemonSet{} - if err = json.Unmarshal([]byte(stdout), restic); err != nil { - return false, errors.Wrapf(err, "failed to unmarshal the restic daemonset") + daemonset := &apps.DaemonSet{} + if err = json.Unmarshal([]byte(stdout), daemonset); err != nil { + return false, errors.Wrapf(err, "failed to unmarshal the node-agent daemonset") } - if restic.Status.DesiredNumberScheduled == restic.Status.NumberAvailable { + if daemonset.Status.DesiredNumberScheduled == daemonset.Status.NumberAvailable { return true, nil } return false, nil }) if err != nil { - return errors.Wrap(err, "fail to wait for the velero restic ready") + return errors.Wrap(err, "fail to wait for the node-agent ready") } } diff --git a/tilt-resources/examples/restic.yaml b/tilt-resources/examples/node-agent.yaml similarity index 93% rename from tilt-resources/examples/restic.yaml rename to tilt-resources/examples/node-agent.yaml index 86d8a6f06c..d5c10fc47e 100644 --- a/tilt-resources/examples/restic.yaml +++ b/tilt-resources/examples/node-agent.yaml @@ -5,22 +5,22 @@ metadata: creationTimestamp: null labels: component: velero - name: restic + name: node-agent namespace: velero spec: selector: matchLabels: - name: restic + name: node-agent template: metadata: creationTimestamp: null labels: component: velero - name: restic + name: node-agent spec: containers: - args: - - restic + - node-agent - server command: - /velero @@ -43,7 +43,7 @@ spec: value: /credentials/cloud image: velero/velero:latest imagePullPolicy: Always - name: restic + name: node-agent resources: {} volumeMounts: - mountPath: /host_pods