Skip to content

Commit

Permalink
[controller] Add an auto extension feature for LVMVolumeGroup thin-po…
Browse files Browse the repository at this point in the history
…ols and LVMLogicalVolumes

Signed-off-by: Viktor Kramarenko <[email protected]>
  • Loading branch information
ViktorKram committed Jul 17, 2024
1 parent e35e7d5 commit 379e9c1
Show file tree
Hide file tree
Showing 20 changed files with 444 additions and 213 deletions.
4 changes: 3 additions & 1 deletion crds/doc-ru-lvmlogicalvolume.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ spec:
Тип LV: Thick или Thin.
size:
description: |
Желаемый размер LV.
Желаемый размер LV. Может быть указан как в численном, так и процентном виде.
> Обратите внимание, что при указании размера в процентах LV будет автоматически расширена при расширении VG или Thin-pool.
lvmVolumeGroupName:
description: |
Имя LVMVolumeGroup ресурса, VG которого будет использовано для создания LV.
Expand Down
4 changes: 3 additions & 1 deletion crds/doc-ru-lvmvolumegroup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ spec:
> Неизменяемое поле.
size:
description: |
Желаемый размер Thin-pool.
Желаемый размер Thin-pool. Может быть указан как в численном, так и процентном виде.
> Обратите внимание, что при указании размера в процентах Thin-pool будет автоматически расширен при расширении VG.
status:
properties:
phase:
Expand Down
4 changes: 3 additions & 1 deletion crds/lvmlogicalvolume.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ spec:
size:
x-kubernetes-int-or-string: true
description: |
Desired LV size.
The desired LV size. Might be specified as number or percent size.
> Note, that if you specify the percent size, the LV will be automatically extended when VG or Thin-pool is extended.
minLength: 1
pattern: '^[0-9]+(\.[0-9]+)?(E|P|T|G|M|k|Ei|Pi|Ti|Gi|Mi|Ki)?$|^[1-9][0-9]?%$|100%'
lvmVolumeGroupName:
Expand Down
4 changes: 3 additions & 1 deletion crds/lvmvolumegroup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ spec:
x-kubernetes-int-or-string: true
pattern: '^[0-9]+(\.[0-9]+)?(E|P|T|G|M|k|Ei|Pi|Ti|Gi|Mi|Ki)?$|^[1-9][0-9]?%$|100%'
description: |
The desired Thin-pool size.
The desired Thin-pool size. Might be specified as number or percent size.
> Note, that if you specify the percent size, the Thin-pool will be automatically extended when VG is extended.
allocationLimit:
type: string
pattern: '^[1-9][0-9]{2,3}%$'
Expand Down
5 changes: 5 additions & 0 deletions images/agent/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func main() {
os.Exit(1)
}

if err = controller.RunLVMLogicalVolumeExtenderWatcherController(mgr, *cfgParams, *log, metrics, sdsCache); err != nil {
log.Error(err, "[main] unable to controller.RunLVMLogicalVolumeExtenderWatcherController")
os.Exit(1)
}

if err = mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
log.Error(err, "[main] unable to mgr.AddHealthzCheck")
os.Exit(1)
Expand Down
14 changes: 7 additions & 7 deletions images/agent/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ require (
github.com/deckhouse/sds-node-configurator/api v0.0.0-20240709091744-c9d24f05db41
github.com/go-logr/logr v1.4.1
github.com/google/go-cmp v0.6.0
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.31.0
github.com/onsi/ginkgo/v2 v2.17.1
github.com/onsi/gomega v1.32.0
github.com/pilebones/go-udev v0.9.0
github.com/prometheus/client_golang v1.18.0
github.com/stretchr/testify v1.8.4
k8s.io/api v0.30.2
k8s.io/apiextensions-apiserver v0.29.4
k8s.io/apiextensions-apiserver v0.30.1
k8s.io/apimachinery v0.30.2
k8s.io/client-go v0.29.4
k8s.io/client-go v0.30.1
k8s.io/klog/v2 v2.120.1
k8s.io/utils v0.0.0-20231127182322-b307cd553661
sigs.k8s.io/controller-runtime v0.17.3
sigs.k8s.io/controller-runtime v0.18.4
)

require (
Expand All @@ -26,7 +26,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
Expand Down Expand Up @@ -67,7 +67,7 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/component-base v0.29.4 // indirect
k8s.io/component-base v0.30.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
Expand Down
11 changes: 11 additions & 0 deletions images/agent/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCv
github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.8.0 h1:lRj6N9Nci7MvzrXuX6HFzU8XjmhPiXPlsKEy1u0KQro=
github.com/evanphx/json-patch/v5 v5.8.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
Expand Down Expand Up @@ -85,8 +87,10 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY=
github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM=
github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs=
github.com/onsi/gomega v1.31.0 h1:54UJxxj6cPInHS3a35wm6BK/F9nHYueZ1NVujHDrnXE=
github.com/onsi/gomega v1.31.0/go.mod h1:DW9aCi7U6Yi40wNVAvT6kzFnEVEI5n3DloYBiKiT6zk=
github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg=
github.com/pilebones/go-udev v0.9.0 h1:N1uEO/SxUwtIctc0WLU0t69JeBxIYEYnj8lT/Nabl9Q=
github.com/pilebones/go-udev v0.9.0/go.mod h1:T2eI2tUSK0hA2WS5QLjXJUfQkluZQu+18Cqvem3CaXI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -203,12 +207,17 @@ k8s.io/api v0.30.2 h1:+ZhRj+28QT4UOH+BKznu4CBgPWgkXO7XAvMcMl0qKvI=
k8s.io/api v0.30.2/go.mod h1:ULg5g9JvOev2dG0u2hig4Z7tQ2hHIuS+m8MNZ+X6EmI=
k8s.io/apiextensions-apiserver v0.29.4 h1:M7hbuHU/ckbibR7yPbe6DyNWgTFKNmZDbdZKD8q1Smk=
k8s.io/apiextensions-apiserver v0.29.4/go.mod h1:TTDC9fB+0kHY2rogf5hgBR03KBKCwED+GHUsXGpR7SM=
k8s.io/apiextensions-apiserver v0.30.1 h1:4fAJZ9985BmpJG6PkoxVRpXv9vmPUOVzl614xarePws=
k8s.io/apiextensions-apiserver v0.30.1/go.mod h1:R4GuSrlhgq43oRY9sF2IToFh7PVlF1JjfWdoG3pixk4=
k8s.io/apimachinery v0.30.2 h1:fEMcnBj6qkzzPGSVsAZtQThU62SmQ4ZymlXRC5yFSCg=
k8s.io/apimachinery v0.30.2/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
k8s.io/client-go v0.29.4 h1:79ytIedxVfyXV8rpH3jCBW0u+un0fxHDwX5F9K8dPR8=
k8s.io/client-go v0.29.4/go.mod h1:kC1thZQ4zQWYwldsfI088BbK6RkxK+aF5ebV8y9Q4tk=
k8s.io/client-go v0.30.1 h1:uC/Ir6A3R46wdkgCV3vbLyNOYyCJ8oZnjtJGKfytl/Q=
k8s.io/client-go v0.30.1/go.mod h1:wrAqLNs2trwiCH/wxxmT/x3hKVH9PuV0GGW0oDoHVqc=
k8s.io/component-base v0.29.4 h1:xeKzuuHI/1tjleu5jycDAcYbhAxeGHCQBZUY2eRIkOo=
k8s.io/component-base v0.29.4/go.mod h1:pYjt+oEZP9gtmwSikwAJgfSBikqKX2gOqRat0QjmQt0=
k8s.io/component-base v0.30.1/go.mod h1:e/X9kDiOebwlI41AvBHuWdqFriSRrX50CdwA9TFaHLI=
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
Expand All @@ -217,6 +226,8 @@ k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6R
k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/controller-runtime v0.17.3 h1:65QmN7r3FWgTxDMz9fvGnO1kbf2nu+acg9p2R9oYYYk=
sigs.k8s.io/controller-runtime v0.17.3/go.mod h1:N0jpP5Lo7lMTF9aL56Z/B2oWBJjey6StQM0jRbKQXtY=
sigs.k8s.io/controller-runtime v0.18.4 h1:87+guW1zhvuPLh1PHybKdYFLU0YJp4FhJRmiHvm5BZw=
sigs.k8s.io/controller-runtime v0.18.4/go.mod h1:TVoGrfdpbA9VRFaRnKgk9P5/atA0pMwq+f+msb9M8Sg=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
Expand Down
2 changes: 2 additions & 0 deletions images/agent/internal/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const (

AllocationLimitDefaultValue = "150%"

PhaseReady = "Ready"

ReasonValidationFailed = "ValidationFailed"
ReasonCreating = "Creating"
ReasonUpdating = "Updating"
Expand Down
20 changes: 20 additions & 0 deletions images/agent/pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ func (c *Cache) GetLVs() ([]internal.LVData, bytes.Buffer) {
return dst, c.lvsErrs
}

func (c *Cache) FindLV(vgName, lvName string) *internal.LVData {
for _, lv := range c.lvs {
if lv.VGName == vgName && lv.LVName == lvName {
return &lv
}
}

return nil
}

func (c *Cache) FindVG(vgName string) *internal.VGData {
for _, vg := range c.vgs {
if vg.VGName == vgName {
return &vg
}
}

return nil
}

func (c *Cache) PrintTheCache(log logger.Logger) {
log.Cache("*****************CACHE BEGIN*****************")
log.Cache("[Devices BEGIN]")
Expand Down
2 changes: 1 addition & 1 deletion images/agent/pkg/controller/block_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func RunBlockDeviceController(

c, err := controller.New(BlockDeviceCtrlName, mgr, controller.Options{
Reconciler: reconcile.Func(func(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
log.Info("[RunBlockDeviceController] Reconciler starts BlockDevice resources reconciliation")
log.Info(fmt.Sprintf("[RunBlockDeviceController] Reconciler starts BlockDevice resources reconciliation at %s", time.Now().String()))

shouldRequeue := BlockDeviceReconcile(ctx, cl, log, metrics, cfg, sdsCache)
if shouldRequeue {
Expand Down
4 changes: 2 additions & 2 deletions images/agent/pkg/controller/lvm_logical_volume_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func BenchmarkRunThickLLVCreationSingleThread(b *testing.B) {
}

if llv.Status != nil &&
llv.Status.Phase == StatusPhaseCreated &&
llv.Status.Phase == LLVStatusPhaseCreated &&
!created {
succeeded++
llvNames[llvName] = true
Expand Down Expand Up @@ -138,7 +138,7 @@ func BenchmarkRunThinLLVCreationSingleThread(b *testing.B) {
}

if llv.Status != nil &&
llv.Status.Phase == StatusPhaseCreated &&
llv.Status.Phase == LLVStatusPhaseCreated &&
!visited {
succeeded++
llvNames[llvName] = true
Expand Down
Loading

0 comments on commit 379e9c1

Please sign in to comment.