2018-02-28 01:35:35 +00:00
|
|
|
/*
|
2021-02-18 18:30:52 +00:00
|
|
|
Copyright the Velero contributors.
|
2018-02-28 01:35:35 +00:00
|
|
|
|
|
|
|
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 controller
|
|
|
|
|
|
|
|
import (
|
k8s 1.18 import (#2651)
* k8s 1.18 import wip
backup, cmd, controller, generated, restic, restore, serverstatusrequest, test and util
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* go mod tidy
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* add changelog file
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* go fmt
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* update code-generator and controller-gen in CI
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* checkout proper code-generator version, regen
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* fix remaining calls
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* regenerate CRDs with ./hack/update-generated-crd-code.sh
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* use existing context in restic and server
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* fix test cases by resetting resource version
also use main library go context, not golang.org/x/net/context, in pkg/restore/restore.go
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* clarify changelog message
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* use github.com/kubernetes-csi/external-snapshotter/v2@v2.2.0-rc1
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* run 'go mod tidy' to remove old external-snapshotter version
Signed-off-by: Andrew Lavery <laverya@umich.edu>
2020-07-16 16:21:37 +00:00
|
|
|
"context"
|
2018-02-28 01:35:35 +00:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2018-09-25 21:46:29 +00:00
|
|
|
"strings"
|
2020-07-22 19:07:52 +00:00
|
|
|
"time"
|
2018-02-28 01:35:35 +00:00
|
|
|
|
|
|
|
jsonpatch "github.com/evanphx/json-patch"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
2019-10-14 16:20:28 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2019-08-27 23:37:51 +00:00
|
|
|
"k8s.io/apimachinery/pkg/labels"
|
2018-02-28 01:35:35 +00:00
|
|
|
"k8s.io/apimachinery/pkg/types"
|
2019-06-28 15:58:02 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/clock"
|
2018-02-28 01:35:35 +00:00
|
|
|
corev1informers "k8s.io/client-go/informers/core/v1"
|
|
|
|
corev1listers "k8s.io/client-go/listers/core/v1"
|
|
|
|
"k8s.io/client-go/tools/cache"
|
|
|
|
|
Use Credential from BSL for restic commands (#3489)
* Use Credential from BSL for restic commands
This change introduces support for restic to make use of per-BSL
credentials. It makes use of the `credentials.FileStore` introduced in
PR #3442 to write the BSL credentials to disk. To support per-BSL
credentials for restic, the environment for the restic commands needs to
be modified for each provider to ensure that the credentials are
provided via the correct provider specific environment variables.
This change introduces a new function `restic.CmdEnv` to check the BSL
provider and create the correct mapping of environment variables for
each provider.
Previously, AWS and GCP could rely on the environment variables in the
Velero deployments to obtain the credentials file, but now these
environment variables need to be set with the path to the serialized
credentials file if a credential is set on the BSL.
For Azure, the credentials file in the environment was loaded and parsed
to set the environment variables for restic. Now, we check if the BSL
has a credential, and if it does, load and parse that file instead.
This change also introduces a few other small improvements. Now that we
are fetching the BSL to check for the `Credential` field, we can use the
BSL directly to get the `CACert` which means that we can remove the
`GetCACert` function. Also, now that we have a way to serialize secrets
to disk, we can use the `credentials.FileStore` to get a temp file for
the restic repo password and remove the `restic.TempCredentialsFile`
function.
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Add documentation for per-BSL credentials
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review feedback
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review comments
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
2021-03-11 18:10:51 +00:00
|
|
|
"github.com/vmware-tanzu/velero/internal/credentials"
|
2019-09-30 21:26:56 +00:00
|
|
|
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
|
|
|
velerov1client "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
|
|
|
|
informers "github.com/vmware-tanzu/velero/pkg/generated/informers/externalversions/velero/v1"
|
|
|
|
listers "github.com/vmware-tanzu/velero/pkg/generated/listers/velero/v1"
|
2020-07-22 19:07:52 +00:00
|
|
|
"github.com/vmware-tanzu/velero/pkg/metrics"
|
2019-09-30 21:26:56 +00:00
|
|
|
"github.com/vmware-tanzu/velero/pkg/restic"
|
|
|
|
"github.com/vmware-tanzu/velero/pkg/util/filesystem"
|
|
|
|
"github.com/vmware-tanzu/velero/pkg/util/kube"
|
2020-06-24 16:55:18 +00:00
|
|
|
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
2018-02-28 01:35:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type podVolumeBackupController struct {
|
|
|
|
*genericController
|
|
|
|
|
2019-01-25 03:33:07 +00:00
|
|
|
podVolumeBackupClient velerov1client.PodVolumeBackupsGetter
|
2018-02-28 01:35:35 +00:00
|
|
|
podVolumeBackupLister listers.PodVolumeBackupLister
|
|
|
|
podLister corev1listers.PodLister
|
|
|
|
pvcLister corev1listers.PersistentVolumeClaimLister
|
2019-07-10 22:16:21 +00:00
|
|
|
pvLister corev1listers.PersistentVolumeLister
|
2020-06-24 16:55:18 +00:00
|
|
|
kbClient client.Client
|
2018-02-28 01:35:35 +00:00
|
|
|
nodeName string
|
2020-07-22 19:07:52 +00:00
|
|
|
metrics *metrics.ServerMetrics
|
Use Credential from BSL for restic commands (#3489)
* Use Credential from BSL for restic commands
This change introduces support for restic to make use of per-BSL
credentials. It makes use of the `credentials.FileStore` introduced in
PR #3442 to write the BSL credentials to disk. To support per-BSL
credentials for restic, the environment for the restic commands needs to
be modified for each provider to ensure that the credentials are
provided via the correct provider specific environment variables.
This change introduces a new function `restic.CmdEnv` to check the BSL
provider and create the correct mapping of environment variables for
each provider.
Previously, AWS and GCP could rely on the environment variables in the
Velero deployments to obtain the credentials file, but now these
environment variables need to be set with the path to the serialized
credentials file if a credential is set on the BSL.
For Azure, the credentials file in the environment was loaded and parsed
to set the environment variables for restic. Now, we check if the BSL
has a credential, and if it does, load and parse that file instead.
This change also introduces a few other small improvements. Now that we
are fetching the BSL to check for the `Credential` field, we can use the
BSL directly to get the `CACert` which means that we can remove the
`GetCACert` function. Also, now that we have a way to serialize secrets
to disk, we can use the `credentials.FileStore` to get a temp file for
the restic repo password and remove the `restic.TempCredentialsFile`
function.
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Add documentation for per-BSL credentials
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review feedback
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review comments
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
2021-03-11 18:10:51 +00:00
|
|
|
credentialsFileStore credentials.FileStore
|
2018-02-28 01:35:35 +00:00
|
|
|
|
2019-01-25 03:33:07 +00:00
|
|
|
processBackupFunc func(*velerov1api.PodVolumeBackup) error
|
2018-06-18 17:54:07 +00:00
|
|
|
fileSystem filesystem.Interface
|
2019-06-28 15:58:02 +00:00
|
|
|
clock clock.Clock
|
2018-02-28 01:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewPodVolumeBackupController creates a new pod volume backup controller.
|
|
|
|
func NewPodVolumeBackupController(
|
|
|
|
logger logrus.FieldLogger,
|
|
|
|
podVolumeBackupInformer informers.PodVolumeBackupInformer,
|
2019-01-25 03:33:07 +00:00
|
|
|
podVolumeBackupClient velerov1client.PodVolumeBackupsGetter,
|
2018-02-28 01:35:35 +00:00
|
|
|
podInformer cache.SharedIndexInformer,
|
|
|
|
pvcInformer corev1informers.PersistentVolumeClaimInformer,
|
2019-07-10 22:16:21 +00:00
|
|
|
pvInformer corev1informers.PersistentVolumeInformer,
|
2020-07-22 19:07:52 +00:00
|
|
|
metrics *metrics.ServerMetrics,
|
2020-06-24 16:55:18 +00:00
|
|
|
kbClient client.Client,
|
2018-02-28 01:35:35 +00:00
|
|
|
nodeName string,
|
Use Credential from BSL for restic commands (#3489)
* Use Credential from BSL for restic commands
This change introduces support for restic to make use of per-BSL
credentials. It makes use of the `credentials.FileStore` introduced in
PR #3442 to write the BSL credentials to disk. To support per-BSL
credentials for restic, the environment for the restic commands needs to
be modified for each provider to ensure that the credentials are
provided via the correct provider specific environment variables.
This change introduces a new function `restic.CmdEnv` to check the BSL
provider and create the correct mapping of environment variables for
each provider.
Previously, AWS and GCP could rely on the environment variables in the
Velero deployments to obtain the credentials file, but now these
environment variables need to be set with the path to the serialized
credentials file if a credential is set on the BSL.
For Azure, the credentials file in the environment was loaded and parsed
to set the environment variables for restic. Now, we check if the BSL
has a credential, and if it does, load and parse that file instead.
This change also introduces a few other small improvements. Now that we
are fetching the BSL to check for the `Credential` field, we can use the
BSL directly to get the `CACert` which means that we can remove the
`GetCACert` function. Also, now that we have a way to serialize secrets
to disk, we can use the `credentials.FileStore` to get a temp file for
the restic repo password and remove the `restic.TempCredentialsFile`
function.
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Add documentation for per-BSL credentials
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review feedback
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review comments
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
2021-03-11 18:10:51 +00:00
|
|
|
credentialsFileStore credentials.FileStore,
|
2018-02-28 01:35:35 +00:00
|
|
|
) Interface {
|
|
|
|
c := &podVolumeBackupController{
|
2020-10-06 17:58:56 +00:00
|
|
|
genericController: newGenericController(PodVolumeBackup, logger),
|
2018-02-28 01:35:35 +00:00
|
|
|
podVolumeBackupClient: podVolumeBackupClient,
|
|
|
|
podVolumeBackupLister: podVolumeBackupInformer.Lister(),
|
|
|
|
podLister: corev1listers.NewPodLister(podInformer.GetIndexer()),
|
|
|
|
pvcLister: pvcInformer.Lister(),
|
2019-07-10 22:16:21 +00:00
|
|
|
pvLister: pvInformer.Lister(),
|
2020-06-24 16:55:18 +00:00
|
|
|
kbClient: kbClient,
|
2018-02-28 01:35:35 +00:00
|
|
|
nodeName: nodeName,
|
2020-07-22 19:07:52 +00:00
|
|
|
metrics: metrics,
|
Use Credential from BSL for restic commands (#3489)
* Use Credential from BSL for restic commands
This change introduces support for restic to make use of per-BSL
credentials. It makes use of the `credentials.FileStore` introduced in
PR #3442 to write the BSL credentials to disk. To support per-BSL
credentials for restic, the environment for the restic commands needs to
be modified for each provider to ensure that the credentials are
provided via the correct provider specific environment variables.
This change introduces a new function `restic.CmdEnv` to check the BSL
provider and create the correct mapping of environment variables for
each provider.
Previously, AWS and GCP could rely on the environment variables in the
Velero deployments to obtain the credentials file, but now these
environment variables need to be set with the path to the serialized
credentials file if a credential is set on the BSL.
For Azure, the credentials file in the environment was loaded and parsed
to set the environment variables for restic. Now, we check if the BSL
has a credential, and if it does, load and parse that file instead.
This change also introduces a few other small improvements. Now that we
are fetching the BSL to check for the `Credential` field, we can use the
BSL directly to get the `CACert` which means that we can remove the
`GetCACert` function. Also, now that we have a way to serialize secrets
to disk, we can use the `credentials.FileStore` to get a temp file for
the restic repo password and remove the `restic.TempCredentialsFile`
function.
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Add documentation for per-BSL credentials
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review feedback
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review comments
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
2021-03-11 18:10:51 +00:00
|
|
|
credentialsFileStore: credentialsFileStore,
|
2018-06-18 17:54:07 +00:00
|
|
|
|
|
|
|
fileSystem: filesystem.NewFileSystem(),
|
2019-06-28 15:58:02 +00:00
|
|
|
clock: &clock.RealClock{},
|
2018-02-28 01:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.syncHandler = c.processQueueItem
|
|
|
|
c.cacheSyncWaiters = append(
|
|
|
|
c.cacheSyncWaiters,
|
|
|
|
podVolumeBackupInformer.Informer().HasSynced,
|
|
|
|
podInformer.HasSynced,
|
|
|
|
pvcInformer.Informer().HasSynced,
|
|
|
|
)
|
|
|
|
c.processBackupFunc = c.processBackup
|
|
|
|
|
|
|
|
podVolumeBackupInformer.Informer().AddEventHandler(
|
|
|
|
cache.ResourceEventHandlerFuncs{
|
2018-06-20 22:46:41 +00:00
|
|
|
AddFunc: c.pvbHandler,
|
|
|
|
UpdateFunc: func(_, obj interface{}) { c.pvbHandler(obj) },
|
2018-02-28 01:35:35 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2018-06-20 22:46:41 +00:00
|
|
|
func (c *podVolumeBackupController) pvbHandler(obj interface{}) {
|
2019-01-25 03:33:07 +00:00
|
|
|
req := obj.(*velerov1api.PodVolumeBackup)
|
2018-06-20 22:46:41 +00:00
|
|
|
|
|
|
|
// only enqueue items for this node
|
|
|
|
if req.Spec.Node != c.nodeName {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log := loggerForPodVolumeBackup(c.logger, req)
|
|
|
|
|
2019-01-25 03:33:07 +00:00
|
|
|
if req.Status.Phase != "" && req.Status.Phase != velerov1api.PodVolumeBackupPhaseNew {
|
2018-06-20 22:46:41 +00:00
|
|
|
log.Debug("Backup is not new, not enqueuing")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-07-22 19:07:52 +00:00
|
|
|
c.metrics.RegisterPodVolumeBackupEnqueue(c.nodeName)
|
|
|
|
|
2018-06-20 22:46:41 +00:00
|
|
|
log.Debug("Enqueueing")
|
|
|
|
c.enqueue(obj)
|
|
|
|
}
|
|
|
|
|
2018-02-28 01:35:35 +00:00
|
|
|
func (c *podVolumeBackupController) processQueueItem(key string) error {
|
|
|
|
log := c.logger.WithField("key", key)
|
2018-06-20 22:46:41 +00:00
|
|
|
log.Debug("Running processQueueItem")
|
2018-02-28 01:35:35 +00:00
|
|
|
|
|
|
|
ns, name, err := cache.SplitMetaNamespaceKey(key)
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("error splitting queue key")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
req, err := c.podVolumeBackupLister.PodVolumeBackups(ns).Get(name)
|
|
|
|
if apierrors.IsNotFound(err) {
|
|
|
|
log.Debug("Unable to find PodVolumeBackup")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "error getting PodVolumeBackup")
|
|
|
|
}
|
|
|
|
|
|
|
|
// only process new items
|
|
|
|
switch req.Status.Phase {
|
2019-01-25 03:33:07 +00:00
|
|
|
case "", velerov1api.PodVolumeBackupPhaseNew:
|
2018-02-28 01:35:35 +00:00
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't mutate the shared cache
|
|
|
|
reqCopy := req.DeepCopy()
|
|
|
|
return c.processBackupFunc(reqCopy)
|
|
|
|
}
|
|
|
|
|
2019-01-25 03:33:07 +00:00
|
|
|
func loggerForPodVolumeBackup(baseLogger logrus.FieldLogger, req *velerov1api.PodVolumeBackup) logrus.FieldLogger {
|
2018-06-20 22:46:41 +00:00
|
|
|
log := baseLogger.WithFields(logrus.Fields{
|
2018-02-28 01:35:35 +00:00
|
|
|
"namespace": req.Namespace,
|
|
|
|
"name": req.Name,
|
|
|
|
})
|
|
|
|
|
2018-06-20 22:46:41 +00:00
|
|
|
if len(req.OwnerReferences) == 1 {
|
|
|
|
log = log.WithField("backup", fmt.Sprintf("%s/%s", req.Namespace, req.OwnerReferences[0].Name))
|
|
|
|
}
|
|
|
|
|
|
|
|
return log
|
|
|
|
}
|
|
|
|
|
2020-07-22 19:07:52 +00:00
|
|
|
func getOwningBackup(req *velerov1api.PodVolumeBackup) string {
|
|
|
|
return fmt.Sprintf("%s/%s", req.Namespace, req.OwnerReferences[0].Name)
|
|
|
|
}
|
|
|
|
|
2019-01-25 03:33:07 +00:00
|
|
|
func (c *podVolumeBackupController) processBackup(req *velerov1api.PodVolumeBackup) error {
|
2018-06-20 22:46:41 +00:00
|
|
|
log := loggerForPodVolumeBackup(c.logger, req)
|
|
|
|
|
|
|
|
log.Info("Backup starting")
|
|
|
|
|
2018-02-28 01:35:35 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
// update status to InProgress
|
2019-06-28 15:58:02 +00:00
|
|
|
req, err = c.patchPodVolumeBackup(req, func(r *velerov1api.PodVolumeBackup) {
|
|
|
|
r.Status.Phase = velerov1api.PodVolumeBackupPhaseInProgress
|
2019-10-14 16:20:28 +00:00
|
|
|
r.Status.StartTimestamp = &metav1.Time{Time: c.clock.Now()}
|
2019-06-28 15:58:02 +00:00
|
|
|
})
|
2018-02-28 01:35:35 +00:00
|
|
|
if err != nil {
|
2019-06-28 15:58:02 +00:00
|
|
|
log.WithError(err).Error("Error setting PodVolumeBackup StartTimestamp and phase to InProgress")
|
2018-02-28 01:35:35 +00:00
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
pod, err := c.podLister.Pods(req.Spec.Pod.Namespace).Get(req.Spec.Pod.Name)
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Errorf("Error getting pod %s/%s", req.Spec.Pod.Namespace, req.Spec.Pod.Name)
|
|
|
|
return c.fail(req, errors.Wrap(err, "error getting pod").Error(), log)
|
|
|
|
}
|
|
|
|
|
2019-07-10 22:16:21 +00:00
|
|
|
volumeDir, err := kube.GetVolumeDirectory(pod, req.Spec.Volume, c.pvcLister, c.pvLister)
|
2018-02-28 01:35:35 +00:00
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("Error getting volume directory name")
|
|
|
|
return c.fail(req, errors.Wrap(err, "error getting volume directory name").Error(), log)
|
|
|
|
}
|
|
|
|
|
2018-06-20 22:46:41 +00:00
|
|
|
pathGlob := fmt.Sprintf("/host_pods/%s/volumes/*/%s", string(req.Spec.Pod.UID), volumeDir)
|
|
|
|
log.WithField("pathGlob", pathGlob).Debug("Looking for path matching glob")
|
|
|
|
|
|
|
|
path, err := singlePathMatch(pathGlob)
|
2018-02-28 01:35:35 +00:00
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("Error uniquely identifying volume path")
|
|
|
|
return c.fail(req, errors.Wrap(err, "error getting volume path on host").Error(), log)
|
|
|
|
}
|
2018-06-20 22:46:41 +00:00
|
|
|
log.WithField("path", path).Debugf("Found path matching glob")
|
2018-02-28 01:35:35 +00:00
|
|
|
|
|
|
|
// temp creds
|
Use Credential from BSL for restic commands (#3489)
* Use Credential from BSL for restic commands
This change introduces support for restic to make use of per-BSL
credentials. It makes use of the `credentials.FileStore` introduced in
PR #3442 to write the BSL credentials to disk. To support per-BSL
credentials for restic, the environment for the restic commands needs to
be modified for each provider to ensure that the credentials are
provided via the correct provider specific environment variables.
This change introduces a new function `restic.CmdEnv` to check the BSL
provider and create the correct mapping of environment variables for
each provider.
Previously, AWS and GCP could rely on the environment variables in the
Velero deployments to obtain the credentials file, but now these
environment variables need to be set with the path to the serialized
credentials file if a credential is set on the BSL.
For Azure, the credentials file in the environment was loaded and parsed
to set the environment variables for restic. Now, we check if the BSL
has a credential, and if it does, load and parse that file instead.
This change also introduces a few other small improvements. Now that we
are fetching the BSL to check for the `Credential` field, we can use the
BSL directly to get the `CACert` which means that we can remove the
`GetCACert` function. Also, now that we have a way to serialize secrets
to disk, we can use the `credentials.FileStore` to get a temp file for
the restic repo password and remove the `restic.TempCredentialsFile`
function.
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Add documentation for per-BSL credentials
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review feedback
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review comments
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
2021-03-11 18:10:51 +00:00
|
|
|
credentialsFile, err := c.credentialsFileStore.Path(restic.RepoKeySelector())
|
2018-02-28 01:35:35 +00:00
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("Error creating temp restic credentials file")
|
|
|
|
return c.fail(req, errors.Wrap(err, "error creating temp restic credentials file").Error(), log)
|
|
|
|
}
|
|
|
|
// ignore error since there's nothing we can do and it's a temp file.
|
2020-03-24 21:50:48 +00:00
|
|
|
defer os.Remove(credentialsFile)
|
2018-02-28 01:35:35 +00:00
|
|
|
|
|
|
|
resticCmd := restic.BackupCommand(
|
2018-06-15 03:24:01 +00:00
|
|
|
req.Spec.RepoIdentifier,
|
2020-03-24 21:50:48 +00:00
|
|
|
credentialsFile,
|
2018-02-28 01:35:35 +00:00
|
|
|
path,
|
|
|
|
req.Spec.Tags,
|
|
|
|
)
|
|
|
|
|
Use Credential from BSL for restic commands (#3489)
* Use Credential from BSL for restic commands
This change introduces support for restic to make use of per-BSL
credentials. It makes use of the `credentials.FileStore` introduced in
PR #3442 to write the BSL credentials to disk. To support per-BSL
credentials for restic, the environment for the restic commands needs to
be modified for each provider to ensure that the credentials are
provided via the correct provider specific environment variables.
This change introduces a new function `restic.CmdEnv` to check the BSL
provider and create the correct mapping of environment variables for
each provider.
Previously, AWS and GCP could rely on the environment variables in the
Velero deployments to obtain the credentials file, but now these
environment variables need to be set with the path to the serialized
credentials file if a credential is set on the BSL.
For Azure, the credentials file in the environment was loaded and parsed
to set the environment variables for restic. Now, we check if the BSL
has a credential, and if it does, load and parse that file instead.
This change also introduces a few other small improvements. Now that we
are fetching the BSL to check for the `Credential` field, we can use the
BSL directly to get the `CACert` which means that we can remove the
`GetCACert` function. Also, now that we have a way to serialize secrets
to disk, we can use the `credentials.FileStore` to get a temp file for
the restic repo password and remove the `restic.TempCredentialsFile`
function.
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Add documentation for per-BSL credentials
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review feedback
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review comments
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
2021-03-11 18:10:51 +00:00
|
|
|
backupLocation := &velerov1api.BackupStorageLocation{}
|
|
|
|
if err := c.kbClient.Get(context.Background(), client.ObjectKey{
|
|
|
|
Namespace: req.Namespace,
|
|
|
|
Name: req.Spec.BackupStorageLocation,
|
|
|
|
}, backupLocation); err != nil {
|
|
|
|
return c.fail(req, errors.Wrap(err, "error getting backup storage location").Error(), log)
|
2020-03-24 21:50:48 +00:00
|
|
|
}
|
2020-06-24 16:55:18 +00:00
|
|
|
|
Use Credential from BSL for restic commands (#3489)
* Use Credential from BSL for restic commands
This change introduces support for restic to make use of per-BSL
credentials. It makes use of the `credentials.FileStore` introduced in
PR #3442 to write the BSL credentials to disk. To support per-BSL
credentials for restic, the environment for the restic commands needs to
be modified for each provider to ensure that the credentials are
provided via the correct provider specific environment variables.
This change introduces a new function `restic.CmdEnv` to check the BSL
provider and create the correct mapping of environment variables for
each provider.
Previously, AWS and GCP could rely on the environment variables in the
Velero deployments to obtain the credentials file, but now these
environment variables need to be set with the path to the serialized
credentials file if a credential is set on the BSL.
For Azure, the credentials file in the environment was loaded and parsed
to set the environment variables for restic. Now, we check if the BSL
has a credential, and if it does, load and parse that file instead.
This change also introduces a few other small improvements. Now that we
are fetching the BSL to check for the `Credential` field, we can use the
BSL directly to get the `CACert` which means that we can remove the
`GetCACert` function. Also, now that we have a way to serialize secrets
to disk, we can use the `credentials.FileStore` to get a temp file for
the restic repo password and remove the `restic.TempCredentialsFile`
function.
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Add documentation for per-BSL credentials
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review feedback
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review comments
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
2021-03-11 18:10:51 +00:00
|
|
|
// if there's a caCert on the ObjectStorage, write it to disk so that it can be passed to restic
|
2020-03-24 21:50:48 +00:00
|
|
|
var caCertFile string
|
Use Credential from BSL for restic commands (#3489)
* Use Credential from BSL for restic commands
This change introduces support for restic to make use of per-BSL
credentials. It makes use of the `credentials.FileStore` introduced in
PR #3442 to write the BSL credentials to disk. To support per-BSL
credentials for restic, the environment for the restic commands needs to
be modified for each provider to ensure that the credentials are
provided via the correct provider specific environment variables.
This change introduces a new function `restic.CmdEnv` to check the BSL
provider and create the correct mapping of environment variables for
each provider.
Previously, AWS and GCP could rely on the environment variables in the
Velero deployments to obtain the credentials file, but now these
environment variables need to be set with the path to the serialized
credentials file if a credential is set on the BSL.
For Azure, the credentials file in the environment was loaded and parsed
to set the environment variables for restic. Now, we check if the BSL
has a credential, and if it does, load and parse that file instead.
This change also introduces a few other small improvements. Now that we
are fetching the BSL to check for the `Credential` field, we can use the
BSL directly to get the `CACert` which means that we can remove the
`GetCACert` function. Also, now that we have a way to serialize secrets
to disk, we can use the `credentials.FileStore` to get a temp file for
the restic repo password and remove the `restic.TempCredentialsFile`
function.
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Add documentation for per-BSL credentials
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review feedback
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review comments
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
2021-03-11 18:10:51 +00:00
|
|
|
if backupLocation.Spec.ObjectStorage != nil && backupLocation.Spec.ObjectStorage.CACert != nil {
|
|
|
|
caCertFile, err = restic.TempCACertFile(backupLocation.Spec.ObjectStorage.CACert, req.Spec.BackupStorageLocation, c.fileSystem)
|
2020-03-24 21:50:48 +00:00
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("Error creating temp cacert file")
|
|
|
|
}
|
|
|
|
// ignore error since there's nothing we can do and it's a temp file.
|
|
|
|
defer os.Remove(caCertFile)
|
|
|
|
}
|
|
|
|
resticCmd.CACertFile = caCertFile
|
|
|
|
|
Use Credential from BSL for restic commands (#3489)
* Use Credential from BSL for restic commands
This change introduces support for restic to make use of per-BSL
credentials. It makes use of the `credentials.FileStore` introduced in
PR #3442 to write the BSL credentials to disk. To support per-BSL
credentials for restic, the environment for the restic commands needs to
be modified for each provider to ensure that the credentials are
provided via the correct provider specific environment variables.
This change introduces a new function `restic.CmdEnv` to check the BSL
provider and create the correct mapping of environment variables for
each provider.
Previously, AWS and GCP could rely on the environment variables in the
Velero deployments to obtain the credentials file, but now these
environment variables need to be set with the path to the serialized
credentials file if a credential is set on the BSL.
For Azure, the credentials file in the environment was loaded and parsed
to set the environment variables for restic. Now, we check if the BSL
has a credential, and if it does, load and parse that file instead.
This change also introduces a few other small improvements. Now that we
are fetching the BSL to check for the `Credential` field, we can use the
BSL directly to get the `CACert` which means that we can remove the
`GetCACert` function. Also, now that we have a way to serialize secrets
to disk, we can use the `credentials.FileStore` to get a temp file for
the restic repo password and remove the `restic.TempCredentialsFile`
function.
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Add documentation for per-BSL credentials
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review feedback
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review comments
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
2021-03-11 18:10:51 +00:00
|
|
|
env, err := restic.CmdEnv(backupLocation, c.credentialsFileStore)
|
|
|
|
if err != nil {
|
|
|
|
return c.fail(req, errors.Wrap(err, "error setting restic cmd env").Error(), log)
|
2018-09-25 21:46:29 +00:00
|
|
|
}
|
Use Credential from BSL for restic commands (#3489)
* Use Credential from BSL for restic commands
This change introduces support for restic to make use of per-BSL
credentials. It makes use of the `credentials.FileStore` introduced in
PR #3442 to write the BSL credentials to disk. To support per-BSL
credentials for restic, the environment for the restic commands needs to
be modified for each provider to ensure that the credentials are
provided via the correct provider specific environment variables.
This change introduces a new function `restic.CmdEnv` to check the BSL
provider and create the correct mapping of environment variables for
each provider.
Previously, AWS and GCP could rely on the environment variables in the
Velero deployments to obtain the credentials file, but now these
environment variables need to be set with the path to the serialized
credentials file if a credential is set on the BSL.
For Azure, the credentials file in the environment was loaded and parsed
to set the environment variables for restic. Now, we check if the BSL
has a credential, and if it does, load and parse that file instead.
This change also introduces a few other small improvements. Now that we
are fetching the BSL to check for the `Credential` field, we can use the
BSL directly to get the `CACert` which means that we can remove the
`GetCACert` function. Also, now that we have a way to serialize secrets
to disk, we can use the `credentials.FileStore` to get a temp file for
the restic repo password and remove the `restic.TempCredentialsFile`
function.
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Add documentation for per-BSL credentials
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review feedback
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review comments
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
2021-03-11 18:10:51 +00:00
|
|
|
resticCmd.Env = env
|
2018-09-25 21:46:29 +00:00
|
|
|
|
2019-08-27 23:37:51 +00:00
|
|
|
// If this is a PVC, look for the most recent completed pod volume backup for it and get
|
|
|
|
// its restic snapshot ID to use as the value of the `--parent` flag. Without this,
|
|
|
|
// if the pod using the PVC (and therefore the directory path under /host_pods/) has
|
|
|
|
// changed since the PVC's last backup, restic will not be able to identify a suitable
|
|
|
|
// parent snapshot to use, and will have to do a full rescan of the contents of the PVC.
|
|
|
|
if pvcUID, ok := req.Labels[velerov1api.PVCUIDLabel]; ok {
|
2020-02-19 19:01:22 +00:00
|
|
|
parentSnapshotID := getParentSnapshot(log, pvcUID, req.Spec.BackupStorageLocation, c.podVolumeBackupLister.PodVolumeBackups(req.Namespace))
|
2019-08-27 23:37:51 +00:00
|
|
|
if parentSnapshotID == "" {
|
|
|
|
log.Info("No parent snapshot found for PVC, not using --parent flag for this backup")
|
|
|
|
} else {
|
|
|
|
log.WithField("parentSnapshotID", parentSnapshotID).Info("Setting --parent flag for this backup")
|
|
|
|
resticCmd.ExtraFlags = append(resticCmd.ExtraFlags, fmt.Sprintf("--parent=%s", parentSnapshotID))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-28 01:35:35 +00:00
|
|
|
var stdout, stderr string
|
|
|
|
|
2019-05-30 16:48:21 +00:00
|
|
|
var emptySnapshot bool
|
2019-09-10 18:28:19 +00:00
|
|
|
if stdout, stderr, err = restic.RunBackup(resticCmd, log, c.updateBackupProgressFunc(req, log)); err != nil {
|
2019-05-30 16:48:21 +00:00
|
|
|
if strings.Contains(stderr, "snapshot is empty") {
|
|
|
|
emptySnapshot = true
|
|
|
|
} else {
|
|
|
|
log.WithError(errors.WithStack(err)).Errorf("Error running command=%s, stdout=%s, stderr=%s", resticCmd.String(), stdout, stderr)
|
|
|
|
return c.fail(req, fmt.Sprintf("error running restic backup, stderr=%s: %s", stderr, err.Error()), log)
|
|
|
|
}
|
2018-02-28 01:35:35 +00:00
|
|
|
}
|
|
|
|
log.Debugf("Ran command=%s, stdout=%s, stderr=%s", resticCmd.String(), stdout, stderr)
|
|
|
|
|
2019-05-30 16:48:21 +00:00
|
|
|
var snapshotID string
|
|
|
|
if !emptySnapshot {
|
Use Credential from BSL for restic commands (#3489)
* Use Credential from BSL for restic commands
This change introduces support for restic to make use of per-BSL
credentials. It makes use of the `credentials.FileStore` introduced in
PR #3442 to write the BSL credentials to disk. To support per-BSL
credentials for restic, the environment for the restic commands needs to
be modified for each provider to ensure that the credentials are
provided via the correct provider specific environment variables.
This change introduces a new function `restic.CmdEnv` to check the BSL
provider and create the correct mapping of environment variables for
each provider.
Previously, AWS and GCP could rely on the environment variables in the
Velero deployments to obtain the credentials file, but now these
environment variables need to be set with the path to the serialized
credentials file if a credential is set on the BSL.
For Azure, the credentials file in the environment was loaded and parsed
to set the environment variables for restic. Now, we check if the BSL
has a credential, and if it does, load and parse that file instead.
This change also introduces a few other small improvements. Now that we
are fetching the BSL to check for the `Credential` field, we can use the
BSL directly to get the `CACert` which means that we can remove the
`GetCACert` function. Also, now that we have a way to serialize secrets
to disk, we can use the `credentials.FileStore` to get a temp file for
the restic repo password and remove the `restic.TempCredentialsFile`
function.
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Add documentation for per-BSL credentials
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review feedback
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
* Address review comments
Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
2021-03-11 18:10:51 +00:00
|
|
|
cmd := restic.GetSnapshotCommand(req.Spec.RepoIdentifier, credentialsFile, req.Spec.Tags)
|
|
|
|
cmd.Env = env
|
|
|
|
cmd.CACertFile = caCertFile
|
|
|
|
|
|
|
|
snapshotID, err = restic.GetSnapshotID(cmd)
|
2019-05-30 16:48:21 +00:00
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("Error getting SnapshotID")
|
|
|
|
return c.fail(req, errors.Wrap(err, "error getting snapshot id").Error(), log)
|
|
|
|
}
|
2018-02-28 01:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update status to Completed with path & snapshot id
|
2019-01-25 03:33:07 +00:00
|
|
|
req, err = c.patchPodVolumeBackup(req, func(r *velerov1api.PodVolumeBackup) {
|
2018-02-28 01:35:35 +00:00
|
|
|
r.Status.Path = path
|
2019-01-25 03:33:07 +00:00
|
|
|
r.Status.Phase = velerov1api.PodVolumeBackupPhaseCompleted
|
2019-05-30 16:48:21 +00:00
|
|
|
r.Status.SnapshotID = snapshotID
|
2019-10-14 16:20:28 +00:00
|
|
|
r.Status.CompletionTimestamp = &metav1.Time{Time: c.clock.Now()}
|
2019-05-30 16:48:21 +00:00
|
|
|
if emptySnapshot {
|
|
|
|
r.Status.Message = "volume was empty so no snapshot was taken"
|
|
|
|
}
|
2018-02-28 01:35:35 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2019-06-28 15:58:02 +00:00
|
|
|
log.WithError(err).Error("Error setting PodVolumeBackup phase to Completed")
|
2018-02-28 01:35:35 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-07-22 19:07:52 +00:00
|
|
|
latencyDuration := req.Status.CompletionTimestamp.Time.Sub(req.Status.StartTimestamp.Time)
|
|
|
|
latencySeconds := float64(latencyDuration / time.Second)
|
|
|
|
backupName := getOwningBackup(req)
|
2020-11-23 16:28:34 +00:00
|
|
|
c.metrics.ObserveResticOpLatency(c.nodeName, req.Name, resticCmd.Command, backupName, latencySeconds)
|
2020-07-22 19:07:52 +00:00
|
|
|
c.metrics.RegisterResticOpLatencyGauge(c.nodeName, req.Name, resticCmd.Command, backupName, latencySeconds)
|
|
|
|
c.metrics.RegisterPodVolumeBackupDequeue(c.nodeName)
|
2018-06-20 22:46:41 +00:00
|
|
|
log.Info("Backup completed")
|
|
|
|
|
2018-02-28 01:35:35 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-08-27 23:37:51 +00:00
|
|
|
// getParentSnapshot finds the most recent completed pod volume backup for the specified PVC and returns its
|
|
|
|
// restic snapshot ID. Any errors encountered are logged but not returned since they do not prevent a backup
|
|
|
|
// from proceeding.
|
2020-02-19 19:01:22 +00:00
|
|
|
func getParentSnapshot(log logrus.FieldLogger, pvcUID, backupStorageLocation string, podVolumeBackupLister listers.PodVolumeBackupNamespaceLister) string {
|
2019-08-27 23:37:51 +00:00
|
|
|
log = log.WithField("pvcUID", pvcUID)
|
|
|
|
log.Infof("Looking for most recent completed pod volume backup for this PVC")
|
|
|
|
|
|
|
|
pvcBackups, err := podVolumeBackupLister.List(labels.SelectorFromSet(map[string]string{velerov1api.PVCUIDLabel: pvcUID}))
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(errors.WithStack(err)).Error("Error listing pod volume backups for PVC")
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// go through all the pod volume backups for the PVC and look for the most recent completed one
|
|
|
|
// to use as the parent.
|
|
|
|
var mostRecentBackup *velerov1api.PodVolumeBackup
|
|
|
|
for _, backup := range pvcBackups {
|
|
|
|
if backup.Status.Phase != velerov1api.PodVolumeBackupPhaseCompleted {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-02-19 19:01:22 +00:00
|
|
|
if backupStorageLocation != backup.Spec.BackupStorageLocation {
|
|
|
|
// Check the backup storage location is the same as spec in order to support backup to multiple backup-locations.
|
|
|
|
// Otherwise, there exists a case that backup volume snapshot to the second location would failed, since the founded
|
|
|
|
// parent ID is only valid for the first backup location, not the second backup location.
|
|
|
|
// Also, the second backup should not use the first backup parent ID since its for the first backup location only.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-08-27 23:37:51 +00:00
|
|
|
if mostRecentBackup == nil || backup.Status.StartTimestamp.After(mostRecentBackup.Status.StartTimestamp.Time) {
|
|
|
|
mostRecentBackup = backup
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if mostRecentBackup == nil {
|
|
|
|
log.Info("No completed pod volume backup found for PVC")
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
log.WithFields(map[string]interface{}{
|
|
|
|
"parentPodVolumeBackup": mostRecentBackup.Name,
|
|
|
|
"parentSnapshotID": mostRecentBackup.Status.SnapshotID,
|
|
|
|
}).Info("Found most recent completed pod volume backup for PVC")
|
|
|
|
|
|
|
|
return mostRecentBackup.Status.SnapshotID
|
|
|
|
}
|
|
|
|
|
2019-01-25 03:33:07 +00:00
|
|
|
func (c *podVolumeBackupController) patchPodVolumeBackup(req *velerov1api.PodVolumeBackup, mutate func(*velerov1api.PodVolumeBackup)) (*velerov1api.PodVolumeBackup, error) {
|
2018-02-28 01:35:35 +00:00
|
|
|
// Record original json
|
|
|
|
oldData, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error marshalling original PodVolumeBackup")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mutate
|
|
|
|
mutate(req)
|
|
|
|
|
|
|
|
// Record new json
|
|
|
|
newData, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error marshalling updated PodVolumeBackup")
|
|
|
|
}
|
|
|
|
|
|
|
|
patchBytes, err := jsonpatch.CreateMergePatch(oldData, newData)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error creating json merge patch for PodVolumeBackup")
|
|
|
|
}
|
|
|
|
|
k8s 1.18 import (#2651)
* k8s 1.18 import wip
backup, cmd, controller, generated, restic, restore, serverstatusrequest, test and util
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* go mod tidy
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* add changelog file
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* go fmt
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* update code-generator and controller-gen in CI
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* checkout proper code-generator version, regen
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* fix remaining calls
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* regenerate CRDs with ./hack/update-generated-crd-code.sh
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* use existing context in restic and server
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* fix test cases by resetting resource version
also use main library go context, not golang.org/x/net/context, in pkg/restore/restore.go
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* clarify changelog message
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* use github.com/kubernetes-csi/external-snapshotter/v2@v2.2.0-rc1
Signed-off-by: Andrew Lavery <laverya@umich.edu>
* run 'go mod tidy' to remove old external-snapshotter version
Signed-off-by: Andrew Lavery <laverya@umich.edu>
2020-07-16 16:21:37 +00:00
|
|
|
req, err = c.podVolumeBackupClient.PodVolumeBackups(req.Namespace).Patch(context.TODO(), req.Name, types.MergePatchType, patchBytes, metav1.PatchOptions{})
|
2018-02-28 01:35:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error patching PodVolumeBackup")
|
|
|
|
}
|
|
|
|
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2019-09-10 18:28:19 +00:00
|
|
|
// updateBackupProgressFunc returns a func that takes progress info and patches
|
|
|
|
// the PVB with the new progress
|
|
|
|
func (c *podVolumeBackupController) updateBackupProgressFunc(req *velerov1api.PodVolumeBackup, log logrus.FieldLogger) func(velerov1api.PodVolumeOperationProgress) {
|
|
|
|
return func(progress velerov1api.PodVolumeOperationProgress) {
|
|
|
|
if _, err := c.patchPodVolumeBackup(req, func(r *velerov1api.PodVolumeBackup) {
|
|
|
|
r.Status.Progress = progress
|
|
|
|
}); err != nil {
|
|
|
|
log.WithError(err).Error("error updating PodVolumeBackup progress")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 03:33:07 +00:00
|
|
|
func (c *podVolumeBackupController) fail(req *velerov1api.PodVolumeBackup, msg string, log logrus.FieldLogger) error {
|
|
|
|
if _, err := c.patchPodVolumeBackup(req, func(r *velerov1api.PodVolumeBackup) {
|
|
|
|
r.Status.Phase = velerov1api.PodVolumeBackupPhaseFailed
|
2018-02-28 01:35:35 +00:00
|
|
|
r.Status.Message = msg
|
2019-10-14 16:20:28 +00:00
|
|
|
r.Status.CompletionTimestamp = &metav1.Time{Time: c.clock.Now()}
|
2018-02-28 01:35:35 +00:00
|
|
|
}); err != nil {
|
2019-06-28 15:58:02 +00:00
|
|
|
log.WithError(err).Error("Error setting PodVolumeBackup phase to Failed")
|
2018-02-28 01:35:35 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func singlePathMatch(path string) (string, error) {
|
|
|
|
matches, err := filepath.Glob(path)
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(matches) != 1 {
|
|
|
|
return "", errors.Errorf("expected one matching path, got %d", len(matches))
|
|
|
|
}
|
|
|
|
|
|
|
|
return matches[0], nil
|
|
|
|
}
|