Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Kramarenko <[email protected]>
  • Loading branch information
ViktorKram committed Mar 7, 2024
1 parent 256f08a commit b05a51c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions images/agent/cmd/bc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ var (
)

func main() {

ctx := context.Background()

cfgParams, err := config.NewConfig()
Expand Down Expand Up @@ -125,7 +124,7 @@ func main() {
os.Exit(1)
}

if _, err = controller.RunLVMLogicalVolumeWatcherController(mgr, *cfgParams, *log, cfgParams.Loglevel, metrics); err != nil {
if _, err = controller.RunLVMLogicalVolumeWatcherController(mgr, *cfgParams, *log, metrics); err != nil {
log.Error(err, "[main] unable to controller.RunLVMLogicalVolumeWatcherController")
os.Exit(1)
}
Expand Down
22 changes: 11 additions & 11 deletions images/agent/pkg/controller/lvm_logical_volume_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func RunLVMLogicalVolumeWatcherController(
mgr manager.Manager,
cfg config.Options,
log logger.Logger,
logLevel logger.Verbosity,
metrics monitoring.Metrics,
) (controller.Controller, error) {
cl := mgr.GetClient()
Expand Down Expand Up @@ -118,11 +117,13 @@ func RunLVMLogicalVolumeWatcherController(
}
log.Trace("[RunLVMLogicalVolumeWatcherController] UpdateFunc get new LVMLogicalVolume: ", newLLV.Name, newLLV)

if logLevel == "4" {
// TODO: Figure out how to log it in our logger.
if cfg.Loglevel == "4" {
fmt.Println("==============START DIFF==================")
fmt.Println(cmp.Diff(oldLLV, newLLV))
fmt.Println("==============END DIFF==================")
}

if reflect.DeepEqual(oldLLV.Spec, newLLV.Spec) && newLLV.DeletionTimestamp == nil {
log.Info(fmt.Sprintf("[UpdateFunc] the LVMLogicalVolume %s has not been changed", newLLV.Name))
log.Info(fmt.Sprintf("[RunLVMLogicalVolumeWatcherController] UpdateFunc ends reconciliation of LLV: %s", newLLV.Name))
Expand Down Expand Up @@ -293,13 +294,12 @@ func removeLLVFinalizersIfExist(
}

func deleteLVIfExists(log logger.Logger, vgName, lvName string) error {

exists, _, err := FindLV(log, vgName, lvName)
lv, err := FindLV(log, vgName, lvName)
if err != nil {
return err
}

if !exists {
if lv == nil {
log.Warning(fmt.Sprintf("[deleteLVIfExists] did not find LV %s in VG %s", lvName, vgName))
return nil
}
Expand Down Expand Up @@ -648,12 +648,12 @@ func shouldReconcileByCreateFunc(log logger.Logger, vgName string, llv *v1alpha1
return false, nil
}

exists, _, err := FindLV(log, vgName, llv.Spec.ActualLVNameOnTheNode)
lv, err := FindLV(log, vgName, llv.Spec.ActualLVNameOnTheNode)
if err != nil {
return false, err
}

if exists {
if lv != nil {
return false, nil
}

Expand Down Expand Up @@ -760,21 +760,21 @@ func updateLVMLogicalVolume(ctx context.Context, metrics monitoring.Metrics, cl
return err
}

func FindLV(log logger.Logger, vgName, lvName string) (bool, internal.LVData, error) {
func FindLV(log logger.Logger, vgName, lvName string) (*internal.LVData, error) {
lvs, cmd, _, err := utils.GetAllLVs()
log.Debug(fmt.Sprintf("[FindLV] runs cmd: %s", cmd))
if err != nil {
log.Error(err, "[shouldReconcileByCreateFunc] unable to GetAllLVs")
return false, internal.LVData{}, err
return &internal.LVData{}, err
}

log.Debug(fmt.Sprintf("[FindLV] Try to find LV: %s in VG: %s", lvName, vgName))
for _, lv := range lvs {
log.Trace(fmt.Sprintf("[FindLV] processing LV: %s, VG: %s", lv.LVName, lv.VGName))
if lv.VGName == vgName && lv.LVName == lvName {
return true, lv, nil
return &lv, nil
}
}

return false, internal.LVData{}, nil
return &internal.LVData{}, nil
}

0 comments on commit b05a51c

Please sign in to comment.