Skip to content

Commit

Permalink
created crd and api-models, renamed files for better reading
Browse files Browse the repository at this point in the history
Signed-off-by: viktor.kramarenko <[email protected]>
  • Loading branch information
ViktorKram committed Jan 17, 2024
1 parent f669618 commit 44a074d
Show file tree
Hide file tree
Showing 13 changed files with 373 additions and 139 deletions.
67 changes: 67 additions & 0 deletions crds/lvmlogicalvolume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: lvmlogicalvolumes.storage.deckhouse.io
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:
type: string
enum: [Thick, Thin]
size:
type: string
lvmVolumeGroup:
type: string
thin:
type: object
properties:
poolName: string
status:
type: object
description: |
properties:
phase:
type: string
enum: [Created, Failed]
reason:
type: string
actualSize:
type: string
additionalPrinterColumns:
- jsonPath: .spec.lvmVolumeGroup
name: LVMVolumeGroup
type: string
description: The selected LVMVolumeGroup resource.
- jsonPath: .spec.thinPoolName
name: ThinPool
type: string
description: The selected ThinPool in LVMVolumeGroup. Might be empty if the LVMVolumeGroup is thick.
- jsonPath: .status.size
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
}
6 changes: 3 additions & 3 deletions images/agent/cmd/bc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ func main() {
os.Exit(1)
}

if _, err := controller.RunWatcherLVMVGController(mgr, *cfgParams, *log, metrics); err != nil {
if _, err := controller.RunLVMVolumeGroupWatcherController(mgr, *cfgParams, *log, metrics); err != nil {
log.Error(err, "[main] error Run RunLVMVolumeGroupController")
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)
}

Expand Down
51 changes: 51 additions & 0 deletions images/agent/pkg/controller/lvm_logical_volume_watcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package controller

import (
"context"
"sds-node-configurator/api/v1alpha1"
"sds-node-configurator/config"
"sds-node-configurator/pkg/logger"
"sds-node-configurator/pkg/monitoring"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

const (
LVMLogicalVolumeWatcherCtrlName = "lvm-logical-volume-watcher-controller"
)

func RunLVMLogicalVolumeController(
mgr manager.Manager,
cfg config.Options,
log logger.Logger,
metrics monitoring.Metrics,
) (controller.Controller, error) {
//cl := mgr.GetClient()
cache := mgr.GetCache()

c, err := controller.New(LVMLogicalVolumeWatcherCtrlName, mgr, controller.Options{
Reconciler: reconcile.Func(func(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
return reconcile.Result{}, nil
}),
})
if err != nil {
log.Error(err, "[RunLVMLogicalVolumeController] unable to create controller")
return nil, err
}

err = c.Watch(source.Kind(cache, &v1alpha1.LVMLogicalVolume{}), handler.Funcs{
CreateFunc: nil,
UpdateFunc: nil,
DeleteFunc: nil,
GenericFunc: nil,
})
if err != nil {
log.Error(err, "[RunLVMLogicalVolumeController] the controller is unable to watch")
return nil, err
}

return c, err
}
Loading

0 comments on commit 44a074d

Please sign in to comment.