Skip to content

Commit

Permalink
also move snapshots restore to EE
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Stefurishin <[email protected]>
  • Loading branch information
astef committed Dec 20, 2024
1 parent eaa249f commit 14e1e82
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
14 changes: 14 additions & 0 deletions images/agent/src/internal/controller/llv/llvs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build !ee

package llv

import (
"context"
"errors"

"github.com/deckhouse/sds-node-configurator/api/v1alpha1"
)

func (r *Reconciler) handleLLVSSource(_ context.Context, _ *v1alpha1.LVMLogicalVolume, _ *v1alpha1.LVMVolumeGroup) (string, bool, error) {
return "", false, errors.New("LLVS as a source is not supported")
}
29 changes: 29 additions & 0 deletions images/agent/src/internal/controller/llv/llvs_ee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//go:build ee

package llv

import (
"agent/internal/utils"
"context"
"errors"
"fmt"

"github.com/deckhouse/sds-node-configurator/api/v1alpha1"
"k8s.io/apimachinery/pkg/types"
)

func (r *Reconciler) handleLLVSSource(ctx context.Context, llv *v1alpha1.LVMLogicalVolume, lvg *v1alpha1.LVMVolumeGroup) (string, bool, error) {
sourceLLVS := &v1alpha1.LVMLogicalVolumeSnapshot{}
if err := r.cl.Get(ctx, types.NamespacedName{Name: llv.Spec.Source.Name}, sourceLLVS); err != nil {
r.log.Error(err, fmt.Sprintf("[reconcileLLVCreateFunc] unable to get source LVMLogicalVolumeSnapshot %s for the LVMLogicalVolume %s", llv.Spec.Source.Name, llv.Name))
return "", true, err
}

if sourceLLVS.Status.ActualVGNameOnTheNode != lvg.Spec.ActualVGNameOnTheNode || sourceLLVS.Status.NodeName != lvg.Spec.Local.NodeName {
return "", false, errors.New("restored volume should be in the same volume group as the origin volume")
}

cmd, err := utils.CreateThinLogicalVolumeFromSource(llv.Spec.ActualLVNameOnTheNode, sourceLLVS.Status.ActualVGNameOnTheNode, sourceLLVS.Spec.ActualSnapshotNameOnTheNode)

return cmd, err != nil, err
}
14 changes: 4 additions & 10 deletions images/agent/src/internal/controller/llv/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,11 @@ func (r *Reconciler) reconcileLLVCreateFunc(

cmd, err = utils.CreateThinLogicalVolumeFromSource(llv.Spec.ActualLVNameOnTheNode, lvg.Spec.ActualVGNameOnTheNode, sourceLLV.Spec.ActualLVNameOnTheNode)
case llv.Spec.Source.Kind == "LVMLogicalVolumeSnapshot":
sourceLLVS := &v1alpha1.LVMLogicalVolumeSnapshot{}
if err := r.cl.Get(ctx, types.NamespacedName{Name: llv.Spec.Source.Name}, sourceLLVS); err != nil {
r.log.Error(err, fmt.Sprintf("[reconcileLLVCreateFunc] unable to get source LVMLogicalVolumeSnapshot %s for the LVMLogicalVolume %s", llv.Spec.Source.Name, llv.Name))
return true, err
}

if sourceLLVS.Status.ActualVGNameOnTheNode != lvg.Spec.ActualVGNameOnTheNode || sourceLLVS.Status.NodeName != lvg.Spec.Local.NodeName {
return false, errors.New("restored volume should be in the same volume group as the origin volume")
cmdTmp, shouldRequeue, err := r.handleLLVSSource(ctx, llv, lvg)
if err != nil {
return shouldRequeue, err
}

cmd, err = utils.CreateThinLogicalVolumeFromSource(llv.Spec.ActualLVNameOnTheNode, sourceLLVS.Status.ActualVGNameOnTheNode, sourceLLVS.Spec.ActualSnapshotNameOnTheNode)
cmd = cmdTmp
}
r.log.Debug(fmt.Sprintf("[reconcileLLVCreateFunc] ran cmd: %s", cmd))
if err != nil {
Expand Down

0 comments on commit 14e1e82

Please sign in to comment.