Skip to content

Commit

Permalink
Merge pull request #115 from nbalacha/crd-changes
Browse files Browse the repository at this point in the history
LVMCluster CRD changes
  • Loading branch information
openshift-merge-robot authored Feb 21, 2022
2 parents 1a0aeb9 + ec88156 commit 3b3bac0
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 123 deletions.
10 changes: 8 additions & 2 deletions api/v1alpha1/lvmcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ type LVMClusterSpec struct {
// Tolerations to apply to nodes to act on
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// DeviceClasses are a rules that assign local storage devices to volumegroups that are used for creating lvm based PVs
// Storage describes the deviceClass configuration for local storage devices
// +Optional
DeviceClasses []DeviceClass `json:"deviceClasses,omitempty"`
Storage Storage `json:"storage,omitempty"`
}

type DeviceClass struct {
Expand Down Expand Up @@ -94,6 +94,12 @@ type DeviceClassStatus struct {
NodeStatus []NodeStatus `json:"nodeStatus,omitempty"`
}

type Storage struct {
// DeviceClasses are a rules that assign local storage devices to volumegroups that are used for creating lvm based PVs
// +Optional
DeviceClasses []DeviceClass `json:"deviceClasses,omitempty"`
}

// NodeStatus defines the observed state of the deviceclass on the node
type NodeStatus struct {
// Node is the name of the node
Expand Down
30 changes: 23 additions & 7 deletions api/v1alpha1/zz_generated.deepcopy.go

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

216 changes: 113 additions & 103 deletions config/crd/bases/lvm.topolvm.io_lvmclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,111 +36,121 @@ spec:
spec:
description: LVMClusterSpec defines the desired state of LVMCluster
properties:
deviceClasses:
description: DeviceClasses are a rules that assign local storage devices
to volumegroups that are used for creating lvm based PVs
items:
properties:
deviceSelector:
description: DeviceSelector is a set of rules that should match
for a device to be included in the LVMCluster
type: object
name:
description: 'Name of the class, the VG and possibly the storageclass.
Validations to confirm that this field can be used as metadata.name
field in storageclass ref: https://github.com/kubernetes/apimachinery/blob/de7147/pkg/util/validation/validation.go#L209'
maxLength: 245
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
nodeSelector:
description: NodeSelector chooses nodes on which to create the
deviceclass
storage:
description: Storage describes the deviceClass configuration for local
storage devices
properties:
deviceClasses:
description: DeviceClasses are a rules that assign local storage
devices to volumegroups that are used for creating lvm based
PVs
items:
properties:
nodeSelectorTerms:
description: Required. A list of node selector terms. The
terms are ORed.
items:
description: A null or empty node selector term matches
no objects. The requirements of them are ANDed. The
TopologySelectorTerm type implements a subset of the
NodeSelectorTerm.
properties:
matchExpressions:
description: A list of node selector requirements
by node's labels.
items:
description: A node selector requirement is a selector
that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: The label key that the selector
applies to.
type: string
operator:
description: Represents a key's relationship
to a set of values. Valid operators are In,
NotIn, Exists, DoesNotExist. Gt, and Lt.
type: string
values:
description: An array of string values. If the
operator is In or NotIn, the values array
must be non-empty. If the operator is Exists
or DoesNotExist, the values array must be
empty. If the operator is Gt or Lt, the values
array must have a single element, which will
be interpreted as an integer. This array is
replaced during a strategic merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchFields:
description: A list of node selector requirements
by node's fields.
items:
description: A node selector requirement is a selector
that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: The label key that the selector
applies to.
type: string
operator:
description: Represents a key's relationship
to a set of values. Valid operators are In,
NotIn, Exists, DoesNotExist. Gt, and Lt.
type: string
values:
description: An array of string values. If the
operator is In or NotIn, the values array
must be non-empty. If the operator is Exists
or DoesNotExist, the values array must be
empty. If the operator is Gt or Lt, the values
array must have a single element, which will
be interpreted as an integer. This array is
replaced during a strategic merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
type: object
type: array
required:
- nodeSelectorTerms
deviceSelector:
description: DeviceSelector is a set of rules that should
match for a device to be included in the LVMCluster
type: object
name:
description: 'Name of the class, the VG and possibly the
storageclass. Validations to confirm that this field can
be used as metadata.name field in storageclass ref: https://github.com/kubernetes/apimachinery/blob/de7147/pkg/util/validation/validation.go#L209'
maxLength: 245
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
nodeSelector:
description: NodeSelector chooses nodes on which to create
the deviceclass
properties:
nodeSelectorTerms:
description: Required. A list of node selector terms.
The terms are ORed.
items:
description: A null or empty node selector term matches
no objects. The requirements of them are ANDed.
The TopologySelectorTerm type implements a subset
of the NodeSelectorTerm.
properties:
matchExpressions:
description: A list of node selector requirements
by node's labels.
items:
description: A node selector requirement is
a selector that contains values, a key, and
an operator that relates the key and values.
properties:
key:
description: The label key that the selector
applies to.
type: string
operator:
description: Represents a key's relationship
to a set of values. Valid operators are
In, NotIn, Exists, DoesNotExist. Gt, and
Lt.
type: string
values:
description: An array of string values.
If the operator is In or NotIn, the values
array must be non-empty. If the operator
is Exists or DoesNotExist, the values
array must be empty. If the operator is
Gt or Lt, the values array must have a
single element, which will be interpreted
as an integer. This array is replaced
during a strategic merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchFields:
description: A list of node selector requirements
by node's fields.
items:
description: A node selector requirement is
a selector that contains values, a key, and
an operator that relates the key and values.
properties:
key:
description: The label key that the selector
applies to.
type: string
operator:
description: Represents a key's relationship
to a set of values. Valid operators are
In, NotIn, Exists, DoesNotExist. Gt, and
Lt.
type: string
values:
description: An array of string values.
If the operator is In or NotIn, the values
array must be non-empty. If the operator
is Exists or DoesNotExist, the values
array must be empty. If the operator is
Gt or Lt, the values array must have a
single element, which will be interpreted
as an integer. This array is replaced
during a strategic merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
type: object
type: array
required:
- nodeSelectorTerms
type: object
type: object
type: object
type: array
type: array
type: object
tolerations:
description: Tolerations to apply to nodes to act on
items:
Expand Down
5 changes: 3 additions & 2 deletions config/samples/lvm_v1alpha1_lvmcluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ kind: LVMCluster
metadata:
name: lvmcluster-sample
spec:
deviceClasses:
- name: vg1
storage:
deviceClasses:
- name: vg1
2 changes: 1 addition & 1 deletion controllers/lvm_volumegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (c lvmVG) getLvmVolumeGroups(r *LVMClusterReconciler, instance *lvmv1alpha1

lvmVolumeGroups := []*lvmv1alpha1.LVMVolumeGroup{}

deviceClasses := instance.Spec.DeviceClasses
deviceClasses := instance.Spec.Storage.DeviceClasses
for _, deviceClass := range deviceClasses {
lvmVolumeGroup := &lvmv1alpha1.LVMVolumeGroup{
ObjectMeta: metav1.ObjectMeta{
Expand Down
6 changes: 4 additions & 2 deletions controllers/lvmcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ var _ = Describe("LVMCluster controller", func() {
Namespace: testLvmClusterNamespace,
},
Spec: lvmv1alpha1.LVMClusterSpec{
DeviceClasses: []lvmv1alpha1.DeviceClass{{Name: testDeviceClassName}},
Storage: lvmv1alpha1.Storage{
DeviceClasses: []lvmv1alpha1.DeviceClass{{Name: testDeviceClassName}},
},
},
}

Expand All @@ -71,7 +73,7 @@ var _ = Describe("LVMCluster controller", func() {

// Topolvm Storage Classes
scNames := []types.NamespacedName{}
for _, deviceClass := range lvmClusterIn.Spec.DeviceClasses {
for _, deviceClass := range lvmClusterIn.Spec.Storage.DeviceClasses {
scNames = append(scNames, types.NamespacedName{
Name: fmt.Sprintf("topolvm-%s", deviceClass.Name),
},
Expand Down
4 changes: 2 additions & 2 deletions controllers/topolvm_storageclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s topolvmStorageClass) ensureDeleted(r *LVMClusterReconciler, ctx context.

// construct name of storage class based on CR spec deviceClass field and
// delete the corresponding storage class
for _, deviceClass := range lvmCluster.Spec.DeviceClasses {
for _, deviceClass := range lvmCluster.Spec.Storage.DeviceClasses {
sc := &storagev1.StorageClass{}
scName := fmt.Sprintf("topolvm-%s", deviceClass.Name)
err := r.Client.Get(ctx, types.NamespacedName{Name: scName}, sc)
Expand Down Expand Up @@ -90,7 +90,7 @@ func getTopolvmStorageClasses(lvmCluster *lvmv1alpha1.LVMCluster) []*storagev1.S
allowVolumeExpansion := true
volumeBindingMode := storagev1.VolumeBindingWaitForFirstConsumer

for _, deviceClass := range lvmCluster.Spec.DeviceClasses {
for _, deviceClass := range lvmCluster.Spec.Storage.DeviceClasses {
storageClass := &storagev1.StorageClass{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("topolvm-%s", deviceClass.Name),
Expand Down
2 changes: 1 addition & 1 deletion controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func extractNodeSelectorAndTolerations(lvmCluster *lvmv1alpha1.LVMCluster) (*cor

terms := make([]corev1.NodeSelectorTerm, 0)
matchAllNodes := false
for _, deviceClass := range lvmCluster.Spec.DeviceClasses {
for _, deviceClass := range lvmCluster.Spec.Storage.DeviceClasses {

if deviceClass.NodeSelector != nil {
terms = append(terms, deviceClass.NodeSelector.NodeSelectorTerms...)
Expand Down
8 changes: 5 additions & 3 deletions controllers/vgmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ func TestVGManagerEnsureCreated(t *testing.T) {
{
desc: "nil nodeSelector in any of the deviceClasses",
lvmclusterSpec: lvmv1alpha1.LVMClusterSpec{
DeviceClasses: []lvmv1alpha1.DeviceClass{
{NodeSelector: nil},
{},
Storage: lvmv1alpha1.Storage{
DeviceClasses: []lvmv1alpha1.DeviceClass{
{NodeSelector: nil},
{},
},
},
},
expectedTolerations: []corev1.Toleration{},
Expand Down

0 comments on commit 3b3bac0

Please sign in to comment.