Skip to content

Commit b286266

Browse files
committed
feat: add LVM status controller
Signed-off-by: Mateusz Urbanek <mateusz.urbanek@siderolabs.com>
1 parent b48a2be commit b286266

16 files changed

Lines changed: 498 additions & 0 deletions
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package storage
6+
7+
import (
8+
"context"
9+
10+
"github.com/cosi-project/runtime/pkg/controller"
11+
"go.uber.org/zap"
12+
13+
"github.com/siderolabs/talos/pkg/machinery/resources/block"
14+
"github.com/siderolabs/talos/pkg/machinery/resources/storage"
15+
)
16+
17+
// LVMLogicalVolumeStatusController manages LVMLogicalVolumeStatus resources.
18+
type LVMLogicalVolumeStatusController struct{}
19+
20+
// Name implements controller.Controller interface.
21+
func (ctrl *LVMLogicalVolumeStatusController) Name() string {
22+
return "storage.LVMLogicalVolumeStatusController"
23+
}
24+
25+
// Inputs implements controller.Controller interface.
26+
func (ctrl *LVMLogicalVolumeStatusController) Inputs() []controller.Input {
27+
return []controller.Input{
28+
{
29+
Namespace: block.NamespaceName,
30+
Type: block.DiscoveredVolumeType,
31+
Kind: controller.InputWeak,
32+
},
33+
{
34+
Namespace: storage.NamespaceName,
35+
Type: storage.LVMPhysicalVolumeStatusType,
36+
Kind: controller.InputWeak,
37+
},
38+
{
39+
Namespace: storage.NamespaceName,
40+
Type: storage.LVMLogicalVolumeStatusType,
41+
Kind: controller.InputWeak,
42+
},
43+
}
44+
}
45+
46+
// Outputs implements controller.Controller interface.
47+
func (ctrl *LVMLogicalVolumeStatusController) Outputs() []controller.Output {
48+
return []controller.Output{
49+
{
50+
Type: storage.LVMLogicalVolumeStatusType,
51+
Kind: controller.OutputExclusive,
52+
},
53+
}
54+
}
55+
56+
// Run implements controller.Controller interface.
57+
func (ctrl *LVMLogicalVolumeStatusController) Run(ctx context.Context, r controller.Runtime, _ *zap.Logger) error {
58+
for {
59+
select {
60+
case <-ctx.Done():
61+
return nil
62+
case <-r.EventCh():
63+
}
64+
}
65+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package storage
6+
7+
import (
8+
"context"
9+
10+
"github.com/cosi-project/runtime/pkg/controller"
11+
"go.uber.org/zap"
12+
13+
"github.com/siderolabs/talos/pkg/machinery/resources/block"
14+
"github.com/siderolabs/talos/pkg/machinery/resources/storage"
15+
)
16+
17+
// LVMPhysicalVolumeStatusController manages LVMPhysicalVolumeStatus resources.
18+
type LVMPhysicalVolumeStatusController struct{}
19+
20+
// Name implements controller.Controller interface.
21+
func (ctrl *LVMPhysicalVolumeStatusController) Name() string {
22+
return "storage.LVMPhysicalVolumeStatusController"
23+
}
24+
25+
// Inputs implements controller.Controller interface.
26+
func (ctrl *LVMPhysicalVolumeStatusController) Inputs() []controller.Input {
27+
return []controller.Input{
28+
{
29+
Namespace: block.NamespaceName,
30+
Type: block.DiscoveredVolumeType,
31+
Kind: controller.InputWeak,
32+
},
33+
}
34+
}
35+
36+
// Outputs implements controller.Controller interface.
37+
func (ctrl *LVMPhysicalVolumeStatusController) Outputs() []controller.Output {
38+
return []controller.Output{
39+
{
40+
Type: storage.LVMPhysicalVolumeStatusType,
41+
Kind: controller.OutputExclusive,
42+
},
43+
}
44+
}
45+
46+
// Run implements controller.Controller interface.
47+
func (ctrl *LVMPhysicalVolumeStatusController) Run(ctx context.Context, r controller.Runtime, _ *zap.Logger) error {
48+
for {
49+
select {
50+
case <-ctx.Done():
51+
return nil
52+
case <-r.EventCh():
53+
}
54+
}
55+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package storage
6+
7+
import (
8+
"context"
9+
10+
"github.com/cosi-project/runtime/pkg/controller"
11+
"go.uber.org/zap"
12+
13+
"github.com/siderolabs/talos/pkg/machinery/resources/storage"
14+
)
15+
16+
// LVMVolumeGroupStatusController manages LVMVolumeGroupStatus resources.
17+
type LVMVolumeGroupStatusController struct{}
18+
19+
// Name implements controller.Controller interface.
20+
func (ctrl *LVMVolumeGroupStatusController) Name() string {
21+
return "storage.LVMVolumeGroupStatusController"
22+
}
23+
24+
// Inputs implements controller.Controller interface.
25+
func (ctrl *LVMVolumeGroupStatusController) Inputs() []controller.Input {
26+
return []controller.Input{
27+
{
28+
Namespace: storage.NamespaceName,
29+
Type: storage.LVMPhysicalVolumeStatusType,
30+
Kind: controller.InputWeak,
31+
},
32+
}
33+
}
34+
35+
// Outputs implements controller.Controller interface.
36+
func (ctrl *LVMVolumeGroupStatusController) Outputs() []controller.Output {
37+
return []controller.Output{
38+
{
39+
Type: storage.LVMVolumeGroupStatusType,
40+
Kind: controller.OutputExclusive,
41+
},
42+
}
43+
}
44+
45+
// Run implements controller.Controller interface.
46+
func (ctrl *LVMVolumeGroupStatusController) Run(ctx context.Context, r controller.Runtime, _ *zap.Logger) error {
47+
for {
48+
select {
49+
case <-ctx.Done():
50+
return nil
51+
case <-r.EventCh():
52+
}
53+
}
54+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
// Package storage provides the controllers related to LVM and storage virtualization.
6+
package storage

internal/app/machined/pkg/runtime/v1alpha2/v1alpha2_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/siderolabs/talos/internal/app/machined/pkg/controllers/secrets"
3737
"github.com/siderolabs/talos/internal/app/machined/pkg/controllers/security"
3838
"github.com/siderolabs/talos/internal/app/machined/pkg/controllers/siderolink"
39+
"github.com/siderolabs/talos/internal/app/machined/pkg/controllers/storage"
3940
timecontrollers "github.com/siderolabs/talos/internal/app/machined/pkg/controllers/time"
4041
"github.com/siderolabs/talos/internal/app/machined/pkg/controllers/v1alpha1"
4142
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
@@ -174,6 +175,9 @@ func (ctrl *Controller) Run(ctx context.Context, drainer *runtime.Drainer) error
174175
&block.ZswapStatusController{
175176
V1Alpha1Mode: ctrl.v1alpha1Runtime.State().Platform().Mode(),
176177
},
178+
&storage.LVMVolumeGroupStatusController{},
179+
&storage.LVMLogicalVolumeStatusController{},
180+
&storage.LVMPhysicalVolumeStatusController{},
177181
&cluster.AffiliateMergeController{},
178182
cluster.NewConfigController(),
179183
&cluster.DiscoveryServiceController{},

internal/app/machined/pkg/runtime/v1alpha2/v1alpha2_state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/siderolabs/talos/pkg/machinery/resources/secrets"
3232
"github.com/siderolabs/talos/pkg/machinery/resources/security"
3333
"github.com/siderolabs/talos/pkg/machinery/resources/siderolink"
34+
"github.com/siderolabs/talos/pkg/machinery/resources/storage"
3435
"github.com/siderolabs/talos/pkg/machinery/resources/time"
3536
"github.com/siderolabs/talos/pkg/machinery/resources/v1alpha1"
3637
)
@@ -259,6 +260,9 @@ func NewState() (*State, error) {
259260
&siderolink.Config{},
260261
&siderolink.Status{},
261262
&siderolink.Tunnel{},
263+
&storage.LVMLogicalVolumeStatus{},
264+
&storage.LVMPhysicalVolumeStatus{},
265+
&storage.LVMVolumeGroupStatus{},
262266
&time.AdjtimeStatus{},
263267
&time.Status{},
264268
&v1alpha1.AcquireConfigSpec{},

pkg/lvm/lv.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package lvm
6+
7+
import (
8+
"context"
9+
10+
"github.com/siderolabs/go-cmd/pkg/cmd"
11+
)
12+
13+
// LV represents a logical volume.
14+
type LV struct{}
15+
16+
// LVDisplay returns a list of logical volumes on the system.
17+
func LVDisplay(ctx context.Context) ([]LV, error) {
18+
cmd.RunWithOptions(ctx, "lvdisplay", []string{"-c"})
19+
20+
return nil, nil
21+
}

pkg/lvm/lvm.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
// Package lvm provides a Go interface to the Linux Logical Volume Manager (LVM).
6+
package lvm

pkg/lvm/pv.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package lvm
6+
7+
import (
8+
"context"
9+
10+
"github.com/siderolabs/go-cmd/pkg/cmd"
11+
)
12+
13+
// PV represents a physical volume in LVM.
14+
type PV struct {
15+
}
16+
17+
// PVDisplay retrieves and returns a list of physical volumes (PVs) in the LVM system.
18+
func PVDisplay(ctx context.Context) ([]PV, error) {
19+
cmd.RunWithOptions(ctx, "pvdisplay", []string{"-c"})
20+
21+
return nil, nil
22+
}

pkg/lvm/vg.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package lvm
6+
7+
import (
8+
"context"
9+
10+
"github.com/siderolabs/go-cmd/pkg/cmd"
11+
)
12+
13+
// VG represents a volume group.
14+
type VG struct{}
15+
16+
// VGDisplay returns a list of volume groups on the system.
17+
func VGDisplay(ctx context.Context) ([]VG, error) {
18+
cmd.RunWithOptions(ctx, "vgdisplay", []string{"-c"})
19+
20+
return nil, nil
21+
}

0 commit comments

Comments
 (0)