Skip to content

Commit

Permalink
[controller] Add thin pool reserved space to the cache
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 Jul 2, 2024
1 parent 7e8a4a2 commit e21adc9
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 236 deletions.
52 changes: 32 additions & 20 deletions images/sds-local-volume-controller/api/v1alpha1/lvm_volume_group.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*
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
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -33,16 +36,24 @@ type LvmVolumeGroup struct {
Status LvmVolumeGroupStatus `json:"status,omitempty"`
}

type SpecThinPool struct {
Name string `json:"name"`
Size resource.Quantity `json:"size"`
type LvmVolumeGroupSpec struct {
ActualVGNameOnTheNode string `json:"actualVGNameOnTheNode"`
BlockDeviceNames []string `json:"blockDeviceNames"`
ThinPools []LvmVolumeGroupThinPoolSpec `json:"thinPools"`
Type string `json:"type"`
}

type LvmVolumeGroupSpec struct {
ActualVGNameOnTheNode string `json:"actualVGNameOnTheNode"`
BlockDeviceNames []string `json:"blockDeviceNames"`
ThinPools []SpecThinPool `json:"thinPools"`
Type string `json:"type"`
type LvmVolumeGroupStatus struct {
AllocatedSize resource.Quantity `json:"allocatedSize"`
Nodes []LvmVolumeGroupNode `json:"nodes"`
ThinPools []LvmVolumeGroupThinPoolStatus `json:"thinPools"`
VGSize resource.Quantity `json:"vgSize"`
VGUuid string `json:"vgUUID"`
Phase string `json:"phase"`
Conditions []metav1.Condition `json:"conditions"`
ThinPoolReady string `json:"thinPoolReady"`
ConfigurationApplied string `json:"configurationApplied"`
VGFree resource.Quantity `json:"vgFree"`
}

type LvmVolumeGroupDevice struct {
Expand All @@ -58,18 +69,19 @@ type LvmVolumeGroupNode struct {
Name string `json:"name"`
}

type StatusThinPool struct {
Name string `json:"name"`
ActualSize resource.Quantity `json:"actualSize"`
UsedSize resource.Quantity `json:"usedSize"`
type LvmVolumeGroupThinPoolStatus struct {
Name string `json:"name"`
ActualSize resource.Quantity `json:"actualSize"`
UsedSize resource.Quantity `json:"usedSize"`
AllocatedSize resource.Quantity `json:"allocatedSize"`
AvailableSpace resource.Quantity `json:"availableSpace"`
AllocationLimit string `json:"allocationLimit"`
Ready bool `json:"ready"`
Message string `json:"message"`
}

type LvmVolumeGroupStatus struct {
AllocatedSize resource.Quantity `json:"allocatedSize"`
Health string `json:"health"`
Message string `json:"message"`
Nodes []LvmVolumeGroupNode `json:"nodes"`
ThinPools []StatusThinPool `json:"thinPools"`
VGSize resource.Quantity `json:"vgSize"`
VGUuid string `json:"vgUUID"`
type LvmVolumeGroupThinPoolSpec struct {
Name string `json:"name"`
Size resource.Quantity `json:"size"`
AllocationLimit string `json:"allocationLimit"`
}
4 changes: 2 additions & 2 deletions images/sds-local-volume-csi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG BASE_ALPINE=registry.deckhouse.io/base_images/alpine:3.16.3@sha256:5548e9172c24a1b0ca9afdd2bf534e265c94b12b36b3e0c0302f5853eaf00abb
ARG BASE_GOLANG_21_ALPINE_BUILDER=registry.deckhouse.io/base_images/golang:1.21.4-alpine3.18@sha256:cf84f3d6882c49ea04b6478ac514a2582c8922d7e5848b43d2918fff8329f6e6
ARG BASE_GOLANG_ALPINE_BUILDER=registry.deckhouse.io/base_images/golang:1.21.4-alpine3.18@sha256:cf84f3d6882c49ea04b6478ac514a2582c8922d7e5848b43d2918fff8329f6e6

FROM $BASE_GOLANG_21_ALPINE_BUILDER as builder
FROM $BASE_GOLANG_ALPINE_BUILDER as builder

WORKDIR /go/src

Expand Down
49 changes: 29 additions & 20 deletions images/sds-local-volume-csi/api/v1alpha1/lvm_volume_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,24 @@ type LvmVolumeGroup struct {
Status LvmVolumeGroupStatus `json:"status,omitempty"`
}

type SpecThinPool struct {
Name string `json:"name"`
Size resource.Quantity `json:"size"`
type LvmVolumeGroupSpec struct {
ActualVGNameOnTheNode string `json:"actualVGNameOnTheNode"`
BlockDeviceNames []string `json:"blockDeviceNames"`
ThinPools []LvmVolumeGroupThinPoolSpec `json:"thinPools"`
Type string `json:"type"`
}

type LvmVolumeGroupSpec struct {
ActualVGNameOnTheNode string `json:"actualVGNameOnTheNode"`
BlockDeviceNames []string `json:"blockDeviceNames"`
ThinPools []SpecThinPool `json:"thinPools"`
Type string `json:"type"`
type LvmVolumeGroupStatus struct {
AllocatedSize resource.Quantity `json:"allocatedSize"`
Nodes []LvmVolumeGroupNode `json:"nodes"`
ThinPools []LvmVolumeGroupThinPoolStatus `json:"thinPools"`
VGSize resource.Quantity `json:"vgSize"`
VGUuid string `json:"vgUUID"`
Phase string `json:"phase"`
Conditions []metav1.Condition `json:"conditions"`
ThinPoolReady string `json:"thinPoolReady"`
ConfigurationApplied string `json:"configurationApplied"`
VGFree resource.Quantity `json:"vgFree"`
}

type LvmVolumeGroupDevice struct {
Expand All @@ -61,18 +69,19 @@ type LvmVolumeGroupNode struct {
Name string `json:"name"`
}

type StatusThinPool struct {
Name string `json:"name"`
ActualSize resource.Quantity `json:"actualSize"`
UsedSize resource.Quantity `json:"usedSize"`
type LvmVolumeGroupThinPoolStatus struct {
Name string `json:"name"`
ActualSize resource.Quantity `json:"actualSize"`
UsedSize resource.Quantity `json:"usedSize"`
AllocatedSize resource.Quantity `json:"allocatedSize"`
AvailableSpace resource.Quantity `json:"availableSpace"`
AllocationLimit string `json:"allocationLimit"`
Ready bool `json:"ready"`
Message string `json:"message"`
}

type LvmVolumeGroupStatus struct {
AllocatedSize resource.Quantity `json:"allocatedSize"`
Health string `json:"health"`
Message string `json:"message"`
Nodes []LvmVolumeGroupNode `json:"nodes"`
ThinPools []StatusThinPool `json:"thinPools"`
VGSize resource.Quantity `json:"vgSize"`
VGUuid string `json:"vgUUID"`
type LvmVolumeGroupThinPoolSpec struct {
Name string `json:"name"`
Size resource.Quantity `json:"size"`
AllocationLimit string `json:"allocationLimit"`
}
2 changes: 1 addition & 1 deletion images/sds-local-volume-csi/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {

cfgParams, err := config.NewConfig()
if err != nil {
klog.Fatal("unable to create NewConfig")
klog.Fatalf("unable to create NewConfig, err: %s", err.Error())
}

var (
Expand Down
11 changes: 4 additions & 7 deletions images/sds-local-volume-csi/pkg/utils/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func GetNodeWithMaxFreeSpace(lvgs []v1alpha1.LvmVolumeGroup, storageClassLVGPara

switch lvmType {
case internal.LVMTypeThick:
freeSpace = GetLVMVolumeGroupFreeSpace(lvg)
freeSpace = lvg.Status.VGFree
case internal.LVMTypeThin:
thinPoolName, ok := storageClassLVGParametersMap[lvg.Name]
if !ok {
Expand All @@ -199,6 +199,7 @@ func GetNodeWithMaxFreeSpace(lvgs []v1alpha1.LvmVolumeGroup, storageClassLVGPara
return nodeName, *resource.NewQuantity(maxFreeSpace, resource.BinarySI), nil
}

// 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 := &v1alpha1.LvmVolumeGroupList{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -273,7 +274,7 @@ func GetLVMVolumeGroupFreeSpace(lvg v1alpha1.LvmVolumeGroup) (vgFreeSpace resour
}

func GetLVMThinPoolFreeSpace(lvg v1alpha1.LvmVolumeGroup, thinPoolName string) (thinPoolFreeSpace resource.Quantity, err error) {
var storagePoolThinPool *v1alpha1.StatusThinPool
var storagePoolThinPool *v1alpha1.LvmVolumeGroupThinPoolStatus
for _, thinPool := range lvg.Status.ThinPools {
if thinPool.Name == thinPoolName {
storagePoolThinPool = &thinPool
Expand All @@ -285,11 +286,7 @@ func GetLVMThinPoolFreeSpace(lvg v1alpha1.LvmVolumeGroup, thinPoolName string) (
return thinPoolFreeSpace, fmt.Errorf("[GetLVMThinPoolFreeSpace] thin pool %s not found in lvg %+v", thinPoolName, lvg)
}

thinPoolActualSize := storagePoolThinPool.ActualSize

thinPoolFreeSpace = thinPoolActualSize.DeepCopy()
thinPoolFreeSpace.Sub(storagePoolThinPool.UsedSize)
return thinPoolFreeSpace, nil
return storagePoolThinPool.AvailableSpace, nil
}

func UpdateLVMLogicalVolume(ctx context.Context, kc client.Client, llv *v1alpha1.LVMLogicalVolume) error {
Expand Down
Loading

0 comments on commit e21adc9

Please sign in to comment.