diff --git a/images/agent/src/internal/controller/llv/llvs.go b/images/agent/src/internal/controller/llv/llvs.go new file mode 100644 index 00000000..34e87c62 --- /dev/null +++ b/images/agent/src/internal/controller/llv/llvs.go @@ -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") +} diff --git a/images/agent/src/internal/controller/llv/llvs_ee.go b/images/agent/src/internal/controller/llv/llvs_ee.go new file mode 100644 index 00000000..38330769 --- /dev/null +++ b/images/agent/src/internal/controller/llv/llvs_ee.go @@ -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 +} diff --git a/images/agent/src/internal/controller/llv/reconciler.go b/images/agent/src/internal/controller/llv/reconciler.go index afa1b0c0..bcc66a32 100644 --- a/images/agent/src/internal/controller/llv/reconciler.go +++ b/images/agent/src/internal/controller/llv/reconciler.go @@ -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 {