Skip to content

Commit

Permalink
labels
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Demchuk <[email protected]>
  • Loading branch information
NikolayDemchuk committed Jul 29, 2024
1 parent 02a04d4 commit 2c9258c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions images/agent/pkg/controller/lvm_volume_group_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (

const (
LVMVolumeGroupWatcherCtrlName = "lvm-volume-group-watcher-controller"
LVGHostnameLabelKey = "kubernetes.io/metadata.name"
)

func RunLVMVolumeGroupWatcherController(
Expand Down
27 changes: 27 additions & 0 deletions images/agent/pkg/controller/lvm_volume_group_watcher_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,39 @@ func checkIfVGExist(vgName string, vgs []internal.VGData) bool {
return false
}

func checkLabels(log logger.Logger, newLVG *v1alpha1.LvmVolumeGroup) bool {

if newLVG.Labels == nil {
log.Debug(fmt.Sprintf("[shouldLVGWatcherReconcileUpdateEvent] update event should be reconciled as the LVMVolumeGroup %s has no labels", newLVG.Name))
return false
}

labelValue, exist := newLVG.Labels[LVGHostnameLabelKey]

if !exist {
log.Debug(fmt.Sprintf("[shouldLVGWatcherReconcileUpdateEvent] update event should be reconciled as the LVMVolumeGroup %s has no label %s", newLVG.Name, LVGHostnameLabelKey))
return false
}

if labelValue != newLVG.Name {
log.Debug(fmt.Sprintf("[shouldLVGWatcherReconcileUpdateEvent] update event should be reconciled as the LVMVolumeGroup %s has label %s but the value is incorrect - %q, but should be %q", newLVG.Name, LVGHostnameLabelKey, labelValue, newLVG.Name))
return false
}

return true
}

func shouldLVGWatcherReconcileUpdateEvent(log logger.Logger, oldLVG, newLVG *v1alpha1.LvmVolumeGroup) bool {
if newLVG.DeletionTimestamp != nil {
log.Debug(fmt.Sprintf("[shouldLVGWatcherReconcileUpdateEvent] update event should be reconciled as the LVMVolumeGroup %s has deletionTimestamp", newLVG.Name))
return true
}

if !checkLabels(log, newLVG) {
log.Debug(fmt.Sprintf("[shouldLVGWatcherReconcileUpdateEvent] update event should be reconciled as the LVMVolumeGroup's %s labels have been changed", newLVG.Name))
return true
}

if !reflect.DeepEqual(oldLVG.Spec, newLVG.Spec) {
log.Debug(fmt.Sprintf("[shouldLVGWatcherReconcileUpdateEvent] update event should be reconciled as the LVMVolumeGroup %s configuration has been changed", newLVG.Name))
return true
Expand Down

0 comments on commit 2c9258c

Please sign in to comment.