Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Kramarenko <viktor.kramarenko@flant.com>
  • Loading branch information
ViktorKram committed Feb 16, 2024
1 parent 7eac80c commit b666097
Show file tree
Hide file tree
Showing 34 changed files with 62 additions and 94 deletions.
3 changes: 0 additions & 3 deletions crds/lvmstorageclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ spec:
- WaitForFirstConsumer
allowVolumeExpansion:
type: boolean
x-kubernetes-validations:
- rule: self == oldSelf
message: Value is immutable.
description: |
Configure if Persistent Volume is going to be expandable.
lvmVolumeGroups:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-controller/api/v1alpha1/lvm_volume_group.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-controller/api/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-controller/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-controller/pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -98,27 +98,9 @@ func RunLVMStorageClassWatcherController(
return reconcile.Result{}, err
}

shouldRequeue := false
recType := identifyReconcileFunc(scList, lsc)
log.Debug(fmt.Sprintf("[LVMStorageClassReconciler] reconcile operation: %s", recType))
switch recType {
case CreateReconcile:
shouldRequeue, err = reconcileLSCCreateFunc(ctx, cl, log, scList, lsc)
if err != nil {
log.Error(err, fmt.Sprintf("[LVMStorageClassReconciler] an error occured while reconciles the LVMStorageClass, name: %s", lsc.Name))
}
case UpdateReconcile:
shouldRequeue, err = reconcileLSCUpdateFunc(ctx, cl, log, scList, lsc)
if err != nil {
log.Error(err, fmt.Sprintf("[LVMStorageClassReconciler] an error occured while reconciles the LVMStorageClass, name: %s", lsc.Name))
}
case DeleteReconcile:
shouldRequeue, err = reconcileLSCDeleteFunc(ctx, cl, log, scList, lsc)
if err != nil {
log.Error(err, fmt.Sprintf("[LVMStorageClassReconciler] an error occured while reconciles the LVMStorageClass, name: %s", lsc.Name))
}
default:
log.Debug(fmt.Sprintf("[LVMStorageClassReconciler] the LVMStorageClass %s should not be reconciled", lsc.Name))
shouldRequeue, err := runEventReconcile(ctx, cl, log, scList, lsc)
if err != nil {
log.Error(err, fmt.Sprintf("[LVMStorageClassReconciler] an error occured while reconciles the LVMStorageClass, name: %s", lsc.Name))
}

if shouldRequeue {
Expand Down Expand Up @@ -161,27 +143,9 @@ func RunLVMStorageClassWatcherController(
return
}

shouldRequeue := false
recType := identifyReconcileFunc(scList, lsc)
log.Debug(fmt.Sprintf("[CreateFunc] reconcile operation: %s", recType))
switch recType {
case CreateReconcile:
shouldRequeue, err = reconcileLSCCreateFunc(ctx, cl, log, scList, lsc)
if err != nil {
log.Error(err, fmt.Sprintf("[CreateFunc] an error occured while reconciles the LVMStorageClass, name: %s", lsc.Name))
}
case UpdateReconcile:
shouldRequeue, err = reconcileLSCUpdateFunc(ctx, cl, log, scList, lsc)
if err != nil {
log.Error(err, fmt.Sprintf("[CreateFunc] an error occured while reconciles the LVMStorageClass, name: %s", lsc.Name))
}
case DeleteReconcile:
shouldRequeue, err = reconcileLSCDeleteFunc(ctx, cl, log, scList, lsc)
if err != nil {
log.Error(err, fmt.Sprintf("[CreateFunc] an error occured while reconciles the LVMStorageClass, name: %s", lsc.Name))
}
default:
log.Debug(fmt.Sprintf("[CreateFunc] the LVMStorageClass %s should not be reconciled", lsc.Name))
shouldRequeue, err := runEventReconcile(ctx, cl, log, scList, lsc)
if err != nil {
log.Error(err, fmt.Sprintf("[CreateFunc] an error occured while reconciles the LVMStorageClass, name: %s", lsc.Name))
}

if shouldRequeue {
Expand Down Expand Up @@ -218,22 +182,9 @@ func RunLVMStorageClassWatcherController(
return
}

shouldRequeue := false
recType := identifyReconcileFunc(scList, lsc)
log.Debug(fmt.Sprintf("[UpdateFunc] reconcile operation: %s", recType))
switch recType {
case UpdateReconcile:
shouldRequeue, err = reconcileLSCUpdateFunc(ctx, cl, log, scList, lsc)
if err != nil {
log.Error(err, fmt.Sprintf("[UpdateFunc] an error occured while reconciles the LVMStorageClass, name: %s", lsc.Name))
}
case DeleteReconcile:
shouldRequeue, err = reconcileLSCDeleteFunc(ctx, cl, log, scList, lsc)
if err != nil {
log.Error(err, fmt.Sprintf("[UpdateFunc] an error occured while reconciles the LVMStorageClass, name: %s", lsc.Name))
}
default:
log.Debug(fmt.Sprintf("[UpdateFunc] the LVMStorageClass %s should not be reconciled", lsc.Name))
shouldRequeue, err := runEventReconcile(ctx, cl, log, scList, lsc)
if err != nil {
log.Error(err, fmt.Sprintf("[UpdateFunc] an error occured while reconciles the LVMStorageClass, name: %s", lsc.Name))
}

if shouldRequeue {
Expand All @@ -257,6 +208,26 @@ func RunLVMStorageClassWatcherController(
return c, nil
}

func runEventReconcile(ctx context.Context, cl client.Client, log logger.Logger, scList *v1.StorageClassList, lsc *v1alpha1.LvmStorageClass) (bool, error) {
recType := identifyReconcileFunc(scList, lsc)
log.Debug(fmt.Sprintf("[runEventReconcile] reconcile operation: %s", recType))
switch recType {
case CreateReconcile:
log.Debug(fmt.Sprintf("[runEventReconcile] CreateReconcile starts reconciliataion for the LVMStorageClass, name: %s", lsc.Name))
return reconcileLSCCreateFunc(ctx, cl, log, scList, lsc)
case UpdateReconcile:
log.Debug(fmt.Sprintf("[runEventReconcile] UpdateReconcile starts reconciliataion for the LVMStorageClass, name: %s", lsc.Name))
return reconcileLSCUpdateFunc(ctx, cl, log, scList, lsc)
case DeleteReconcile:
log.Debug(fmt.Sprintf("[runEventReconcile] DeleteReconcile starts reconciliataion for the LVMStorageClass, name: %s", lsc.Name))
return reconcileLSCDeleteFunc(ctx, cl, log, scList, lsc)
default:
log.Debug(fmt.Sprintf("[runEventReconcile] the LVMStorageClass %s should not be reconciled", lsc.Name))
}

return false, nil
}

func reconcileLSCDeleteFunc(
ctx context.Context,
cl client.Client,
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-controller/pkg/kubutils/kubernetes.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-controller/pkg/logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-controller/pkg/monitoring/monitoring.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/api/v1alpha1/lvm_logical_volume.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/api/v1alpha1/lvm_volume_group.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/api/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/api/v1alpha1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/config/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/driver/const.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/driver/controller.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/driver/driver.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/driver/health.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/driver/identity.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/driver/node.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/driver/type.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/pkg/kubutils/kubernetes.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/pkg/logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/pkg/utils/func.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-csi/pkg/utils/volume.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-scheduler-extender/api/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-scheduler-extender/config/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
2 changes: 1 addition & 1 deletion images/sds-lvm-scheduler-extender/pkg/logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Flant JSC
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down

0 comments on commit b666097

Please sign in to comment.