mirror of
https://github.com/vmware-tanzu/velero.git
synced 2025-12-23 06:15:21 +00:00
The ShouldPerformSnapshotWithVolumeHelper function and tests intentionally use NewVolumeHelperImpl (deprecated) for backwards compatibility with third-party plugins. Add nolint:staticcheck to suppress the linter warnings with explanatory comments. Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>
98 lines
3.3 KiB
Go
98 lines
3.3 KiB
Go
/*
|
|
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 volumehelper
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
crclient "sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
"github.com/vmware-tanzu/velero/internal/resourcepolicies"
|
|
"github.com/vmware-tanzu/velero/internal/volumehelper"
|
|
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
|
"github.com/vmware-tanzu/velero/pkg/util/boolptr"
|
|
)
|
|
|
|
// ShouldPerformSnapshotWithBackup is used for third-party plugins.
|
|
// It supports to check whether the PVC or PodVolume should be backed
|
|
// up on demand. On the other hand, the volumeHelperImpl assume there
|
|
// is a VolumeHelper instance initialized before calling the
|
|
// ShouldPerformXXX functions.
|
|
//
|
|
// Deprecated: Use ShouldPerformSnapshotWithVolumeHelper instead for better performance.
|
|
// ShouldPerformSnapshotWithVolumeHelper allows passing a pre-created VolumeHelper with
|
|
// an internal PVC-to-Pod cache, which avoids O(N*M) complexity when there are many PVCs and pods.
|
|
// See issue #9179 for details.
|
|
func ShouldPerformSnapshotWithBackup(
|
|
unstructured runtime.Unstructured,
|
|
groupResource schema.GroupResource,
|
|
backup velerov1api.Backup,
|
|
crClient crclient.Client,
|
|
logger logrus.FieldLogger,
|
|
) (bool, error) {
|
|
return ShouldPerformSnapshotWithVolumeHelper(
|
|
unstructured,
|
|
groupResource,
|
|
backup,
|
|
crClient,
|
|
logger,
|
|
nil, // no cached VolumeHelper, will create one
|
|
)
|
|
}
|
|
|
|
// ShouldPerformSnapshotWithVolumeHelper is like ShouldPerformSnapshotWithBackup
|
|
// but accepts an optional VolumeHelper. If vh is non-nil, it will be used directly,
|
|
// avoiding the overhead of creating a new VolumeHelper on each call.
|
|
// This is useful for BIA plugins that process multiple PVCs during a single backup
|
|
// and want to reuse the same VolumeHelper (with its internal cache) across calls.
|
|
func ShouldPerformSnapshotWithVolumeHelper(
|
|
unstructured runtime.Unstructured,
|
|
groupResource schema.GroupResource,
|
|
backup velerov1api.Backup,
|
|
crClient crclient.Client,
|
|
logger logrus.FieldLogger,
|
|
vh volumehelper.VolumeHelper,
|
|
) (bool, error) {
|
|
// If a VolumeHelper is provided, use it directly
|
|
if vh != nil {
|
|
return vh.ShouldPerformSnapshot(unstructured, groupResource)
|
|
}
|
|
|
|
// Otherwise, create a new VolumeHelper (original behavior for third-party plugins)
|
|
resourcePolicies, err := resourcepolicies.GetResourcePoliciesFromBackup(
|
|
backup,
|
|
crClient,
|
|
logger,
|
|
)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
//nolint:staticcheck // Intentional use of deprecated function for backwards compatibility
|
|
volumeHelperImpl := volumehelper.NewVolumeHelperImpl(
|
|
resourcePolicies,
|
|
backup.Spec.SnapshotVolumes,
|
|
logger,
|
|
crClient,
|
|
boolptr.IsSetToTrue(backup.Spec.DefaultVolumesToFsBackup),
|
|
true,
|
|
)
|
|
|
|
return volumeHelperImpl.ShouldPerformSnapshot(unstructured, groupResource)
|
|
}
|