mirror of
https://github.com/kubevirt/containerized-data-importer.git
synced 2025-06-03 06:30:22 +00:00

* touch up zero restoresize snapshot Signed-off-by: Michael Henriksen <mhenriks@redhat.com> * clone populator only supports PVC source now snapshot coming soon Signed-off-by: Michael Henriksen <mhenriks@redhat.com> * more unit tests Signed-off-by: Michael Henriksen <mhenriks@redhat.com> * unit test for clone populator Signed-off-by: Michael Henriksen <mhenriks@redhat.com> * func tests for clone populator Signed-off-by: Michael Henriksen <mhenriks@redhat.com> * move clone populator cleanup function to planner other review comments verifier pod should bount readonly Signed-off-by: Michael Henriksen <mhenriks@redhat.com> * add readonly flag to test executor pods synchronize get hash calls Signed-off-by: Michael Henriksen <mhenriks@redhat.com> * increase linter timeout Signed-off-by: Michael Henriksen <mhenriks@redhat.com> * better/explicit readonly support for test pods Signed-off-by: Michael Henriksen <mhenriks@redhat.com> * check pv for driver info before looking up storageclass as it may not exist Signed-off-by: Michael Henriksen <mhenriks@redhat.com> * addressed review comments Signed-off-by: Michael Henriksen <mhenriks@redhat.com> * chooseStrategy shoud generate more events Signed-off-by: Michael Henriksen <mhenriks@redhat.com> --------- Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package clone
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/go-logr/logr"
|
|
corev1 "k8s.io/api/core/v1"
|
|
"k8s.io/client-go/tools/record"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
|
|
|
cc "kubevirt.io/containerized-data-importer/pkg/controller/common"
|
|
)
|
|
|
|
// RebindPhase binds a PV from one PVC to another
|
|
type RebindPhase struct {
|
|
SourceNamespace string
|
|
SourceName string
|
|
TargetNamespace string
|
|
TargetName string
|
|
Client client.Client
|
|
Log logr.Logger
|
|
Recorder record.EventRecorder
|
|
}
|
|
|
|
var _ Phase = &RebindPhase{}
|
|
|
|
// Name returns the name of the phase
|
|
func (p *RebindPhase) Name() string {
|
|
return "Rebind"
|
|
}
|
|
|
|
// Reconcile rebinds a PV
|
|
func (p *RebindPhase) Reconcile(ctx context.Context) (*reconcile.Result, error) {
|
|
targetClaim := &corev1.PersistentVolumeClaim{}
|
|
exists, err := getResource(ctx, p.Client, p.TargetNamespace, p.TargetName, targetClaim)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if !exists {
|
|
return nil, fmt.Errorf("target claim does not exist")
|
|
}
|
|
|
|
if targetClaim.Spec.VolumeName != "" {
|
|
// guess we're all done
|
|
return nil, nil
|
|
}
|
|
|
|
sourceClaim := &corev1.PersistentVolumeClaim{}
|
|
exists, err = getResource(ctx, p.Client, p.SourceNamespace, p.SourceName, sourceClaim)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if !exists {
|
|
return nil, fmt.Errorf("source claim does not exist")
|
|
}
|
|
|
|
if err := cc.Rebind(ctx, p.Client, sourceClaim, targetClaim); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &reconcile.Result{}, nil
|
|
}
|