From dc8922047c61abb7defcce0d49d138394fb4bfb4 Mon Sep 17 00:00:00 2001 From: Viktor Kram <92625690+ViktorKram@users.noreply.github.com> Date: Wed, 25 Sep 2024 12:12:19 +0300 Subject: [PATCH] [controller] Update sds-node-configuration api version (#83) Signed-off-by: Viktor Kramarenko --- docs/FAQ.md | 18 ++-- docs/FAQ.ru.md | 18 ++-- docs/README.md | 62 ++++++++----- docs/README.ru.md | 62 ++++++++----- images/sds-local-volume-controller/src/go.mod | 2 +- images/sds-local-volume-controller/src/go.sum | 4 + .../pkg/controller/local_csi_node_watcher.go | 16 ++-- .../controller/local_csi_node_watcher_test.go | 8 +- .../local_storage_class_watcher_func.go | 10 +-- .../local_storage_class_watcher_test.go | 30 +++---- .../src/driver/controller.go | 6 +- images/sds-local-volume-csi/src/go.mod | 2 +- images/sds-local-volume-csi/src/go.sum | 4 + .../src/internal/const.go | 2 +- .../src/pkg/utils/func.go | 32 +++---- .../src/go.mod | 2 +- .../src/go.sum | 4 + .../src/pkg/cache/cache.go | 12 +-- .../src/pkg/cache/cache_test.go | 88 +++++++++---------- .../src/pkg/consts/consts.go | 2 +- .../src/pkg/controller/lvg_watcher_cache.go | 10 +-- .../pkg/controller/lvg_watcher_cache_test.go | 36 ++++---- .../src/pkg/scheduler/filter.go | 22 ++--- images/webhooks/src/go.mod | 2 +- images/webhooks/src/go.sum | 4 + images/webhooks/src/handlers/lscValidator.go | 2 +- 26 files changed, 255 insertions(+), 205 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index c829a7fe..1813f6f9 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -120,14 +120,14 @@ You can verify this using the command: kubectl get node %node-name% --show-labels ``` -If the labels from `nodeSelector` are not present on the node, ensure that this node does not own any `LvmVolumeGroup` resources used by `LocalStorageClass` resources. More details about this check can be found [here](#how-to-check-if-there-are-dependent-resources-lvmvolumegroup-on-the-node). +If the labels from `nodeSelector` are not present on the node, ensure that this node does not own any `LVMVolumeGroup` resources used by `LocalStorageClass` resources. More details about this check can be found [here](#how-to-check-if-there-are-dependent-resources-lvmvolumegroup-on-the-node). -> Please note that on the `LvmVolumeGroup` and `LocalStorageClass` resources, which prevent the node from being taken out of the module's control, the label `storage.deckhouse.io/sds-local-volume-candidate-for-eviction` will be displayed. +> Please note that on the `LVMVolumeGroup` and `LocalStorageClass` resources, which prevent the node from being taken out of the module's control, the label `storage.deckhouse.io/sds-local-volume-candidate-for-eviction` will be displayed. On the node itself, the label `storage.deckhouse.io/sds-local-volume-need-manual-eviction` will be present. -## How to check if there are dependent resources `LvmVolumeGroup` on the node? +## How to check if there are dependent resources `LVMVolumeGroup` on the node? To check for such resources, follow these steps: 1. Display the existing `LocalStorageClass` resources @@ -135,7 +135,7 @@ To check for such resources, follow these steps: kubectl get lsc ``` -2. Check each of them for the list of used `LvmVolumeGroup` resources. +2. Check each of them for the list of used `LVMVolumeGroup` resources. > If you want to list all `LocalStorageClass` resources at once, run the command: > @@ -170,15 +170,15 @@ items: kind: List ``` -> Please pay attention to the `spec.lvm.lvmVolumeGroups` field - it specifies the used `LvmVolumeGroup` resources. +> Please pay attention to the `spec.lvm.lvmVolumeGroups` field - it specifies the used `LVMVolumeGroup` resources. -3. Display the list of existing `LvmVolumeGroup` resources. +3. Display the list of existing `LVMVolumeGroup` resources. ```shell kubectl get lvg ``` -An approximate representation of `LvmVolumeGroup` could be: +An approximate representation of `LVMVolumeGroup` could be: ```text NAME HEALTH NODE SIZE ALLOCATED SIZE VG AGE @@ -190,12 +190,12 @@ lvg-on-worker-4 Operational node-worker-4 307196Mi 0 test lvg-on-worker-5 Operational node-worker-5 204796Mi 0 test-vg 15d ``` -4. Ensure that the node you intend to remove from the module's control does not have any `LvmVolumeGroup` resources used in `LocalStorageClass` resources. +4. Ensure that the node you intend to remove from the module's control does not have any `LVMVolumeGroup` resources used in `LocalStorageClass` resources. > To avoid unintentionally losing control over volumes already created using the module, the user needs to manually delete dependent resources by performing necessary operations on the volume. ## I removed the labels from the node, but the `sds-local-volume-csi-node` pod is still there. Why did this happen? -Most likely, there are `LvmVolumeGroup` resources present on the node, which are used in one of the `LocalStorageClass` resources. +Most likely, there are `LVMVolumeGroup` resources present on the node, which are used in one of the `LocalStorageClass` resources. To avoid unintentionally losing control over volumes already created using the module, the user needs to manually delete dependent resources by performing necessary operations on the volume." diff --git a/docs/FAQ.ru.md b/docs/FAQ.ru.md index 63e23346..d264bd22 100644 --- a/docs/FAQ.ru.md +++ b/docs/FAQ.ru.md @@ -117,14 +117,14 @@ kubectl -n d8-sds-local-volume get po -owide kubectl get node %node-name% --show-labels ``` -Если метки из `nodeSelector` не присутствуют на узле, то убедитесь, что данному узлу не принадлежат `LvmVolumeGroup` ресурсы, использующиеся `LocalStorageClass` ресурсами. Подробнее об этой проверке можно прочитать [здесь](#как-проверить-имеются-ли-зависимые-ресурсы-lvmvolumegroup-на-узле). +Если метки из `nodeSelector` не присутствуют на узле, то убедитесь, что данному узлу не принадлежат `LVMVolumeGroup` ресурсы, использующиеся `LocalStorageClass` ресурсами. Подробнее об этой проверке можно прочитать [здесь](#как-проверить-имеются-ли-зависимые-ресурсы-lvmvolumegroup-на-узле). -> Обратите внимание, что на ресурсах `LvmVolumeGroup` и `LocalStorageClass`, из-за которых не удается вывести узел из-под управления модуля будет отображена метка `storage.deckhouse.io/sds-local-volume-candidate-for-eviction`. +> Обратите внимание, что на ресурсах `LVMVolumeGroup` и `LocalStorageClass`, из-за которых не удается вывести узел из-под управления модуля будет отображена метка `storage.deckhouse.io/sds-local-volume-candidate-for-eviction`. > > На самом узле будет присутствовать метка `storage.deckhouse.io/sds-local-volume-need-manual-eviction`. -## Как проверить, имеются ли зависимые ресурсы `LvmVolumeGroup` на узле? +## Как проверить, имеются ли зависимые ресурсы `LVMVolumeGroup` на узле? Для проверки таковых ресурсов необходимо выполнить следующие шаги: 1. Отобразить имеющиеся `LocalStorageClass` ресурсы @@ -132,7 +132,7 @@ kubectl get node %node-name% --show-labels kubectl get lsc ``` -2. Проверить у каждого из них список используемых `LvmVolumeGroup` ресурсов +2. Проверить у каждого из них список используемых `LVMVolumeGroup` ресурсов > Вы можете сразу отобразить содержимое всех `LocalStorageClass` ресурсов, выполнив команду: > @@ -167,15 +167,15 @@ items: kind: List ``` -> Обратите внимание на поле spec.lvm.lvmVolumeGroups - именно в нем указаны используемые `LvmVolumeGroup` ресурсы. +> Обратите внимание на поле spec.lvm.lvmVolumeGroups - именно в нем указаны используемые `LVMVolumeGroup` ресурсы. -3. Отобразите список существующих `LvmVolumeGroup` ресурсов +3. Отобразите список существующих `LVMVolumeGroup` ресурсов ```shell kubectl get lvg ``` -Примерный вывод `LvmVolumeGroup` ресурсов: +Примерный вывод `LVMVolumeGroup` ресурсов: ```text NAME HEALTH NODE SIZE ALLOCATED SIZE VG AGE @@ -187,12 +187,12 @@ lvg-on-worker-4 Operational node-worker-4 307196Mi 0 test lvg-on-worker-5 Operational node-worker-5 204796Mi 0 test-vg 15d ``` -4. Проверьте, что на узле, который вы собираетесь вывести из-под управления модуля, не присутствует какой-либо `LvmVolumeGroup` ресурс, используемый в `LocalStorageClass` ресурсах. +4. Проверьте, что на узле, который вы собираетесь вывести из-под управления модуля, не присутствует какой-либо `LVMVolumeGroup` ресурс, используемый в `LocalStorageClass` ресурсах. > Во избежание непредвиденной потери контроля за уже созданными с помощью модуля томами пользователю необходимо вручную удалить зависимые ресурсы, совершив необходимые операции над томом. ## Я убрал метки с узла, но pod `sds-local-volume-csi-node` остался. Почему так произошло? -Вероятнее всего, на узле присутствуют `LvmVolumeGroup` ресурсы, которые используются в одном из `LocalStorageClass` ресурсов. +Вероятнее всего, на узле присутствуют `LVMVolumeGroup` ресурсы, которые используются в одном из `LocalStorageClass` ресурсов. Во избежание непредвиденной потери контроля за уже созданными с помощью модуля томами пользователю необходимо вручную удалить зависимые ресурсы, совершив необходимые операции над томом. diff --git a/docs/README.md b/docs/README.md index f651da2a..285ad1ba 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,7 +5,7 @@ moduleStatus: preview --- This module manages local block storage based on `LVM`. The module allows you to create a `StorageClass` in `Kubernetes` by creating [Kubernetes custom resources](./cr.html) `LocalStorageClass` (see example below). -To create a `Storage Class`, you will need the `LvmVolumeGroup` configured on the cluster nodes. The `LVM` configuration is done by the [sds-node-configurator](../../sds-node-configurator/stable/) module. +To create a `Storage Class`, you will need the `LVMVolumeGroup` configured on the cluster nodes. The `LVM` configuration is done by the [sds-node-configurator](../../sds-node-configurator/stable/) module. > **Caution!** Before enabling the `sds-local-volume` module, you must enable the `sds-node-configurator` module. > After you enable the `sds-local-volume` module in the Deckhouse Kubernetes Platform configuration, you have to create StorageClasses. @@ -82,9 +82,9 @@ By default, the pods will be scheduled on all nodes in the cluster. You can veri ### Configuring storage on nodes -You need to create `LVM` volume groups on the nodes using `LvmVolumeGroup` custom resources. As part of this quickstart guide, we will create a regular `Thick` storage. +You need to create `LVM` volume groups on the nodes using `LVMVolumeGroup` custom resources. As part of this quickstart guide, we will create a regular `Thick` storage. -> Please ensure that the `sds-local-volume-csi-node` pod is running on the node before creating the `LvmVolumeGroup`. You can do this using the command: +> Please ensure that the `sds-local-volume-csi-node` pod is running on the node before creating the `LVMVolumeGroup`. You can do this using the command: > ```shell > kubectl -n d8-sds-local-volume get pod -owide @@ -106,24 +106,30 @@ dev-53d904f18b912187ac82de29af06a34d9ae23199 worker-2 false 976762584 dev-6c5abbd549100834c6b1668c8f89fb97872ee2b1 worker-2 false 894006140416 /dev/nvme0n1p6 ``` -- Create an [LvmVolumeGroup](../../sds-node-configurator/stable/cr.html#lvmvolumegroup) resource for `worker-0`: +- Create an [LVMVolumeGroup](../../sds-node-configurator/stable/cr.html#lvmvolumegroup) resource for `worker-0`: ```yaml kubectl apply -f - < **Внимание!** Перед включением модуля `sds-local-volume` необходимо включить модуль `sds-node-configurator`. > После включения модуля `sds-local-volume` необходимо создать StorageClass'ы. @@ -80,9 +80,9 @@ kubectl -n d8-sds-node-configurator get pod -o wide -w > Расположение данных pod-ов определяется специальными метками (nodeSelector), которые указываются в поле `spec.settings.dataNodes.nodeSelector` в настройках модуля. Для получения более подробной информации о настройке, пожалуйста, перейдите по [ссылке](./faq.html#я-не-хочу-чтобы-модуль-использовался-на-всех-узлах-кластера-как-мне-выбрать-желаемые-узлы) ### Настройка хранилища на узлах -Необходимо на этих узлах создать группы томов `LVM` с помощью пользовательских ресурсов `LvmVolumeGroup`. В быстром старте будем создавать обычное `Thick` хранилище. +Необходимо на этих узлах создать группы томов `LVM` с помощью пользовательских ресурсов `LVMVolumeGroup`. В быстром старте будем создавать обычное `Thick` хранилище. -> Пожалуйста, перед созданием `LvmVolumeGroup` убедитесь, что на данном узле запущен pod `sds-local-volume-csi-node`. Это можно сделать командой: +> Пожалуйста, перед созданием `LVMVolumeGroup` убедитесь, что на данном узле запущен pod `sds-local-volume-csi-node`. Это можно сделать командой: > > ```shell > kubectl -n d8-sds-local-volume get pod -owide @@ -104,24 +104,30 @@ kubectl -n d8-sds-node-configurator get pod -o wide -w dev-6c5abbd549100834c6b1668c8f89fb97872ee2b1 worker-2 false 894006140416 /dev/nvme0n1p6 ``` -- Создать ресурс [LvmVolumeGroup](../../sds-node-configurator/stable/cr.html#lvmvolumegroup) для узла `worker-0`: +- Создать ресурс [LVMVolumeGroup](../../sds-node-configurator/stable/cr.html#lvmvolumegroup) для узла `worker-0`: ```yaml kubectl apply -f - < 0 { lvmType = controller.LVMThinType } - thinPoolsSpec := make([]snc.LvmVolumeGroupThinPoolSpec, 0) - thinPoolsStatus := make([]snc.LvmVolumeGroupThinPoolStatus, 0) + thinPoolsSpec := make([]snc.LVMVolumeGroupThinPoolSpec, 0) + thinPoolsStatus := make([]snc.LVMVolumeGroupThinPoolStatus, 0) for i := 0; i < len(thinPoolNames); i++ { - thinPoolsSpec = append(thinPoolsSpec, snc.LvmVolumeGroupThinPoolSpec{ + thinPoolsSpec = append(thinPoolsSpec, snc.LVMVolumeGroupThinPoolSpec{ Name: thinPoolNames[i], Size: "10Gi", }) - thinPoolsStatus = append(thinPoolsStatus, snc.LvmVolumeGroupThinPoolStatus{ + thinPoolsStatus = append(thinPoolsStatus, snc.LVMVolumeGroupThinPoolStatus{ Name: thinPoolNames[i], ActualSize: resource.MustParse("10Gi"), UsedSize: resource.MustParse("0Gi"), }) } - return &snc.LvmVolumeGroup{ + return &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, - Spec: snc.LvmVolumeGroupSpec{ + Spec: snc.LVMVolumeGroupSpec{ ActualVGNameOnTheNode: "vg1", - BlockDeviceNames: devices, ThinPools: thinPoolsSpec, Type: lvmType, }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ ThinPools: thinPoolsStatus, }, } diff --git a/images/sds-local-volume-csi/src/driver/controller.go b/images/sds-local-volume-csi/src/driver/controller.go index 12520d00..fbd3e176 100644 --- a/images/sds-local-volume-csi/src/driver/controller.go +++ b/images/sds-local-volume-csi/src/driver/controller.go @@ -57,13 +57,13 @@ func (d *Driver) CreateVolume(ctx context.Context, request *csi.CreateVolumeRequ LvmType := request.GetParameters()[internal.LvmTypeKey] d.log.Info(fmt.Sprintf("[CreateVolume][traceID:%s][volumeID:%s] storage class LvmType: %s", traceID, volumeID, LvmType)) - if len(request.GetParameters()[internal.LvmVolumeGroupKey]) == 0 { + if len(request.GetParameters()[internal.LVMVolumeGroupKey]) == 0 { err := errors.New("no LVMVolumeGroups specified in a storage class's parameters") d.log.Error(err, fmt.Sprintf("[CreateVolume][traceID:%s][volumeID:%s] no LVMVolumeGroups were found for the request: %+v", traceID, volumeID, request)) return nil, status.Errorf(codes.InvalidArgument, err.Error()) } - storageClassLVGs, storageClassLVGParametersMap, err := utils.GetStorageClassLVGsAndParameters(ctx, d.cl, d.log, request.GetParameters()[internal.LvmVolumeGroupKey]) + storageClassLVGs, storageClassLVGParametersMap, err := utils.GetStorageClassLVGsAndParameters(ctx, d.cl, d.log, request.GetParameters()[internal.LVMVolumeGroupKey]) if err != nil { d.log.Error(err, fmt.Sprintf("[CreateVolume][traceID:%s][volumeID:%s] error GetStorageClassLVGs", traceID, volumeID)) return nil, status.Errorf(codes.Internal, err.Error()) @@ -321,7 +321,7 @@ func (d *Driver) ControllerExpandVolume(ctx context.Context, request *csi.Contro }, nil } - lvg, err := utils.GetLVMVolumeGroup(ctx, d.cl, llv.Spec.LvmVolumeGroupName, llv.Namespace) + lvg, err := utils.GetLVMVolumeGroup(ctx, d.cl, llv.Spec.LVMVolumeGroupName, llv.Namespace) if err != nil { d.log.Error(err, fmt.Sprintf("[ControllerExpandVolume][traceID:%s][volumeID:%s] error getting LVMVolumeGroup", traceID, volumeID)) return nil, status.Errorf(codes.Internal, "error getting LVMVolumeGroup: %v", err) diff --git a/images/sds-local-volume-csi/src/go.mod b/images/sds-local-volume-csi/src/go.mod index 070322e6..13e994c5 100644 --- a/images/sds-local-volume-csi/src/go.mod +++ b/images/sds-local-volume-csi/src/go.mod @@ -5,7 +5,7 @@ go 1.22.3 require ( github.com/container-storage-interface/spec v1.10.0 github.com/deckhouse/sds-local-volume/api v0.0.0-20240903071950-ed9d3bba999b - github.com/deckhouse/sds-node-configurator/api v0.0.0-20240902155711-f525d7d805fa + github.com/deckhouse/sds-node-configurator/api v0.0.0-20240925090458-249de2896583 github.com/go-logr/logr v1.4.2 github.com/golang/protobuf v1.5.4 github.com/google/uuid v1.6.0 diff --git a/images/sds-local-volume-csi/src/go.sum b/images/sds-local-volume-csi/src/go.sum index 6b620d67..70c0f71f 100644 --- a/images/sds-local-volume-csi/src/go.sum +++ b/images/sds-local-volume-csi/src/go.sum @@ -8,6 +8,10 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckhouse/sds-node-configurator/api v0.0.0-20240902155711-f525d7d805fa h1:VaqIf8flnAgl+MY59EYq5zUwRwaSfoLvxTZ4NfXxtgE= github.com/deckhouse/sds-node-configurator/api v0.0.0-20240902155711-f525d7d805fa/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0= +github.com/deckhouse/sds-node-configurator/api v0.0.0-20240919102704-a035b4a92e77 h1:Y3vswUk/rnCpkZzWBk+Mlr9LtMg6EI5LkQ4GvgHCslI= +github.com/deckhouse/sds-node-configurator/api v0.0.0-20240919102704-a035b4a92e77/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0= +github.com/deckhouse/sds-node-configurator/api v0.0.0-20240925090458-249de2896583 h1:HQd5YFQqoHj/CQwBKFCyuVCQmNV0PdML8QJiyDka4fQ= +github.com/deckhouse/sds-node-configurator/api v0.0.0-20240925090458-249de2896583/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0= github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU= github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= diff --git a/images/sds-local-volume-csi/src/internal/const.go b/images/sds-local-volume-csi/src/internal/const.go index b048b110..4e23d591 100644 --- a/images/sds-local-volume-csi/src/internal/const.go +++ b/images/sds-local-volume-csi/src/internal/const.go @@ -21,7 +21,7 @@ const ( Lvm = "lvm" LvmTypeKey = "local.csi.storage.deckhouse.io/lvm-type" BindingModeKey = "local.csi.storage.deckhouse.io/volume-binding-mode" - LvmVolumeGroupKey = "local.csi.storage.deckhouse.io/lvm-volume-groups" + LVMVolumeGroupKey = "local.csi.storage.deckhouse.io/lvm-volume-groups" LVMVThickContiguousParamKey = "local.csi.storage.deckhouse.io/lvm-thick-contiguous" TopologyKey = "topology.sds-local-volume-csi/node" SubPath = "subPath" diff --git a/images/sds-local-volume-csi/src/pkg/utils/func.go b/images/sds-local-volume-csi/src/pkg/utils/func.go index 121b6c36..07044873 100644 --- a/images/sds-local-volume-csi/src/pkg/utils/func.go +++ b/images/sds-local-volume-csi/src/pkg/utils/func.go @@ -154,7 +154,7 @@ func AreSizesEqualWithinDelta(leftSize, rightSize, allowedDelta resource.Quantit return math.Abs(leftSizeFloat-rightSizeFloat) < float64(allowedDelta.Value()) } -func GetNodeWithMaxFreeSpace(lvgs []snc.LvmVolumeGroup, storageClassLVGParametersMap map[string]string, lvmType string) (nodeName string, freeSpace resource.Quantity, err error) { +func GetNodeWithMaxFreeSpace(lvgs []snc.LVMVolumeGroup, storageClassLVGParametersMap map[string]string, lvmType string) (nodeName string, freeSpace resource.Quantity, err error) { var maxFreeSpace int64 for _, lvg := range lvgs { switch lvmType { @@ -182,14 +182,14 @@ func GetNodeWithMaxFreeSpace(lvgs []snc.LvmVolumeGroup, storageClassLVGParameter // TODO: delete the method below? func GetLVMVolumeGroupParams(ctx context.Context, kc client.Client, log logger.Logger, lvmVG map[string]string, nodeName, lvmType string) (lvgName, vgName string, err error) { - listLvgs := &snc.LvmVolumeGroupList{ + listLvgs := &snc.LVMVolumeGroupList{ ListMeta: metav1.ListMeta{}, - Items: []snc.LvmVolumeGroup{}, + Items: []snc.LVMVolumeGroup{}, } err = kc.List(ctx, listLvgs) if err != nil { - return "", "", fmt.Errorf("error getting LvmVolumeGroup list: %w", err) + return "", "", fmt.Errorf("error getting LVMVolumeGroup list: %w", err) } for _, lvg := range listLvgs.Items { @@ -218,8 +218,8 @@ func GetLVMVolumeGroupParams(ctx context.Context, kc client.Client, log logger.L return "", "", errors.New("there are no matches") } -func GetLVMVolumeGroup(ctx context.Context, kc client.Client, lvgName, namespace string) (*snc.LvmVolumeGroup, error) { - var lvg snc.LvmVolumeGroup +func GetLVMVolumeGroup(ctx context.Context, kc client.Client, lvgName, namespace string) (*snc.LVMVolumeGroup, error) { + var lvg snc.LVMVolumeGroup err := kc.Get(ctx, client.ObjectKey{ Name: lvgName, @@ -229,14 +229,14 @@ func GetLVMVolumeGroup(ctx context.Context, kc client.Client, lvgName, namespace return &lvg, err } -func GetLVMVolumeGroupFreeSpace(lvg snc.LvmVolumeGroup) (vgFreeSpace resource.Quantity) { +func GetLVMVolumeGroupFreeSpace(lvg snc.LVMVolumeGroup) (vgFreeSpace resource.Quantity) { vgFreeSpace = lvg.Status.VGSize vgFreeSpace.Sub(lvg.Status.AllocatedSize) return vgFreeSpace } -func GetLVMThinPoolFreeSpace(lvg snc.LvmVolumeGroup, thinPoolName string) (thinPoolFreeSpace resource.Quantity, err error) { - var storagePoolThinPool *snc.LvmVolumeGroupThinPoolStatus +func GetLVMThinPoolFreeSpace(lvg snc.LVMVolumeGroup, thinPoolName string) (thinPoolFreeSpace resource.Quantity, err error) { + var storagePoolThinPool *snc.LVMVolumeGroupThinPoolStatus for _, thinPool := range lvg.Status.ThinPools { if thinPool.Name == thinPoolName { storagePoolThinPool = &thinPool @@ -256,7 +256,7 @@ func ExpandLVMLogicalVolume(ctx context.Context, kc client.Client, llv *snc.LVML return kc.Update(ctx, llv) } -func GetStorageClassLVGsAndParameters(ctx context.Context, kc client.Client, log *logger.Logger, storageClassLVGParametersString string) (storageClassLVGs []snc.LvmVolumeGroup, storageClassLVGParametersMap map[string]string, err error) { +func GetStorageClassLVGsAndParameters(ctx context.Context, kc client.Client, log *logger.Logger, storageClassLVGParametersString string) (storageClassLVGs []snc.LVMVolumeGroup, storageClassLVGParametersMap map[string]string, err error) { var storageClassLVGParametersList LVMVolumeGroups err = yaml.Unmarshal([]byte(storageClassLVGParametersString), &storageClassLVGParametersList) if err != nil { @@ -291,17 +291,17 @@ func GetStorageClassLVGsAndParameters(ctx context.Context, kc client.Client, log return storageClassLVGs, storageClassLVGParametersMap, nil } -func GetLVGList(ctx context.Context, kc client.Client) (*snc.LvmVolumeGroupList, error) { - listLvgs := &snc.LvmVolumeGroupList{} +func GetLVGList(ctx context.Context, kc client.Client) (*snc.LVMVolumeGroupList, error) { + listLvgs := &snc.LVMVolumeGroupList{} return listLvgs, kc.List(ctx, listLvgs) } -func GetLLVSpec(log *logger.Logger, lvName string, selectedLVG snc.LvmVolumeGroup, storageClassLVGParametersMap map[string]string, lvmType string, llvSize resource.Quantity, contiguous bool) snc.LVMLogicalVolumeSpec { +func GetLLVSpec(log *logger.Logger, lvName string, selectedLVG snc.LVMVolumeGroup, storageClassLVGParametersMap map[string]string, lvmType string, llvSize resource.Quantity, contiguous bool) snc.LVMLogicalVolumeSpec { lvmLogicalVolumeSpec := snc.LVMLogicalVolumeSpec{ ActualLVNameOnTheNode: lvName, Type: lvmType, Size: llvSize.String(), - LvmVolumeGroupName: selectedLVG.Name, + LVMVolumeGroupName: selectedLVG.Name, } switch lvmType { @@ -323,13 +323,13 @@ func GetLLVSpec(log *logger.Logger, lvName string, selectedLVG snc.LvmVolumeGrou return lvmLogicalVolumeSpec } -func SelectLVG(storageClassLVGs []snc.LvmVolumeGroup, nodeName string) (snc.LvmVolumeGroup, error) { +func SelectLVG(storageClassLVGs []snc.LVMVolumeGroup, nodeName string) (snc.LVMVolumeGroup, error) { for _, lvg := range storageClassLVGs { if lvg.Status.Nodes[0].Name == nodeName { return lvg, nil } } - return snc.LvmVolumeGroup{}, fmt.Errorf("[SelectLVG] no LVMVolumeGroup found for node %s", nodeName) + return snc.LVMVolumeGroup{}, fmt.Errorf("[SelectLVG] no LVMVolumeGroup found for node %s", nodeName) } func removeLLVFinalizerIfExist(ctx context.Context, kc client.Client, log *logger.Logger, llv *snc.LVMLogicalVolume, finalizer string) (bool, error) { diff --git a/images/sds-local-volume-scheduler-extender/src/go.mod b/images/sds-local-volume-scheduler-extender/src/go.mod index 8837b7e1..359af893 100644 --- a/images/sds-local-volume-scheduler-extender/src/go.mod +++ b/images/sds-local-volume-scheduler-extender/src/go.mod @@ -4,7 +4,7 @@ go 1.22.2 require ( github.com/deckhouse/sds-local-volume/api v0.0.0-20240903071950-ed9d3bba999b - github.com/deckhouse/sds-node-configurator/api v0.0.0-20240902155711-f525d7d805fa + github.com/deckhouse/sds-node-configurator/api v0.0.0-20240925090458-249de2896583 github.com/go-logr/logr v1.4.2 github.com/go-logr/zapr v1.3.0 github.com/spf13/cobra v1.8.1 diff --git a/images/sds-local-volume-scheduler-extender/src/go.sum b/images/sds-local-volume-scheduler-extender/src/go.sum index 9934acdd..8f314298 100644 --- a/images/sds-local-volume-scheduler-extender/src/go.sum +++ b/images/sds-local-volume-scheduler-extender/src/go.sum @@ -11,6 +11,10 @@ github.com/deckhouse/sds-local-volume/api v0.0.0-20240903071950-ed9d3bba999b h1: github.com/deckhouse/sds-local-volume/api v0.0.0-20240903071950-ed9d3bba999b/go.mod h1:cYxHYJmIl6g9lXb1etqmLeQL/vsPMgscmact/FObd+U= github.com/deckhouse/sds-node-configurator/api v0.0.0-20240902155711-f525d7d805fa h1:VaqIf8flnAgl+MY59EYq5zUwRwaSfoLvxTZ4NfXxtgE= github.com/deckhouse/sds-node-configurator/api v0.0.0-20240902155711-f525d7d805fa/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0= +github.com/deckhouse/sds-node-configurator/api v0.0.0-20240919102704-a035b4a92e77 h1:Y3vswUk/rnCpkZzWBk+Mlr9LtMg6EI5LkQ4GvgHCslI= +github.com/deckhouse/sds-node-configurator/api v0.0.0-20240919102704-a035b4a92e77/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0= +github.com/deckhouse/sds-node-configurator/api v0.0.0-20240925090458-249de2896583 h1:HQd5YFQqoHj/CQwBKFCyuVCQmNV0PdML8QJiyDka4fQ= +github.com/deckhouse/sds-node-configurator/api v0.0.0-20240925090458-249de2896583/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0= github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU= github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8P3k= diff --git a/images/sds-local-volume-scheduler-extender/src/pkg/cache/cache.go b/images/sds-local-volume-scheduler-extender/src/pkg/cache/cache.go index 6a635e21..16954fdb 100644 --- a/images/sds-local-volume-scheduler-extender/src/pkg/cache/cache.go +++ b/images/sds-local-volume-scheduler-extender/src/pkg/cache/cache.go @@ -28,7 +28,7 @@ type Cache struct { } type lvgCache struct { - lvg *snc.LvmVolumeGroup + lvg *snc.LVMVolumeGroup thickPVCs sync.Map // map[string]*pvcCache thinPools sync.Map // map[string]*thinPoolCache } @@ -50,7 +50,7 @@ func NewCache(logger logger.Logger) *Cache { } // AddLVG adds selected LVMVolumeGroup resource to the cache. If it is already stored, does nothing. -func (c *Cache) AddLVG(lvg *snc.LvmVolumeGroup) { +func (c *Cache) AddLVG(lvg *snc.LVMVolumeGroup) { _, loaded := c.lvgs.LoadOrStore(lvg.Name, &lvgCache{ lvg: lvg, thickPVCs: sync.Map{}, @@ -75,7 +75,7 @@ func (c *Cache) AddLVG(lvg *snc.LvmVolumeGroup) { } // UpdateLVG updated selected LVMVolumeGroup resource in the cache. If such LVMVolumeGroup is not stored, returns an error. -func (c *Cache) UpdateLVG(lvg *snc.LvmVolumeGroup) error { +func (c *Cache) UpdateLVG(lvg *snc.LVMVolumeGroup) error { if lvgCh, found := c.lvgs.Load(lvg.Name); found { lvgCh.(*lvgCache).lvg = lvg @@ -102,7 +102,7 @@ func (c *Cache) UpdateLVG(lvg *snc.LvmVolumeGroup) error { } // TryGetLVG returns selected LVMVolumeGroup resource if it is stored in the cache, otherwise returns nil. -func (c *Cache) TryGetLVG(name string) *snc.LvmVolumeGroup { +func (c *Cache) TryGetLVG(name string) *snc.LVMVolumeGroup { lvgCh, found := c.lvgs.Load(name) if !found { c.log.Debug(fmt.Sprintf("[TryGetLVG] the LVMVolumeGroup %s was not found in the cache. Return nil", name)) @@ -124,8 +124,8 @@ func (c *Cache) GetLVGNamesByNodeName(nodeName string) []string { } // GetAllLVG returns all the LVMVolumeGroups resources stored in the cache. -func (c *Cache) GetAllLVG() map[string]*snc.LvmVolumeGroup { - lvgs := make(map[string]*snc.LvmVolumeGroup) +func (c *Cache) GetAllLVG() map[string]*snc.LVMVolumeGroup { + lvgs := make(map[string]*snc.LVMVolumeGroup) c.lvgs.Range(func(lvgName, lvgCh any) bool { if lvgCh.(*lvgCache).lvg == nil { c.log.Error(fmt.Errorf("LVMVolumeGroup %s is not initialized", lvgName), "[GetAllLVG] an error occurs while iterating the LVMVolumeGroups") diff --git a/images/sds-local-volume-scheduler-extender/src/pkg/cache/cache_test.go b/images/sds-local-volume-scheduler-extender/src/pkg/cache/cache_test.go index 9a472ccb..e3586bc4 100644 --- a/images/sds-local-volume-scheduler-extender/src/pkg/cache/cache_test.go +++ b/images/sds-local-volume-scheduler-extender/src/pkg/cache/cache_test.go @@ -15,7 +15,7 @@ import ( func BenchmarkCache_DeleteLVG(b *testing.B) { cache := NewCache(logger.Logger{}) - lvg := &snc.LvmVolumeGroup{ + lvg := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: "first", }, @@ -34,7 +34,7 @@ func BenchmarkCache_DeleteLVG(b *testing.B) { func BenchmarkCache_GetLVGReservedSpace(b *testing.B) { cache := NewCache(logger.Logger{}) - lvg := &snc.LvmVolumeGroup{ + lvg := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: "first", }, @@ -101,32 +101,32 @@ func BenchmarkCache_GetLVGReservedSpace(b *testing.B) { func BenchmarkCache_AddPVC(b *testing.B) { cache := NewCache(logger.Logger{}) - lvg1 := &snc.LvmVolumeGroup{ + lvg1 := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: "first", }, - Status: snc.LvmVolumeGroupStatus{ - Nodes: []snc.LvmVolumeGroupNode{ + Status: snc.LVMVolumeGroupStatus{ + Nodes: []snc.LVMVolumeGroupNode{ {Name: "test-node1"}, }, }, } - lvg2 := &snc.LvmVolumeGroup{ + lvg2 := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: "second", }, - Status: snc.LvmVolumeGroupStatus{ - Nodes: []snc.LvmVolumeGroupNode{ + Status: snc.LVMVolumeGroupStatus{ + Nodes: []snc.LVMVolumeGroupNode{ {Name: "test-node2"}, }, }, } - lvg3 := &snc.LvmVolumeGroup{ + lvg3 := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: "third", }, - Status: snc.LvmVolumeGroupStatus{ - Nodes: []snc.LvmVolumeGroupNode{ + Status: snc.LVMVolumeGroupStatus{ + Nodes: []snc.LVMVolumeGroupNode{ {Name: "test-node3"}, }, }, @@ -170,14 +170,14 @@ func BenchmarkCache_GetAllLVG(b *testing.B) { cache := NewCache(logger.Logger{}) lvgs := map[string]*lvgCache{ "first": { - lvg: &snc.LvmVolumeGroup{ + lvg: &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: "first", }, }, }, "second": { - lvg: &snc.LvmVolumeGroup{ + lvg: &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: "second", }, @@ -225,7 +225,7 @@ func BenchmarkCache_TryGetLVG(b *testing.B) { cache := NewCache(logger.Logger{}) name := "test-name" - lvg := &snc.LvmVolumeGroup{ + lvg := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, @@ -249,12 +249,12 @@ func BenchmarkCache_AddLVG(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { i++ - lvg1 := &snc.LvmVolumeGroup{ + lvg1 := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("test-lvg-%d", i), }, - Status: snc.LvmVolumeGroupStatus{ - Nodes: []snc.LvmVolumeGroupNode{ + Status: snc.LVMVolumeGroupStatus{ + Nodes: []snc.LVMVolumeGroupNode{ { Name: "test-1", }, @@ -262,12 +262,12 @@ func BenchmarkCache_AddLVG(b *testing.B) { }, } - lvg2 := &snc.LvmVolumeGroup{ + lvg2 := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("test-lvg-%d", i+1), }, - Status: snc.LvmVolumeGroupStatus{ - Nodes: []snc.LvmVolumeGroupNode{ + Status: snc.LVMVolumeGroupStatus{ + Nodes: []snc.LVMVolumeGroupNode{ { Name: "test-1", }, @@ -275,12 +275,12 @@ func BenchmarkCache_AddLVG(b *testing.B) { }, } - lvg3 := &snc.LvmVolumeGroup{ + lvg3 := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("test-lvg-%d", i+2), }, - Status: snc.LvmVolumeGroupStatus{ - Nodes: []snc.LvmVolumeGroupNode{ + Status: snc.LVMVolumeGroupStatus{ + Nodes: []snc.LVMVolumeGroupNode{ { Name: "test-1", }, @@ -301,21 +301,21 @@ func BenchmarkCache_AddLVG(b *testing.B) { func TestCache_UpdateLVG(t *testing.T) { cache := NewCache(logger.Logger{}) name := "test-lvg" - lvg := &snc.LvmVolumeGroup{ + lvg := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ AllocatedSize: resource.MustParse("1Gi"), }, } cache.AddLVG(lvg) - newLVG := &snc.LvmVolumeGroup{ + newLVG := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ AllocatedSize: resource.MustParse("2Gi"), }, } @@ -334,7 +334,7 @@ func BenchmarkCache_UpdateLVG(b *testing.B) { name := "test-name" i := 0 - lvg := &snc.LvmVolumeGroup{ + lvg := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, @@ -349,11 +349,11 @@ func BenchmarkCache_UpdateLVG(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { i++ - updated := &snc.LvmVolumeGroup{ + updated := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ AllocatedSize: resource.MustParse(fmt.Sprintf("2%dGi", i)), }, } @@ -369,12 +369,12 @@ func BenchmarkCache_UpdateLVG(b *testing.B) { func BenchmarkCache_UpdatePVC(b *testing.B) { cache := NewCache(logger.Logger{}) i := 0 - lvg := &snc.LvmVolumeGroup{ + lvg := &snc.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ Name: "test-lvg", }, - Status: snc.LvmVolumeGroupStatus{ - Nodes: []snc.LvmVolumeGroupNode{ + Status: snc.LVMVolumeGroupStatus{ + Nodes: []snc.LVMVolumeGroupNode{ { Name: "test-node", }, @@ -426,13 +426,13 @@ func BenchmarkCache_FullLoad(b *testing.B) { for pb.Next() { i++ - lvgs := []*snc.LvmVolumeGroup{ + lvgs := []*snc.LVMVolumeGroup{ { ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("test-lvg-%d", i), }, - Status: snc.LvmVolumeGroupStatus{ - Nodes: []snc.LvmVolumeGroupNode{ + Status: snc.LVMVolumeGroupStatus{ + Nodes: []snc.LVMVolumeGroupNode{ { Name: nodeName, }, @@ -444,8 +444,8 @@ func BenchmarkCache_FullLoad(b *testing.B) { ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("test-lvg-%d", i+1), }, - Status: snc.LvmVolumeGroupStatus{ - Nodes: []snc.LvmVolumeGroupNode{ + Status: snc.LVMVolumeGroupStatus{ + Nodes: []snc.LVMVolumeGroupNode{ { Name: nodeName, }, @@ -457,8 +457,8 @@ func BenchmarkCache_FullLoad(b *testing.B) { ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("test-lvg-%d", i+2), }, - Status: snc.LvmVolumeGroupStatus{ - Nodes: []snc.LvmVolumeGroupNode{ + Status: snc.LVMVolumeGroupStatus{ + Nodes: []snc.LVMVolumeGroupNode{ { Name: nodeName, }, @@ -501,12 +501,12 @@ func BenchmarkCache_FullLoad(b *testing.B) { } } - updatedLvgs := []*snc.LvmVolumeGroup{ + updatedLvgs := []*snc.LVMVolumeGroup{ { ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("test-lvg-%d", i), }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ AllocatedSize: resource.MustParse(fmt.Sprintf("1%dGi", i+1)), }, }, @@ -514,7 +514,7 @@ func BenchmarkCache_FullLoad(b *testing.B) { ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("test-lvg-%d", i+1), }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ AllocatedSize: resource.MustParse(fmt.Sprintf("1%dGi", i+1)), }, }, @@ -522,7 +522,7 @@ func BenchmarkCache_FullLoad(b *testing.B) { ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("test-lvg-%d", i+2), }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ AllocatedSize: resource.MustParse(fmt.Sprintf("1%dGi", i+1)), }, }, diff --git a/images/sds-local-volume-scheduler-extender/src/pkg/consts/consts.go b/images/sds-local-volume-scheduler-extender/src/pkg/consts/consts.go index 947c77ab..85bed0a3 100644 --- a/images/sds-local-volume-scheduler-extender/src/pkg/consts/consts.go +++ b/images/sds-local-volume-scheduler-extender/src/pkg/consts/consts.go @@ -4,7 +4,7 @@ const ( SdsLocalVolumeProvisioner = "local.csi.storage.deckhouse.io" LvmTypeParamKey = "local.csi.storage.deckhouse.io/lvm-type" - LvmVolumeGroupsParamKey = "local.csi.storage.deckhouse.io/lvm-volume-groups" + LVMVolumeGroupsParamKey = "local.csi.storage.deckhouse.io/lvm-volume-groups" Thick = "Thick" Thin = "Thin" diff --git a/images/sds-local-volume-scheduler-extender/src/pkg/controller/lvg_watcher_cache.go b/images/sds-local-volume-scheduler-extender/src/pkg/controller/lvg_watcher_cache.go index bd3c11c8..7c6e4ea3 100644 --- a/images/sds-local-volume-scheduler-extender/src/pkg/controller/lvg_watcher_cache.go +++ b/images/sds-local-volume-scheduler-extender/src/pkg/controller/lvg_watcher_cache.go @@ -40,8 +40,8 @@ func RunLVGWatcherCacheController( return nil, err } - err = c.Watch(source.Kind(mgr.GetCache(), &snc.LvmVolumeGroup{}, handler.TypedFuncs[*snc.LvmVolumeGroup, reconcile.Request]{ - CreateFunc: func(_ context.Context, e event.TypedCreateEvent[*snc.LvmVolumeGroup], _ workqueue.TypedRateLimitingInterface[reconcile.Request]) { + err = c.Watch(source.Kind(mgr.GetCache(), &snc.LVMVolumeGroup{}, handler.TypedFuncs[*snc.LVMVolumeGroup, reconcile.Request]{ + CreateFunc: func(_ context.Context, e event.TypedCreateEvent[*snc.LVMVolumeGroup], _ workqueue.TypedRateLimitingInterface[reconcile.Request]) { log.Info(fmt.Sprintf("[RunLVGWatcherCacheController] CreateFunc starts the cache reconciliation for the LVMVolumeGroup %s", e.Object.GetName())) lvg := e.Object @@ -86,7 +86,7 @@ func RunLVGWatcherCacheController( log.Info(fmt.Sprintf("[RunLVGWatcherCacheController] cache for the LVMVolumeGroup %s was reconciled by CreateFunc", lvg.Name)) }, - UpdateFunc: func(_ context.Context, e event.TypedUpdateEvent[*snc.LvmVolumeGroup], _ workqueue.TypedRateLimitingInterface[reconcile.Request]) { + UpdateFunc: func(_ context.Context, e event.TypedUpdateEvent[*snc.LVMVolumeGroup], _ workqueue.TypedRateLimitingInterface[reconcile.Request]) { log.Info(fmt.Sprintf("[RunCacheWatcherController] UpdateFunc starts the cache reconciliation for the LVMVolumeGroup %s", e.ObjectNew.GetName())) oldLvg := e.ObjectOld newLvg := e.ObjectNew @@ -126,7 +126,7 @@ func RunLVGWatcherCacheController( log.Debug(fmt.Sprintf("[RunLVGWatcherCacheController] Update Func ends reconciliation the LVMVolumeGroup %s cache", newLvg.Name)) }, - DeleteFunc: func(_ context.Context, e event.TypedDeleteEvent[*snc.LvmVolumeGroup], _ workqueue.TypedRateLimitingInterface[reconcile.Request]) { + DeleteFunc: func(_ context.Context, e event.TypedDeleteEvent[*snc.LVMVolumeGroup], _ workqueue.TypedRateLimitingInterface[reconcile.Request]) { log.Info(fmt.Sprintf("[RunCacheWatcherController] DeleteFunc starts the cache reconciliation for the LVMVolumeGroup %s", e.Object.GetName())) lvg := e.Object cache.DeleteLVG(lvg.Name) @@ -143,7 +143,7 @@ func RunLVGWatcherCacheController( return c, nil } -func shouldReconcileLVG(oldLVG, newLVG *snc.LvmVolumeGroup) bool { +func shouldReconcileLVG(oldLVG, newLVG *snc.LVMVolumeGroup) bool { if newLVG.DeletionTimestamp != nil { return false } diff --git a/images/sds-local-volume-scheduler-extender/src/pkg/controller/lvg_watcher_cache_test.go b/images/sds-local-volume-scheduler-extender/src/pkg/controller/lvg_watcher_cache_test.go index e5c75517..23bd9e3d 100644 --- a/images/sds-local-volume-scheduler-extender/src/pkg/controller/lvg_watcher_cache_test.go +++ b/images/sds-local-volume-scheduler-extender/src/pkg/controller/lvg_watcher_cache_test.go @@ -12,34 +12,34 @@ import ( func TestLVGWatcherCache(t *testing.T) { t.Run("shouldReconcileLVG", func(t *testing.T) { t.Run("deletion_timestamp_not_nil_returns_false", func(t *testing.T) { - lvg := &snc.LvmVolumeGroup{} + lvg := &snc.LVMVolumeGroup{} lvg.DeletionTimestamp = &v1.Time{} - assert.False(t, shouldReconcileLVG(&snc.LvmVolumeGroup{}, lvg)) + assert.False(t, shouldReconcileLVG(&snc.LVMVolumeGroup{}, lvg)) }) t.Run("allocated_size_and_status_thin_pools_equal_returns_false", func(t *testing.T) { size := resource.MustParse("1G") - thinPools := []snc.LvmVolumeGroupThinPoolStatus{ + thinPools := []snc.LVMVolumeGroupThinPoolStatus{ { Name: "thin", ActualSize: resource.MustParse("1G"), }, } - oldLvg := &snc.LvmVolumeGroup{ + oldLvg := &snc.LVMVolumeGroup{ ObjectMeta: v1.ObjectMeta{ Name: "first", }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ AllocatedSize: size, ThinPools: thinPools, }, } - newLvg := &snc.LvmVolumeGroup{ + newLvg := &snc.LVMVolumeGroup{ ObjectMeta: v1.ObjectMeta{ Name: "first", }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ AllocatedSize: size, ThinPools: thinPools, }, @@ -49,26 +49,26 @@ func TestLVGWatcherCache(t *testing.T) { }) t.Run("allocated_size_not_equal_returns_true", func(t *testing.T) { - thinPools := []snc.LvmVolumeGroupThinPoolStatus{ + thinPools := []snc.LVMVolumeGroupThinPoolStatus{ { Name: "thin", ActualSize: resource.MustParse("1G"), }, } - oldLvg := &snc.LvmVolumeGroup{ + oldLvg := &snc.LVMVolumeGroup{ ObjectMeta: v1.ObjectMeta{ Name: "first", }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ AllocatedSize: resource.MustParse("1G"), ThinPools: thinPools, }, } - newLvg := &snc.LvmVolumeGroup{ + newLvg := &snc.LVMVolumeGroup{ ObjectMeta: v1.ObjectMeta{ Name: "first", }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ AllocatedSize: resource.MustParse("2G"), ThinPools: thinPools, }, @@ -79,13 +79,13 @@ func TestLVGWatcherCache(t *testing.T) { t.Run("status_thin_pools_not_equal_returns_false", func(t *testing.T) { size := resource.MustParse("1G") - oldLvg := &snc.LvmVolumeGroup{ + oldLvg := &snc.LVMVolumeGroup{ ObjectMeta: v1.ObjectMeta{ Name: "first", }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ AllocatedSize: size, - ThinPools: []snc.LvmVolumeGroupThinPoolStatus{ + ThinPools: []snc.LVMVolumeGroupThinPoolStatus{ { Name: "thin", ActualSize: resource.MustParse("1G"), @@ -93,13 +93,13 @@ func TestLVGWatcherCache(t *testing.T) { }, }, } - newLvg := &snc.LvmVolumeGroup{ + newLvg := &snc.LVMVolumeGroup{ ObjectMeta: v1.ObjectMeta{ Name: "first", }, - Status: snc.LvmVolumeGroupStatus{ + Status: snc.LVMVolumeGroupStatus{ AllocatedSize: size, - ThinPools: []snc.LvmVolumeGroupThinPoolStatus{ + ThinPools: []snc.LVMVolumeGroupThinPoolStatus{ { Name: "thin", ActualSize: resource.MustParse("2G"), diff --git a/images/sds-local-volume-scheduler-extender/src/pkg/scheduler/filter.go b/images/sds-local-volume-scheduler-extender/src/pkg/scheduler/filter.go index 5ca4d86f..cd7f2a7d 100644 --- a/images/sds-local-volume-scheduler-extender/src/pkg/scheduler/filter.go +++ b/images/sds-local-volume-scheduler-extender/src/pkg/scheduler/filter.go @@ -516,7 +516,7 @@ func filterNodes( return result, nil } -func getLVGThinFreeSpaces(lvgs map[string]*snc.LvmVolumeGroup) map[string]map[string]int64 { +func getLVGThinFreeSpaces(lvgs map[string]*snc.LVMVolumeGroup) map[string]map[string]int64 { result := make(map[string]map[string]int64, len(lvgs)) for _, lvg := range lvgs { @@ -532,7 +532,7 @@ func getLVGThinFreeSpaces(lvgs map[string]*snc.LvmVolumeGroup) map[string]map[st return result } -func getLVGThickFreeSpaces(lvgs map[string]*snc.LvmVolumeGroup) map[string]int64 { +func getLVGThickFreeSpaces(lvgs map[string]*snc.LVMVolumeGroup) map[string]int64 { result := make(map[string]int64, len(lvgs)) for _, lvg := range lvgs { @@ -542,7 +542,7 @@ func getLVGThickFreeSpaces(lvgs map[string]*snc.LvmVolumeGroup) map[string]int64 return result } -func findMatchedThinPool(thinPools []snc.LvmVolumeGroupThinPoolStatus, name string) *snc.LvmVolumeGroupThinPoolStatus { +func findMatchedThinPool(thinPools []snc.LVMVolumeGroupThinPoolStatus, name string) *snc.LVMVolumeGroupThinPoolStatus { for _, tp := range thinPools { if tp.Name == name { return &tp @@ -552,7 +552,7 @@ func findMatchedThinPool(thinPools []snc.LvmVolumeGroupThinPoolStatus, name stri return nil } -func findMatchedLVG(nodeLVGs []*snc.LvmVolumeGroup, scLVGs LVMVolumeGroups) *LVMVolumeGroup { +func findMatchedLVG(nodeLVGs []*snc.LVMVolumeGroup, scLVGs LVMVolumeGroups) *LVMVolumeGroup { nodeLVGNames := make(map[string]struct{}, len(nodeLVGs)) for _, lvg := range nodeLVGs { nodeLVGNames[lvg.Name] = struct{}{} @@ -567,8 +567,8 @@ func findMatchedLVG(nodeLVGs []*snc.LvmVolumeGroup, scLVGs LVMVolumeGroups) *LVM return nil } -func getCommonNodesByStorageClasses(scs map[string]*v1.StorageClass, nodesWithLVGs map[string][]*snc.LvmVolumeGroup) (map[string][]*snc.LvmVolumeGroup, error) { - result := make(map[string][]*snc.LvmVolumeGroup, len(nodesWithLVGs)) +func getCommonNodesByStorageClasses(scs map[string]*v1.StorageClass, nodesWithLVGs map[string][]*snc.LVMVolumeGroup) (map[string][]*snc.LVMVolumeGroup, error) { + result := make(map[string][]*snc.LVMVolumeGroup, len(nodesWithLVGs)) for nodeName, lvgs := range nodesWithLVGs { lvgNames := make(map[string]struct{}, len(lvgs)) @@ -605,8 +605,8 @@ func getCommonNodesByStorageClasses(scs map[string]*v1.StorageClass, nodesWithLV return result, nil } -func RemoveUnusedLVGs(lvgs map[string]*snc.LvmVolumeGroup, scsLVGs map[string]LVMVolumeGroups) map[string]*snc.LvmVolumeGroup { - result := make(map[string]*snc.LvmVolumeGroup, len(lvgs)) +func RemoveUnusedLVGs(lvgs map[string]*snc.LVMVolumeGroup, scsLVGs map[string]LVMVolumeGroups) map[string]*snc.LVMVolumeGroup { + result := make(map[string]*snc.LVMVolumeGroup, len(lvgs)) usedLvgs := make(map[string]struct{}, len(lvgs)) for _, scLvgs := range scsLVGs { @@ -649,15 +649,15 @@ type LVMVolumeGroups []LVMVolumeGroup func ExtractLVGsFromSC(sc *v1.StorageClass) (LVMVolumeGroups, error) { var lvmVolumeGroups LVMVolumeGroups - err := yaml.Unmarshal([]byte(sc.Parameters[consts.LvmVolumeGroupsParamKey]), &lvmVolumeGroups) + err := yaml.Unmarshal([]byte(sc.Parameters[consts.LVMVolumeGroupsParamKey]), &lvmVolumeGroups) if err != nil { return nil, err } return lvmVolumeGroups, nil } -func SortLVGsByNodeName(lvgs map[string]*snc.LvmVolumeGroup) map[string][]*snc.LvmVolumeGroup { - sorted := make(map[string][]*snc.LvmVolumeGroup, len(lvgs)) +func SortLVGsByNodeName(lvgs map[string]*snc.LVMVolumeGroup) map[string][]*snc.LVMVolumeGroup { + sorted := make(map[string][]*snc.LVMVolumeGroup, len(lvgs)) for _, lvg := range lvgs { for _, node := range lvg.Status.Nodes { sorted[node.Name] = append(sorted[node.Name], lvg) diff --git a/images/webhooks/src/go.mod b/images/webhooks/src/go.mod index 6ffbb8ce..88004bf6 100644 --- a/images/webhooks/src/go.mod +++ b/images/webhooks/src/go.mod @@ -4,7 +4,7 @@ go 1.22.3 require ( github.com/deckhouse/sds-local-volume/api v0.0.0-20240813100234-cf7ae5802ee1 - github.com/deckhouse/sds-node-configurator/api v0.0.0-20240805103635-969dc811217b + github.com/deckhouse/sds-node-configurator/api v0.0.0-20240925090458-249de2896583 github.com/sirupsen/logrus v1.9.3 github.com/slok/kubewebhook/v2 v2.6.0 k8s.io/api v0.30.3 diff --git a/images/webhooks/src/go.sum b/images/webhooks/src/go.sum index 2003d4fd..9b66fbf4 100644 --- a/images/webhooks/src/go.sum +++ b/images/webhooks/src/go.sum @@ -5,6 +5,10 @@ github.com/deckhouse/sds-local-volume/api v0.0.0-20240813100234-cf7ae5802ee1 h1: github.com/deckhouse/sds-local-volume/api v0.0.0-20240813100234-cf7ae5802ee1/go.mod h1:cYxHYJmIl6g9lXb1etqmLeQL/vsPMgscmact/FObd+U= github.com/deckhouse/sds-node-configurator/api v0.0.0-20240805103635-969dc811217b h1:EYmHWTWcWMpyxJGZK05ZxlIFnh9s66DRrxLw/LNb/xw= github.com/deckhouse/sds-node-configurator/api v0.0.0-20240805103635-969dc811217b/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0= +github.com/deckhouse/sds-node-configurator/api v0.0.0-20240919102704-a035b4a92e77 h1:Y3vswUk/rnCpkZzWBk+Mlr9LtMg6EI5LkQ4GvgHCslI= +github.com/deckhouse/sds-node-configurator/api v0.0.0-20240919102704-a035b4a92e77/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0= +github.com/deckhouse/sds-node-configurator/api v0.0.0-20240925090458-249de2896583 h1:HQd5YFQqoHj/CQwBKFCyuVCQmNV0PdML8QJiyDka4fQ= +github.com/deckhouse/sds-node-configurator/api v0.0.0-20240925090458-249de2896583/go.mod h1:H71+9G0Jr46Qs0BA3z3/xt0h9lbnJnCEYcaCJCWFBf0= github.com/emicklei/go-restful/v3 v3.12.0 h1:y2DdzBAURM29NFF94q6RaY4vjIH1rtwDapwQtU84iWk= github.com/emicklei/go-restful/v3 v3.12.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= diff --git a/images/webhooks/src/handlers/lscValidator.go b/images/webhooks/src/handlers/lscValidator.go index 434e5759..d0c3bd32 100644 --- a/images/webhooks/src/handlers/lscValidator.go +++ b/images/webhooks/src/handlers/lscValidator.go @@ -50,7 +50,7 @@ func LSCValidate(ctx context.Context, _ *model.AdmissionReview, obj metav1.Objec klog.Fatal(err) } - listDevice := &snc.LvmVolumeGroupList{} + listDevice := &snc.LVMVolumeGroupList{} err = cl.List(ctx, listDevice) if err != nil {