Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move LLVS to EE #114

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
.settings
.idea/
venv/
.vscode

# macOS Finder files
*.DS_Store
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/lvm_logical_volume_snapshot.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build ee

/*
Copyright 2024 Flant JSC

Expand All @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions api/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions images/agent/src/cmd/llvs.go
Original file line number Diff line number Diff line change
@@ -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
}
45 changes: 45 additions & 0 deletions images/agent/src/cmd/llvs_ee.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
22 changes: 1 addition & 21 deletions images/agent/src/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
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")
}
30 changes: 30 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,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
}
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build ee

package llvs

import (
Expand Down
Loading