Skip to content

Commit

Permalink
[controller] Add a LVMLogicalVolumeWatcher CRDs (#13)
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Kramarenko <[email protected]>
Signed-off-by: Aleksandr Zimin <[email protected]>
Co-authored-by: Aleksandr Zimin <[email protected]>
  • Loading branch information
ViktorKram and AleksZimin authored Feb 16, 2024
1 parent 00af364 commit fd1c9b3
Show file tree
Hide file tree
Showing 19 changed files with 1,286 additions and 386 deletions.
2 changes: 1 addition & 1 deletion .werf/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
image: bundle
from: registry.deckhouse.io/base_images/scratch@sha256:b054705fcc9f2205777d80a558d920c0b4209efdc3163c22b5bfcb5dda1db5fc
fromCacheVersion: "2024-01-05.1"
fromCacheVersion: "2024-02-12.1"
import:
# Rendering .werf/images-digests.yaml is required!
- image: images-digests
Expand Down
80 changes: 80 additions & 0 deletions crds/lvmlogicalvolume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: lvmlogicalvolumes.storage.deckhouse.io
finalizers:
- storage.deckhouse.io/sds-node-configurator
labels:
heritage: deckhouse
module: storage
spec:
group: storage.deckhouse.io
scope: Cluster
names:
kind: LvmLogicalVolume
plural: lvmlogicalvolumes
singular: lvmlogicalvolume
shortNames:
- llv
preserveUnknownFields: false
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
description: |
The LVMLogicalVolume resource defines the storage where a PV will be created in.
properties:
spec:
type: object
description: |
properties:
type:
x-kubernetes-validations:
- rule: self == oldSelf
type: string
enum: [Thick, Thin]
size:
type: string
lvmVolumeGroup:
x-kubernetes-validations:
- rule: self == oldSelf
type: string
thin:
x-kubernetes-validations:
- rule: self == oldSelf
type: object
properties:
poolName:
type: string
status:
type: object
description: |
properties:
phase:
type: string
enum: [Created, Pending, Resizing, Failed]
reason:
type: string
actualSize:
type: string
additionalPrinterColumns:
- jsonPath: .status.phase
name: Phase
type: string
description: The current resource status.
- jsonPath: .spec.lvmVolumeGroup
name: LVMVolumeGroup
type: string
description: The selected LVMVolumeGroup resource.
- jsonPath: .spec.thin.poolName
name: ThinPool
type: string
description: The selected ThinPool in LVMVolumeGroup. Might be empty if the LVMVolumeGroup is thick.
- jsonPath: .status.actualSize
name: Size
type: string
description: Actual LVMLogicalVolume size.
54 changes: 54 additions & 0 deletions images/agent/api/v1alpha1/lvm_logical_volume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright 2023 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.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

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

type LvmLogicalVolumeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []LvmLogicalVolume `json:"items"`
}

type LvmLogicalVolume struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec LvmLogicalVolumeSpec `json:"spec"`
Status *LvmLogicalVolumeStatus `json:"status,omitempty"`
}

type LvmLogicalVolumeSpec struct {
Type string `json:"type"`
Size resource.Quantity `json:"size"`
LvmVolumeGroup string `json:"lvmVolumeGroup"`
Thin *ThinLogicalVolumeSpec `json:"thin"`
}

type ThinLogicalVolumeSpec struct {
PoolName string `json:"poolName"`
}

type LvmLogicalVolumeStatus struct {
Phase string `json:"phase"`
Reason string `json:"reason"`
ActualSize resource.Quantity `json:"actualSize"`
}
3 changes: 3 additions & 0 deletions images/agent/api/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
const (
BlockDeviceKind = "BlockDevice"
LVMVolumeGroupKind = "LvmVolumeGroup"
LVMLogicalVolumeKind = "LvmLogicalVolume"
APIGroup = "storage.deckhouse.io"
APIVersion = "v1alpha1"
OwnerReferencesAPIVersion = "v1"
Expand All @@ -49,6 +50,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&BlockDeviceList{},
&LvmVolumeGroup{},
&LvmVolumeGroupList{},
&LvmLogicalVolume{},
&LvmLogicalVolumeList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
58 changes: 58 additions & 0 deletions images/agent/api/v1alpha1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,61 @@ func (in *LvmVolumeGroupList) DeepCopyObject() runtime.Object {
}
return nil
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *LvmLogicalVolume) DeepCopyInto(out *LvmLogicalVolume) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)

}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EmptyBlockDevice.
func (in *LvmLogicalVolume) DeepCopy() *LvmLogicalVolume {
if in == nil {
return nil
}
out := new(LvmLogicalVolume)
in.DeepCopyInto(out)
return out
}

// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *LvmLogicalVolume) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *LvmLogicalVolumeList) DeepCopyInto(out *LvmLogicalVolumeList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]LvmLogicalVolume, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GuestbookList.
func (in *LvmLogicalVolumeList) DeepCopy() *LvmLogicalVolumeList {
if in == nil {
return nil
}
out := new(LvmLogicalVolumeList)
in.DeepCopyInto(out)
return out
}

// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *LvmLogicalVolumeList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
19 changes: 12 additions & 7 deletions images/agent/cmd/bc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,33 @@ func main() {
}
log.Info("[main] ReTag ends")

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

if _, err := controller.RunWatcherLVMVGController(mgr, *cfgParams, *log, metrics); err != nil {
log.Error(err, "[main] error Run RunLVMVolumeGroupController")
if _, err = controller.RunLVMVolumeGroupWatcherController(mgr, *cfgParams, *log, metrics); err != nil {
log.Error(err, "[main] unable to controller.RunLVMVolumeGroupWatcherController")
os.Exit(1)
}

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

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
if _, err = controller.RunLVMLogicalVolumeWatcherController(mgr, *cfgParams, *log, metrics); err != nil {
log.Error(err, "[main] unable to controller.RunLVMLogicalVolumeWatcherController")
os.Exit(1)
}

if err = mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
log.Error(err, "[main] unable to mgr.AddHealthzCheck")
os.Exit(1)
}
log.Info("[main] successfully AddHealthzCheck")

if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
if err = mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
log.Error(err, "[main] unable to mgr.AddReadyzCheck")
os.Exit(1)
}
Expand Down
13 changes: 11 additions & 2 deletions images/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ limitations under the License.
package config

import (
"bytes"
"fmt"
"os"
"os/exec"
"sds-node-configurator/pkg/logger"
"time"
)
Expand Down Expand Up @@ -75,12 +77,19 @@ func NewConfig() (*Options, error) {
func getMachineId() (string, error) {
id := os.Getenv(MachineID)
if id == "" {
byteId, err := os.ReadFile("/host-root/etc/machine-id")
args := []string{"-m", "-u", "-i", "-n", "-p", "-t", "1", "cat", "/etc/machine-id"}

var stdout bytes.Buffer
cmd := exec.Command("/usr/bin/nsenter", args...)
cmd.Stdout = &stdout
err := cmd.Run()
if err != nil {
return "", err
}

id = string(byteId)
id = stdout.String()
fmt.Println("MACHINE ID " + id)

}

return id, nil
Expand Down
30 changes: 16 additions & 14 deletions images/agent/internal/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ limitations under the License.
package internal

const (
TypePart = "part"
DRBDName = "/dev/drbd"
LoopDeviceType = "loop"
LVMDeviceType = "lvm"
LVMFSType = "LVM2_member"
SdsNodeConfigurator = "storage.deckhouse.io/sds-node-configurator"
LVMVGHealthOperational = "Operational"
LVMVGHealthNonOperational = "NonOperational"
TypePart = "part"
DRBDName = "/dev/drbd"
LoopDeviceType = "loop"
LVMDeviceType = "lvm"
LVMFSType = "LVM2_member"
SdsNodeConfiguratorFinalizer = "storage.deckhouse.io/sds-node-configurator"
LVMVGHealthOperational = "Operational"
LVMVGHealthNonOperational = "NonOperational"
BlockDeviceValidSize = "1G"
ResizeDelta = "32Mi"
KubernetesApiRequestLimit = 5
KubernetesApiRequestTimeout = 1
)

var (
AllowedFSTypes = [...]string{LVMFSType}
InvalidDeviceTypes = [...]string{LoopDeviceType, LVMDeviceType}
BlockDeviceValidSize = "1G"
ResizeDelta = "32Mi"
Finalizers = []string{SdsNodeConfigurator}
LVMTags = []string{"storage.deckhouse.io/enabled=true", "linstor-"}
AllowedFSTypes = [...]string{LVMFSType}
InvalidDeviceTypes = [...]string{LoopDeviceType, LVMDeviceType}
Finalizers = []string{SdsNodeConfiguratorFinalizer}
LVMTags = []string{"storage.deckhouse.io/enabled=true", "linstor-"}
)
Loading

0 comments on commit fd1c9b3

Please sign in to comment.