diff --git a/.gitignore b/.gitignore index 5d3548aa..46eaf95e 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ .settings .idea/ venv/ +.vscode # macOS Finder files *.DS_Store diff --git a/api/v1alpha1/lvm_logical_volume_snapshot.go b/api/v1alpha1/lvm_logical_volume_snapshot.go index 38af8344..4e2e06ac 100644 --- a/api/v1alpha1/lvm_logical_volume_snapshot.go +++ b/api/v1alpha1/lvm_logical_volume_snapshot.go @@ -1,3 +1,5 @@ +//go:build ee + /* Copyright 2024 Flant JSC @@ -21,6 +23,14 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +func init() { + knownTypes = append( + knownTypes, + &LVMLogicalVolumeSnapshot{}, + &LVMLogicalVolumeSnapshotList{}, + ) +} + // +k8s:deepcopy-gen=true // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type LVMLogicalVolumeSnapshotList struct { diff --git a/api/v1alpha1/register.go b/api/v1alpha1/register.go index 41750972..dab4e856 100644 --- a/api/v1alpha1/register.go +++ b/api/v1alpha1/register.go @@ -37,20 +37,20 @@ var ( AddToScheme = SchemeBuilder.AddToScheme ) +var knownTypes = []runtime.Object{ + &BlockDevice{}, + &BlockDeviceList{}, + &LVMVolumeGroup{}, + &LVMVolumeGroupList{}, + &LVMLogicalVolume{}, + &LVMLogicalVolumeList{}, + &LVMVolumeGroupSet{}, + &LVMVolumeGroupSetList{}, +} + // Adds the list of known types to Scheme. func addKnownTypes(scheme *runtime.Scheme) error { - scheme.AddKnownTypes(SchemeGroupVersion, - &BlockDevice{}, - &BlockDeviceList{}, - &LVMVolumeGroup{}, - &LVMVolumeGroupList{}, - &LVMLogicalVolume{}, - &LVMLogicalVolumeList{}, - &LVMLogicalVolumeSnapshot{}, - &LVMLogicalVolumeSnapshotList{}, - &LVMVolumeGroupSet{}, - &LVMVolumeGroupSetList{}, - ) + scheme.AddKnownTypes(SchemeGroupVersion, knownTypes...) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil } diff --git a/api/v1alpha1/zz_generated_lvm_logical_volume_snapshot.deepcopy.go b/api/v1alpha1/zz_generated_lvm_logical_volume_snapshot.deepcopy.go index 9cc347d7..2f625e8e 100644 --- a/api/v1alpha1/zz_generated_lvm_logical_volume_snapshot.deepcopy.go +++ b/api/v1alpha1/zz_generated_lvm_logical_volume_snapshot.deepcopy.go @@ -1,5 +1,4 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated +//go:build !ignore_autogenerated && ee /* Copyright 2024 Flant JSC diff --git a/images/agent/src/cmd/llvs.go b/images/agent/src/cmd/llvs.go new file mode 100644 index 00000000..ea6841a1 --- /dev/null +++ b/images/agent/src/cmd/llvs.go @@ -0,0 +1,22 @@ +//go:build !ee + +package main + +import ( + "sigs.k8s.io/controller-runtime/pkg/manager" + + "agent/internal/cache" + "agent/internal/config" + "agent/internal/logger" + "agent/internal/monitoring" +) + +func addLLVSReconciler( + _ manager.Manager, + _ logger.Logger, + _ monitoring.Metrics, + _ *cache.Cache, + _ *config.Config, +) { + // noop +} diff --git a/images/agent/src/cmd/llvs_ee.go b/images/agent/src/cmd/llvs_ee.go new file mode 100644 index 00000000..bd0dec95 --- /dev/null +++ b/images/agent/src/cmd/llvs_ee.go @@ -0,0 +1,45 @@ +//go:build ee + +package main + +import ( + "os" + + "sigs.k8s.io/controller-runtime/pkg/manager" + + "agent/internal/cache" + "agent/internal/config" + "agent/internal/controller" + "agent/internal/controller/llvs" + "agent/internal/logger" + "agent/internal/monitoring" +) + +func addLLVSReconciler( + mgr manager.Manager, + log logger.Logger, + metrics monitoring.Metrics, + sdsCache *cache.Cache, + cfgParams *config.Config, +) { + err := controller.AddReconciler( + mgr, + log, + llvs.NewReconciler( + mgr.GetClient(), + log, + metrics, + sdsCache, + llvs.ReconcilerConfig{ + NodeName: cfgParams.NodeName, + LLVRequeueInterval: cfgParams.LLVRequeueInterval, + VolumeGroupScanInterval: cfgParams.VolumeGroupScanInterval, + LLVSRequeueInterval: cfgParams.LLVSRequeueInterval, + }, + ), + ) + if err != nil { + log.Error(err, "[main] unable to start llvs.NewReconciler") + os.Exit(1) + } +} diff --git a/images/agent/src/cmd/main.go b/images/agent/src/cmd/main.go index e0a4df6e..22a3e36f 100644 --- a/images/agent/src/cmd/main.go +++ b/images/agent/src/cmd/main.go @@ -38,7 +38,6 @@ import ( "agent/internal/controller/bd" "agent/internal/controller/llv" "agent/internal/controller/llv_extender" - "agent/internal/controller/llvs" "agent/internal/controller/lvg" "agent/internal/kubutils" "agent/internal/logger" @@ -234,26 +233,7 @@ func main() { os.Exit(1) } - err = controller.AddReconciler( - mgr, - log, - llvs.NewReconciler( - mgr.GetClient(), - log, - metrics, - sdsCache, - llvs.ReconcilerConfig{ - NodeName: cfgParams.NodeName, - LLVRequeueInterval: cfgParams.LLVRequeueInterval, - VolumeGroupScanInterval: cfgParams.VolumeGroupScanInterval, - LLVSRequeueInterval: cfgParams.LLVSRequeueInterval, - }, - ), - ) - if err != nil { - log.Error(err, "[main] unable to start llvs.NewReconciler") - os.Exit(1) - } + addLLVSReconciler(mgr, log, metrics, sdsCache, cfgParams) if err = mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { log.Error(err, "[main] unable to mgr.AddHealthzCheck") 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..1095e0de --- /dev/null +++ b/images/agent/src/internal/controller/llv/llvs_ee.go @@ -0,0 +1,30 @@ +//go:build ee + +package llv + +import ( + "context" + "errors" + "fmt" + + "github.com/deckhouse/sds-node-configurator/api/v1alpha1" + "k8s.io/apimachinery/pkg/types" + + "agent/internal/utils" +) + +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 { diff --git a/images/agent/src/internal/controller/llvs/reconciler.go b/images/agent/src/internal/controller/llvs/reconciler_ee.go similarity index 99% rename from images/agent/src/internal/controller/llvs/reconciler.go rename to images/agent/src/internal/controller/llvs/reconciler_ee.go index 694f66b0..05d2471b 100644 --- a/images/agent/src/internal/controller/llvs/reconciler.go +++ b/images/agent/src/internal/controller/llvs/reconciler_ee.go @@ -1,3 +1,5 @@ +//go:build ee + package llvs import (