Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend NodeConfig with loop device management #1691

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,26 @@ spec:
type: string
type: object
type: array
loopDevices:
description: loops is a list of loop device configurations.
items:
description: LoopDeviceConfiguration specifies loop device configuration options.
properties:
imagePath:
description: imagePath specifies path on host where backing image file for loop device should be located.
type: string
name:
description: name specifies the name of the symlink that will point to actual loop device, created under `/dev/loops/`.
type: string
size:
anyOf:
- type: integer
- type: string
description: size specifies the size of the loop device.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
type: array
mounts:
description: mounts is a list of mount configuration.
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ object
* - :ref:`filesystems<api-scylla.scylladb.com-nodeconfigs-v1alpha1-.spec.localDiskSetup.filesystems[]>`
- array (object)
- filesystems is a list of filesystem configurations.
* - :ref:`loopDevices<api-scylla.scylladb.com-nodeconfigs-v1alpha1-.spec.localDiskSetup.loopDevices[]>`
- array (object)
- loops is a list of loop device configurations.
* - :ref:`mounts<api-scylla.scylladb.com-nodeconfigs-v1alpha1-.spec.localDiskSetup.mounts[]>`
- array (object)
- mounts is a list of mount configuration.
Expand Down Expand Up @@ -144,6 +147,37 @@ object
- string
- type is a desired filesystem type.

.. _api-scylla.scylladb.com-nodeconfigs-v1alpha1-.spec.localDiskSetup.loopDevices[]:

.spec.localDiskSetup.loopDevices[]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Description
"""""""""""
LoopDeviceConfiguration specifies loop device configuration options.

Type
""""
object


.. list-table::
:widths: 25 10 150
:header-rows: 1

* - Property
- Type
- Description
* - imagePath
- string
- imagePath specifies path on host where backing image file for loop device should be located.
* - name
- string
- name specifies the name of the symlink that will point to actual loop device, created under `/dev/loops/`.
* - size
-
- size specifies the size of the loop device.

.. _api-scylla.scylladb.com-nodeconfigs-v1alpha1-.spec.localDiskSetup.mounts[]:

.spec.localDiskSetup.mounts[]
Expand Down
20 changes: 20 additions & 0 deletions pkg/api/scylla/v1alpha1/scylla.scylladb.com_nodeconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ spec:
type: string
type: object
type: array
loopDevices:
description: loops is a list of loop device configurations.
items:
description: LoopDeviceConfiguration specifies loop device configuration options.
properties:
imagePath:
description: imagePath specifies path on host where backing image file for loop device should be located.
type: string
name:
description: name specifies the name of the symlink that will point to actual loop device, created under `/dev/loops/`.
type: string
size:
anyOf:
- type: integer
- type: string
description: size specifies the size of the loop device.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
type: array
mounts:
description: mounts is a list of mount configuration.
items:
Expand Down
16 changes: 16 additions & 0 deletions pkg/api/scylla/v1alpha1/types_nodeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -155,8 +156,23 @@ type MountConfiguration struct {
UnsupportedOptions []string `json:"unsupportedOptions"`
}

// LoopDeviceConfiguration specifies loop device configuration options.
type LoopDeviceConfiguration struct {
// name specifies the name of the symlink that will point to actual loop device, created under `/dev/loops/`.
Name string `json:"name"`

// imagePath specifies path on host where backing image file for loop device should be located.
ImagePath string `json:"imagePath"`

// size specifies the size of the loop device.
Size resource.Quantity `json:"size"`
}

// LocalDiskSetup specifies configuration of local disk setup.
type LocalDiskSetup struct {
// loops is a list of loop device configurations.
LoopDevices []LoopDeviceConfiguration `json:"loopDevices"`

// raids is a list of raid configurations.
RAIDs []RAIDConfiguration `json:"raids"`

Expand Down
24 changes: 24 additions & 0 deletions pkg/api/scylla/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pkg/api/scylla/validation/nodeconfig_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package validation

import (
scyllav1alpha1 "github.com/scylladb/scylla-operator/pkg/api/scylla/v1alpha1"
"k8s.io/apimachinery/pkg/api/resource"
apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
)

Expand Down Expand Up @@ -90,5 +92,21 @@ func ValidateNodeConfigUpdate(new, old *scyllav1alpha1.NodeConfig) field.ErrorLi
func ValidateNodeConfigSpecUpdate(new, old *scyllav1alpha1.NodeConfig, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}

oldLoopDevicesSizes := make(map[string]resource.Quantity)
if old.Spec.LocalDiskSetup != nil {
for _, ldc := range old.Spec.LocalDiskSetup.LoopDevices {
oldLoopDevicesSizes[ldc.Name] = ldc.Size
}
}

if new.Spec.LocalDiskSetup != nil {
for i, ld := range new.Spec.LocalDiskSetup.LoopDevices {
oldSize, ok := oldLoopDevicesSizes[ld.Name]
if ok && !ld.Size.Equal(oldSize) {
allErrs = append(allErrs, apimachineryvalidation.ValidateImmutableField(ld.Size.String(), oldSize.String(), fldPath.Child("localDiskSetup", "loopDevices").Index(i).Child("size"))...)
}
}
}

return allErrs
}
31 changes: 31 additions & 0 deletions pkg/api/scylla/validation/nodeconfig_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
package validation_test

import (
"fmt"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
scyllav1alpha1 "github.com/scylladb/scylla-operator/pkg/api/scylla/v1alpha1"
"github.com/scylladb/scylla-operator/pkg/api/scylla/validation"
"github.com/scylladb/scylla-operator/pkg/test/unit"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/validation/field"
)

Expand Down Expand Up @@ -236,6 +238,35 @@ func TestValidateNodeConfigUpdate(t *testing.T) {
},
expectedErrorString: `[spec.localDiskSetup.mounts[1].mountPoint: Duplicate value: "/mnt/foo", spec.localDiskSetup.mounts[3].mountPoint: Duplicate value: "/mnt/bar"]`,
},
{
name: "immutable loop device size",
old: func() *scyllav1alpha1.NodeConfig {
nc := validNodeConfig.DeepCopy()
nc.Spec.LocalDiskSetup.LoopDevices = []scyllav1alpha1.LoopDeviceConfiguration{
{
Name: "foo",
ImagePath: "/mnt/foo.img",
Size: resource.MustParse("100Mi"),
},
}
return nc
}(),
new: func() *scyllav1alpha1.NodeConfig {
nc := validNodeConfig.DeepCopy()
nc.Spec.LocalDiskSetup.LoopDevices = []scyllav1alpha1.LoopDeviceConfiguration{
{
Name: "foo",
ImagePath: "/mnt/foo.img",
Size: resource.MustParse("200Mi"),
},
}
return nc
}(),
expectedErrorList: field.ErrorList{
&field.Error{Type: field.ErrorTypeInvalid, Field: "spec.localDiskSetup.loopDevices[0].size", BadValue: "200Mi", Detail: "field is immutable"},
},
expectedErrorString: fmt.Sprintf(`spec.localDiskSetup.loopDevices[0].size: Invalid value: "200Mi": field is immutable`),
},
}

for i := range tt {
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/nodesetup/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ const (

mountControllerNodeProgressingConditionFormat = "MountControllerNode%sProgressing"
mountControllerNodeDegradedConditionFormat = "MountControllerNode%sDegraded"

loopDeviceControllerNodeProgressingConditionFormat = "LoopDeviceControllerNode%sProgressing"
loopDeviceControllerNodeDegradedConditionFormat = "LoopDeviceControllerNode%sDegraded"
)
13 changes: 13 additions & 0 deletions pkg/controller/nodesetup/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ func (nsc *Controller) sync(ctx context.Context) error {
return nsc.updateNodeStatus(ctx, nc, conditions)
}

err = controllerhelpers.RunSync(
&conditions,
fmt.Sprintf(loopDeviceControllerNodeProgressingConditionFormat, nsc.nodeName),
fmt.Sprintf(loopDeviceControllerNodeDegradedConditionFormat, nsc.nodeName),
nc.Generation,
func() ([]metav1.Condition, error) {
return nsc.syncLoopDevices(ctx, nc)
},
)
if err != nil {
errs = append(errs, fmt.Errorf("can't sync loop devices: %w", err))
}

err = controllerhelpers.RunSync(
&conditions,
fmt.Sprintf(raidControllerNodeProgressingConditionFormat, nsc.nodeName),
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/nodesetup/sync_filesystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (nsc *Controller) syncFilesystems(ctx context.Context, nc *scyllav1alpha1.N
}

for _, fs := range nc.Spec.LocalDiskSetup.Filesystems {
device, err := disks.GetRAIDDeviceWithName(ctx, nsc.executor, nsc.devtmpfsPath, fs.Device)
device, err := disks.GetDeviceWithName(ctx, nsc.executor, nsc.devtmpfsPath, fs.Device)
if err != nil {
errs = append(errs, fmt.Errorf("can't resolve RAID device %q: %w", fs.Device, err))
continue
Expand Down
Loading