Skip to content

Commit

Permalink
fix review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandr Stefurishin <[email protected]>
  • Loading branch information
Alexandr Stefurishin committed Nov 12, 2024
1 parent 84919b4 commit 8b20028
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 106 deletions.
15 changes: 8 additions & 7 deletions api/v1alpha1/lvm_logical_volume_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ type LVMLogicalVolumeSnapshot struct {

// +k8s:deepcopy-gen=true
type LVMLogicalVolumeSnapshotSpec struct {
NodeName string `json:"nodeName"`
LVMVolumeGroupName string `json:"lvmVolumeGroupName"`
LVMLogicalVolumeName string `json:"lvmLogicalVolumeName"`
NodeName string `json:"nodeName"`
ActualVGNameOnTheNode string `json:"actualVGNameOnTheNode"`
ActualLVNameOnTheNode string `json:"actualLVNameOnTheNode"`
ActualSnapshotNameOnTheNode string `json:"actualSnapshotNameOnTheNode"`
}

// +k8s:deepcopy-gen=true
type LVMLogicalVolumeSnapshotStatus struct {
Phase string `json:"phase"`
Reason string `json:"reason"`
Size resource.Quantity `json:"size"`
ActualSize resource.Quantity `json:"actualSize"`
Phase string `json:"phase"`
Reason string `json:"reason"`
Size resource.Quantity `json:"size"`
UsedSize resource.Quantity `json:"usedSize"`
}

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

20 changes: 14 additions & 6 deletions crds/lvmlogicalvolumesnapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,26 @@ spec:
- rule: self == oldSelf
message: Value is immutable.
minLength: 1
lvmVolumeGroupName:
actualVGNameOnTheNode:
type: string
description: |
The name of the volume group, where the snapshot resides in.
x-kubernetes-validations:
- rule: self == oldSelf
message: Value is immutable.
minLength: 1
lvmLogicalVolumeName:
actualLVNameOnTheNode:
type: string
description: |
The name of the LVMLogicalVolume resource the snapshot is created from.
The name of the volume the snapshot is created from.
x-kubernetes-validations:
- rule: self == oldSelf
message: Value is immutable.
minLength: 1
actualSnapshotNameOnTheNode:
type: string
description: |
The name of the snapshot volume.
x-kubernetes-validations:
- rule: self == oldSelf
message: Value is immutable.
Expand All @@ -77,7 +85,7 @@ spec:
description: |
Snapshotted LV size on the node.
type: string
actualSize:
usedSize:
description: |
Snapshot LV size on the node.
type: string
Expand All @@ -96,7 +104,7 @@ spec:
name: Size
type: string
description: Snapshotted LV size.
- jsonPath: .status.actualSize
name: ActualSize
- jsonPath: .status.usedSize
name: UsedSize
type: string
description: Snapshot size.
43 changes: 34 additions & 9 deletions images/agent/src/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ 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 @@ -214,21 +215,45 @@ func main() {
os.Exit(1)
}

err = controller.AddReconciler(mgr, log, llv_extender.NewReconciler(
mgr.GetClient(),
err = controller.AddReconciler(
mgr,
log,
metrics,
sdsCache,
llv_extender.ReconcilerConfig{
NodeName: cfgParams.NodeName,
VolumeGroupScanInterval: cfgParams.VolumeGroupScanInterval,
},
))
llv_extender.NewReconciler(
mgr.GetClient(),
log,
metrics,
sdsCache,
llv_extender.ReconcilerConfig{
NodeName: cfgParams.NodeName,
VolumeGroupScanInterval: cfgParams.VolumeGroupScanInterval,
},
),
)
if err != nil {
log.Error(err, "[main] unable to controller.RunLVMLogicalVolumeExtenderWatcherController")
os.Exit(1)
}

err = controller.AddReconciler(
mgr,
log,
llvs.NewReconciler(
mgr.GetClient(),
log,
metrics,
sdsCache,
llvs.ReconcilerConfig{
NodeName: cfgParams.NodeName,
LLVRequeueInterval: cfgParams.LLVRequeueInterval,
LLVSRequeueInterval: cfgParams.LLVSRequeueInterval,
},
),
)
if err != nil {
log.Error(err, "[main] unable to start llvs.NewReconciler")
os.Exit(1)
}

if err = mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
log.Error(err, "[main] unable to mgr.AddHealthzCheck")
os.Exit(1)
Expand Down
3 changes: 3 additions & 0 deletions images/agent/src/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Config struct {
BlockDeviceScanInterval time.Duration
VolumeGroupScanInterval time.Duration
LLVRequeueInterval time.Duration
LLVSRequeueInterval time.Duration
ThrottleInterval time.Duration
CmdDeadlineDuration time.Duration
HealthProbeBindAddress string
Expand Down Expand Up @@ -90,6 +91,7 @@ func NewConfig() (*Config, error) {
cfg.BlockDeviceScanInterval = 5 * time.Second
cfg.VolumeGroupScanInterval = 5 * time.Second
cfg.LLVRequeueInterval = 5 * time.Second
cfg.LLVSRequeueInterval = 5 * time.Second
} else {
interval, err := strconv.Atoi(scanInt)
if err != nil {
Expand All @@ -98,6 +100,7 @@ func NewConfig() (*Config, error) {
cfg.BlockDeviceScanInterval = time.Duration(interval) * time.Second
cfg.VolumeGroupScanInterval = time.Duration(interval) * time.Second
cfg.LLVRequeueInterval = time.Duration(interval) * time.Second
cfg.LLVSRequeueInterval = time.Duration(interval) * time.Second
}

thrInt := os.Getenv(ThrottleInterval)
Expand Down
1 change: 1 addition & 0 deletions images/agent/src/internal/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const (
LLVSStatusPhaseCreated = "Created"
LLVSStatusPhasePending = "Pending"
LLVSStatusPhaseFailed = "Failed"
LLVSNameTag = "storage.deckhouse.io/lvmLogicalVolumeSnapshotName"

Local = "Local"
Shared = "Shared"
Expand Down
2 changes: 1 addition & 1 deletion images/agent/src/internal/controller/bd/discoverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (d *Discoverer) getBlockDeviceCandidates() []internal.BlockDeviceCandidate
if pv.PVName == device.Name {
d.log.Trace(fmt.Sprintf("[GetBlockDeviceCandidates] The device is a PV. Found PV name: %s", pv.PVName))
if candidate.FSType == internal.LVMFSType {
hasTag, lvmVGName := utils.CheckTag(pv.VGTags)
hasTag, lvmVGName := utils.ReadValueFromTags(pv.VGTags, internal.LVMVolumeGroupTag)
if hasTag {
d.log.Debug(fmt.Sprintf("[GetBlockDeviceCandidates] PV %s of BlockDevice %s has tag, fill the VG information", pv.PVName, candidate.Name))
candidate.PVUuid = pv.PVUuid
Expand Down
4 changes: 2 additions & 2 deletions images/agent/src/internal/controller/bd/discoverer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ func TestBlockDeviceCtrl(t *testing.T) {
expectedName := "testName"
tags := fmt.Sprintf("storage.deckhouse.io/enabled=true,storage.deckhouse.io/lvmVolumeGroupName=%s", expectedName)

shouldBeTrue, actualName := utils.CheckTag(tags)
shouldBeTrue, actualName := utils.ReadValueFromTags(tags, internal.LVMVolumeGroupTag)
if assert.True(t, shouldBeTrue) {
assert.Equal(t, expectedName, actualName)
}
Expand All @@ -559,7 +559,7 @@ func TestBlockDeviceCtrl(t *testing.T) {
t.Run("Haven't tag_Returns false and empty", func(t *testing.T) {
tags := "someWeirdTags=oMGwtFIsThis"

shouldBeFalse, actualName := utils.CheckTag(tags)
shouldBeFalse, actualName := utils.ReadValueFromTags(tags, internal.LVMVolumeGroupTag)
if assert.False(t, shouldBeFalse) {
assert.Equal(t, "", actualName)
}
Expand Down
6 changes: 6 additions & 0 deletions images/agent/src/internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Named interface {
type Reconciler[T client.Object] interface {
Named
MaxConcurrentReconciles() int
ShouldReconcileCreate(objectNew T) bool
ShouldReconcileUpdate(objectOld T, objectNew T) bool
Reconcile(context.Context, ReconcileRequest[T]) (Result, error)
}
Expand Down Expand Up @@ -86,6 +87,11 @@ func AddReconciler[T client.Object](
e event.TypedCreateEvent[T],
q workqueue.TypedRateLimitingInterface[reconcile.Request],
) {
if !reconciler.ShouldReconcileCreate(e.Object) {
log.Debug(fmt.Sprintf("createFunc skipped a request for the %s %s to the Reconcilers queue", tname, e.Object.GetName()))
return
}

log.Info(fmt.Sprintf("createFunc got a create event for the %s, name: %s", tname, e.Object.GetName()))

request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.Object.GetNamespace(), Name: e.Object.GetName()}}
Expand Down
7 changes: 6 additions & 1 deletion images/agent/src/internal/controller/llv/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func (r *Reconciler) MaxConcurrentReconciles() int {
return 10
}

// ShouldReconcileCreate implements controller.Reconciler.
func (r *Reconciler) ShouldReconcileCreate(_ *v1alpha1.LVMLogicalVolume) bool {
return true
}

// ShouldReconcileUpdate implements controller.Reconciler.
func (r *Reconciler) ShouldReconcileUpdate(objectOld *v1alpha1.LVMLogicalVolume, objectNew *v1alpha1.LVMLogicalVolume) bool {
r.log.Info(fmt.Sprintf("[RunLVMLogicalVolumeWatcherController] got an update event for the LVMLogicalVolume: %s", objectNew.GetName()))
Expand Down Expand Up @@ -429,7 +434,7 @@ func (r *Reconciler) reconcileLLVDeleteFunc(

err = r.removeLLVFinalizersIfExist(ctx, llv)
if err != nil {
r.log.Error(err, fmt.Sprintf("[reconcileLLVDeleteFunc] unable to remove finalizers from the LVMVolumeGroup %s", llv.Name))
r.log.Error(err, fmt.Sprintf("[reconcileLLVDeleteFunc] unable to remove finalizers from the LVMLogicalVolume %s", llv.Name))
return true, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func (r *Reconciler) ShouldReconcileUpdate(_ *v1alpha1.LVMVolumeGroup, _ *v1alph
return true
}

// ShouldReconcileCreate implements controller.Reconciler.
func (r *Reconciler) ShouldReconcileCreate(_ *v1alpha1.LVMVolumeGroup) bool {
return true
}

// Reconcile implements controller.Reconciler.
func (r *Reconciler) Reconcile(
ctx context.Context,
Expand Down
Loading

0 comments on commit 8b20028

Please sign in to comment.