From 64a75b134cc1b2cc00e811e37f52cdd41aab4e32 Mon Sep 17 00:00:00 2001 From: "viktor.kramarenko" Date: Wed, 17 Jan 2024 12:22:53 +0300 Subject: [PATCH] created crd and api-models, renamed files for better reading Signed-off-by: viktor.kramarenko --- crds/lvmlogicalvolume.yaml | 68 ++++++++++ .../agent/api/v1alpha1/lvm_logical_volume.go | 52 ++++++++ images/agent/api/v1alpha1/register.go | 3 + .../api/v1alpha1/zz_generated.deepcopy.go | 58 +++++++++ images/agent/cmd/bc/main.go | 6 +- .../controller/lvm_logical_volume_watcher.go | 51 ++++++++ ..._group.go => lvm_volume_group_discover.go} | 88 ++++++------- ...t.go => lvm_volume_group_discover_test.go} | 0 ...e_group.go => lvm_volume_group_watcher.go} | 64 +++++----- ... => lvm_volume_group_watcher_constants.go} | 0 ...nc.go => lvm_volume_group_watcher_func.go} | 116 +++++++++--------- ...st.go => lvm_volume_group_watcher_test.go} | 4 +- 12 files changed, 371 insertions(+), 139 deletions(-) create mode 100644 crds/lvmlogicalvolume.yaml create mode 100644 images/agent/api/v1alpha1/lvm_logical_volume.go create mode 100644 images/agent/pkg/controller/lvm_logical_volume_watcher.go rename images/agent/pkg/controller/{discover_lvm_volume_group.go => lvm_volume_group_discover.go} (86%) rename images/agent/pkg/controller/{discover_lvm_volume_group_test.go => lvm_volume_group_discover_test.go} (100%) rename images/agent/pkg/controller/{watcher_lvm_volume_group.go => lvm_volume_group_watcher.go} (84%) rename images/agent/pkg/controller/{watcher_lvm_volume_group_constants.go => lvm_volume_group_watcher_constants.go} (100%) rename images/agent/pkg/controller/{watcher_lvm_volume_group_func.go => lvm_volume_group_watcher_func.go} (69%) rename images/agent/pkg/controller/{watcher_lvm_volume_group_test.go => lvm_volume_group_watcher_test.go} (99%) diff --git a/crds/lvmlogicalvolume.yaml b/crds/lvmlogicalvolume.yaml new file mode 100644 index 00000000..59f79737 --- /dev/null +++ b/crds/lvmlogicalvolume.yaml @@ -0,0 +1,68 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: logicalvolume.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: | + properties: + spec: + type: object + description: | + properties: + type: + type: string + enum: [Thick, Thin] + size: + type: string + lvmVolumeGroup: + type: string + thinPoolName: + type: string + source: + type: string + status: + type: object + description: | + properties: + phase: + type: string + enum: [Created, Failed] + reason: + type: string + size: + type: string + actualVGNameOnTheNode: + 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. diff --git a/images/agent/api/v1alpha1/lvm_logical_volume.go b/images/agent/api/v1alpha1/lvm_logical_volume.go new file mode 100644 index 00000000..84407974 --- /dev/null +++ b/images/agent/api/v1alpha1/lvm_logical_volume.go @@ -0,0 +1,52 @@ +/* +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"` + ThinPoolName string `json:"thinPoolName"` + Source string `json:"source"` +} + +type LVMLogicalVolumeStatus struct { + Phase string `json:"phase"` + Reason string `json:"reason"` + Size resource.Quantity `json:"size"` + ActualVGNameOnTheNode string `json:"actualVGNameOnTheNode"` +} diff --git a/images/agent/api/v1alpha1/register.go b/images/agent/api/v1alpha1/register.go index bed80762..e9627be5 100644 --- a/images/agent/api/v1alpha1/register.go +++ b/images/agent/api/v1alpha1/register.go @@ -25,6 +25,7 @@ import ( const ( BlockDeviceKind = "BlockDevice" LVMVolumeGroupKind = "LvmVolumeGroup" + LVMLogicalVolumeKind = "LvmLogicalVolume" APIGroup = "storage.deckhouse.io" APIVersion = "v1alpha1" OwnerReferencesAPIVersion = "v1" @@ -49,6 +50,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &BlockDeviceList{}, &LvmVolumeGroup{}, &LvmVolumeGroupList{}, + &LVMLogicalVolume{}, + &LVMLogicalVolumeList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/images/agent/api/v1alpha1/zz_generated.deepcopy.go b/images/agent/api/v1alpha1/zz_generated.deepcopy.go index cb5b78d3..cf24bd03 100644 --- a/images/agent/api/v1alpha1/zz_generated.deepcopy.go +++ b/images/agent/api/v1alpha1/zz_generated.deepcopy.go @@ -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 +} diff --git a/images/agent/cmd/bc/main.go b/images/agent/cmd/bc/main.go index a8ec04fe..739e992b 100644 --- a/images/agent/cmd/bc/main.go +++ b/images/agent/cmd/bc/main.go @@ -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) } diff --git a/images/agent/pkg/controller/lvm_logical_volume_watcher.go b/images/agent/pkg/controller/lvm_logical_volume_watcher.go new file mode 100644 index 00000000..9469f4ed --- /dev/null +++ b/images/agent/pkg/controller/lvm_logical_volume_watcher.go @@ -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 +} diff --git a/images/agent/pkg/controller/discover_lvm_volume_group.go b/images/agent/pkg/controller/lvm_volume_group_discover.go similarity index 86% rename from images/agent/pkg/controller/discover_lvm_volume_group.go rename to images/agent/pkg/controller/lvm_volume_group_discover.go index 751020d5..ceee1dea 100644 --- a/images/agent/pkg/controller/discover_lvm_volume_group.go +++ b/images/agent/pkg/controller/lvm_volume_group_discover.go @@ -43,9 +43,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/source" ) -const discoveryLVMVGCtrlName = "discover-lvmvg-controller" +const LVMVolumeGroupDiscoverCtrlName = "lvm-volume-group-discover-controller" -func RunDiscoveryLVMVGController( +func RunLVMVolumeGroupDiscoverController( ctx context.Context, mgr manager.Manager, cfg config.Options, @@ -55,53 +55,53 @@ func RunDiscoveryLVMVGController( cl := mgr.GetClient() cache := mgr.GetCache() - c, err := controller.New(discoveryLVMVGCtrlName, mgr, controller.Options{ + c, err := controller.New(LVMVolumeGroupDiscoverCtrlName, 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, fmt.Sprintf(`[RunDiscoveryLVMVGController] unable to create controller: "%s"`, discoveryLVMVGCtrlName)) + log.Error(err, fmt.Sprintf(`[RunLVMVolumeGroupDiscoverController] unable to create controller: "%s"`, LVMVolumeGroupDiscoverCtrlName)) return nil, err } err = c.Watch(source.Kind(cache, &v1alpha1.LvmVolumeGroup{}), &handler.EnqueueRequestForObject{}) if err != nil { - log.Error(err, fmt.Sprintf(`[RunDiscoveryLVMVGController] unable to run "%s" controller watch`, discoveryLVMVGCtrlName)) + log.Error(err, fmt.Sprintf(`[RunLVMVolumeGroupDiscoverController] unable to run "%s" controller watch`, LVMVolumeGroupDiscoverCtrlName)) } - log.Info("[RunDiscoveryLVMVGController] run discovery loop") + log.Info("[RunLVMVolumeGroupDiscoverController] run discovery loop") go func() { for { time.Sleep(cfg.VolumeGroupScanInterval * time.Second) reconcileStart := time.Now() - log.Info("[RunDiscoveryLVMVGController] START discovery loop") + log.Info("[RunLVMVolumeGroupDiscoverController] START discovery loop") currentLVMVGs, err := GetAPILVMVolumeGroups(ctx, cl, metrics) if err != nil { - log.Error(err, "[RunDiscoveryLVMVGController] unable to run GetAPILVMVolumeGroups") + log.Error(err, "[RunLVMVolumeGroupDiscoverController] unable to run GetAPILVMVolumeGroups") continue } blockDevices, err := GetAPIBlockDevices(ctx, cl, metrics) if err != nil { - log.Error(err, "[RunDiscoveryLVMVGController] unable to GetAPIBlockDevices") + log.Error(err, "[RunLVMVolumeGroupDiscoverController] unable to GetAPIBlockDevices") for _, lvm := range currentLVMVGs { if err = turnLVMVGHealthToNonOperational(ctx, cl, lvm, err); err != nil { - log.Error(err, fmt.Sprintf(`[RunDiscoveryLVMVGController] unable to change health param in LVMVolumeGroup, name: "%s"`, lvm.Name)) + log.Error(err, fmt.Sprintf(`[RunLVMVolumeGroupDiscoverController] unable to change health param in LVMVolumeGroup, name: "%s"`, lvm.Name)) } } continue } if len(blockDevices) == 0 { - log.Error(fmt.Errorf("no block devices found"), "[RunDiscoveryLVMVGController] unable to get block devices") + log.Error(fmt.Errorf("no block devices found"), "[RunLVMVolumeGroupDiscoverController] unable to get block devices") for _, lvm := range currentLVMVGs { if err = turnLVMVGHealthToNonOperational(ctx, cl, lvm, fmt.Errorf("no block devices found")); err != nil { - log.Error(err, fmt.Sprintf(`[RunDiscoveryLVMVGController] unable to change health param in LVMVolumeGroup, name: "%s"`, lvm.Name)) + log.Error(err, fmt.Sprintf(`[RunLVMVolumeGroupDiscoverController] unable to change health param in LVMVolumeGroup, name: "%s"`, lvm.Name)) } } continue @@ -111,10 +111,10 @@ func RunDiscoveryLVMVGController( candidates, err := GetLVMVolumeGroupCandidates(log, metrics, blockDevices, cfg.NodeName) if err != nil { - log.Error(err, "[RunDiscoveryLVMVGController] unable to run GetLVMVolumeGroupCandidates") + log.Error(err, "[RunLVMVolumeGroupDiscoverController] unable to run GetLVMVolumeGroupCandidates") for _, lvm := range filteredResources { if err = turnLVMVGHealthToNonOperational(ctx, cl, lvm, err); err != nil { - log.Error(err, fmt.Sprintf(`[RunDiscoveryLVMVGController] unable to change health param in LVMVolumeGroup, name: "%s"`, lvm.Name)) + log.Error(err, fmt.Sprintf(`[RunLVMVolumeGroupDiscoverController] unable to change health param in LVMVolumeGroup, name: "%s"`, lvm.Name)) } } continue @@ -123,36 +123,36 @@ func RunDiscoveryLVMVGController( for _, candidate := range candidates { if lvmVolumeGroup := getResourceByCandidate(filteredResources, candidate); lvmVolumeGroup != nil { if !hasLVMVolumeGroupDiff(log, *lvmVolumeGroup, candidate) { - log.Debug(fmt.Sprintf(`[RunDiscoveryLVMVGController] no data to update for LvmVolumeGroup, name: "%s"`, lvmVolumeGroup.Name)) + log.Debug(fmt.Sprintf(`[RunLVMVolumeGroupDiscoverController] no data to update for LvmVolumeGroup, name: "%s"`, lvmVolumeGroup.Name)) continue } //TODO: take lock - log.Debug(fmt.Sprintf("[RunDiscoveryLVMVGController] run UpdateLVMVolumeGroupByCandidate, lvmVolumeGroup name: %s", lvmVolumeGroup.Name)) + log.Debug(fmt.Sprintf("[RunLVMVolumeGroupDiscoverController] run UpdateLVMVolumeGroupByCandidate, lvmVolumeGroup name: %s", lvmVolumeGroup.Name)) if err = UpdateLVMVolumeGroupByCandidate(ctx, cl, metrics, *lvmVolumeGroup, candidate); err != nil { - log.Error(err, fmt.Sprintf(`[RunDiscoveryLVMVGController] unable to update LvmVolumeGroup, name: "%s"`, + log.Error(err, fmt.Sprintf(`[RunLVMVolumeGroupDiscoverController] unable to update LvmVolumeGroup, name: "%s"`, lvmVolumeGroup.Name)) continue } - log.Info(fmt.Sprintf(`[RunDiscoveryLVMVGController] updated LvmVolumeGroup, name: "%s"`, lvmVolumeGroup.Name)) + log.Info(fmt.Sprintf(`[RunLVMVolumeGroupDiscoverController] updated LvmVolumeGroup, name: "%s"`, lvmVolumeGroup.Name)) //TODO: release lock } else { lvm, err := CreateLVMVolumeGroup(ctx, log, metrics, cl, candidate) if err != nil { - log.Error(err, "[RunDiscoveryLVMVGController] unable to CreateLVMVolumeGroup") + log.Error(err, "[RunLVMVolumeGroupDiscoverController] unable to CreateLVMVolumeGroup") continue } - log.Info(fmt.Sprintf(`[RunDiscoveryLVMVGController] created new APILVMVolumeGroup, name: "%s"`, lvm.Name)) + log.Info(fmt.Sprintf(`[RunLVMVolumeGroupDiscoverController] created new APILVMVolumeGroup, name: "%s"`, lvm.Name)) } } ClearLVMVolumeGroupResources(ctx, cl, log, metrics, candidates, filteredResources, cfg.NodeName) - log.Info("[RunDiscoveryLVMVGController] END discovery loop") - metrics.ReconcileDuration(discoveryLVMVGCtrlName).Observe(metrics.GetEstimatedTimeInSeconds(reconcileStart)) - metrics.ReconcilesCountTotal(discoveryLVMVGCtrlName).Inc() + log.Info("[RunLVMVolumeGroupDiscoverController] END discovery loop") + metrics.ReconcileDuration(LVMVolumeGroupDiscoverCtrlName).Observe(metrics.GetEstimatedTimeInSeconds(reconcileStart)) + metrics.ReconcilesCountTotal(LVMVolumeGroupDiscoverCtrlName).Inc() } }() @@ -320,10 +320,10 @@ func DeleteLVMVolumeGroup(ctx context.Context, kc kclient.Client, metrics monito start := time.Now() err := kc.Delete(ctx, lvm) - metrics.ApiMethodsDuration(discoveryLVMVGCtrlName, "delete").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.ApiMethodsExecutionCount(discoveryLVMVGCtrlName, "delete").Inc() + metrics.ApiMethodsDuration(LVMVolumeGroupDiscoverCtrlName, "delete").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.ApiMethodsExecutionCount(LVMVolumeGroupDiscoverCtrlName, "delete").Inc() if err != nil { - metrics.ApiMethodsErrors(discoveryLVMVGCtrlName, "delete").Inc() + metrics.ApiMethodsErrors(LVMVolumeGroupDiscoverCtrlName, "delete").Inc() return err } return nil @@ -334,13 +334,13 @@ func GetLVMVolumeGroupCandidates(log logger.Logger, metrics monitoring.Metrics, start := time.Now() vgs, cmdStr, vgErrs, err := utils.GetAllVGs() - metrics.UtilsCommandsDuration(discoveryLVMVGCtrlName, "vgs").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(discoveryLVMVGCtrlName, "vgs").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupDiscoverCtrlName, "vgs").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupDiscoverCtrlName, "vgs").Inc() log.Debug(fmt.Sprintf("[GetLVMVolumeGroupCandidates] exec cmd: %s", cmdStr)) // If we can't run vgs command at all, that means we will not have important information, so we break. if err != nil { - metrics.UtilsCommandsErrorsCount(discoveryLVMVGCtrlName, "vgs").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupDiscoverCtrlName, "vgs").Inc() log.Error(err, "[GetLVMVolumeGroupCandidates] unable to GetAllVGs") return nil, err } @@ -360,13 +360,13 @@ func GetLVMVolumeGroupCandidates(log logger.Logger, metrics monitoring.Metrics, start = time.Now() pvs, cmdStr, pvErrs, err := utils.GetAllPVs() - metrics.UtilsCommandsDuration(discoveryLVMVGCtrlName, "pvs").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(discoveryLVMVGCtrlName, "pvs").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupDiscoverCtrlName, "pvs").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupDiscoverCtrlName, "pvs").Inc() log.Debug(fmt.Sprintf("[GetLVMVolumeGroupCandidates] exec cmd: %s", cmdStr)) // If we can't run pvs command at all, that means we will not have important information, so we break. if err != nil { - metrics.UtilsCommandsErrorsCount(discoveryLVMVGCtrlName, "pvs").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupDiscoverCtrlName, "pvs").Inc() log.Error(err, "[GetLVMVolumeGroupCandidates] unable to GetAllPVs") return nil, err } @@ -379,13 +379,13 @@ func GetLVMVolumeGroupCandidates(log logger.Logger, metrics monitoring.Metrics, start = time.Now() lvs, cmdStr, lvErrs, err := utils.GetAllLVs() - metrics.UtilsCommandsDuration(discoveryLVMVGCtrlName, "lvs").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(discoveryLVMVGCtrlName, "lvs").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupDiscoverCtrlName, "lvs").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupDiscoverCtrlName, "lvs").Inc() log.Debug(fmt.Sprintf("[GetLVMVolumeGroupCandidates] exec cmd: %s", cmdStr)) // As long as LVS data is used to fill ThinPool fields, that is optional, we won't break but log the error. if err != nil { - metrics.UtilsCommandsErrorsCount(discoveryLVMVGCtrlName, "lvs").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupDiscoverCtrlName, "lvs").Inc() log.Error(err, "[GetLVMVolumeGroupCandidates] unable to GetAllLVs") } @@ -765,10 +765,10 @@ func CreateLVMVolumeGroup( start := time.Now() err := kc.Create(ctx, lvmVolumeGroup) - metrics.ApiMethodsDuration(discoveryLVMVGCtrlName, "create").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.ApiMethodsExecutionCount(discoveryLVMVGCtrlName, "create").Inc() + metrics.ApiMethodsDuration(LVMVolumeGroupDiscoverCtrlName, "create").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.ApiMethodsExecutionCount(LVMVolumeGroupDiscoverCtrlName, "create").Inc() if err != nil { - metrics.ApiMethodsErrors(discoveryLVMVGCtrlName, "create").Inc() + metrics.ApiMethodsErrors(LVMVolumeGroupDiscoverCtrlName, "create").Inc() return nil, fmt.Errorf("unable to CreateLVMVolumeGroup, err: %w", err) } @@ -838,10 +838,10 @@ func UpdateLVMVolumeGroupByCandidate( start := time.Now() err := kc.Update(ctx, lvmvg) - metrics.ApiMethodsDuration(discoveryLVMVGCtrlName, "update").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.ApiMethodsExecutionCount(discoveryLVMVGCtrlName, "update").Inc() + metrics.ApiMethodsDuration(LVMVolumeGroupDiscoverCtrlName, "update").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.ApiMethodsExecutionCount(LVMVolumeGroupDiscoverCtrlName, "update").Inc() if err != nil { - metrics.ApiMethodsErrors(discoveryLVMVGCtrlName, "update").Inc() + metrics.ApiMethodsErrors(LVMVolumeGroupDiscoverCtrlName, "update").Inc() return fmt.Errorf(`[UpdateLVMVolumeGroupByCandidate] unable to update LVMVolumeGroup, name: "%s", err: %w`, lvmvg.Name, err) } @@ -925,10 +925,10 @@ func GetAPILVMVolumeGroups(ctx context.Context, kc kclient.Client, metrics monit start := time.Now() err := kc.List(ctx, listLvms) - metrics.ApiMethodsDuration(discoveryLVMVGCtrlName, "list").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.ApiMethodsExecutionCount(discoveryLVMVGCtrlName, "list").Inc() + metrics.ApiMethodsDuration(LVMVolumeGroupDiscoverCtrlName, "list").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.ApiMethodsExecutionCount(LVMVolumeGroupDiscoverCtrlName, "list").Inc() if err != nil { - metrics.ApiMethodsErrors(discoveryLVMVGCtrlName, "list").Inc() + metrics.ApiMethodsErrors(LVMVolumeGroupDiscoverCtrlName, "list").Inc() return nil, fmt.Errorf("[GetApiLVMVolumeGroups] unable to list lvm volume groups, err: %w", err) } diff --git a/images/agent/pkg/controller/discover_lvm_volume_group_test.go b/images/agent/pkg/controller/lvm_volume_group_discover_test.go similarity index 100% rename from images/agent/pkg/controller/discover_lvm_volume_group_test.go rename to images/agent/pkg/controller/lvm_volume_group_discover_test.go diff --git a/images/agent/pkg/controller/watcher_lvm_volume_group.go b/images/agent/pkg/controller/lvm_volume_group_watcher.go similarity index 84% rename from images/agent/pkg/controller/watcher_lvm_volume_group.go rename to images/agent/pkg/controller/lvm_volume_group_watcher.go index 63d01797..5ec29ec0 100644 --- a/images/agent/pkg/controller/watcher_lvm_volume_group.go +++ b/images/agent/pkg/controller/lvm_volume_group_watcher.go @@ -44,10 +44,10 @@ import ( ) const ( - watcherLVMVGCtrlName = "watcher-lvmvg-controller" + LVMVolumeGroupWatcherCtrlName = "lvm-volume-group-watcher-controller" ) -func RunWatcherLVMVGController( +func RunLVMVolumeGroupWatcherController( mgr manager.Manager, cfg config.Options, log logger.Logger, @@ -56,9 +56,9 @@ func RunWatcherLVMVGController( cl := mgr.GetClient() cache := mgr.GetCache() - c, err := controller.New(watcherLVMVGCtrlName, mgr, controller.Options{ + c, err := controller.New(LVMVolumeGroupWatcherCtrlName, mgr, controller.Options{ Reconciler: reconcile.Func(func(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { - log.Info(fmt.Sprintf(`Reconcile of RunWatcherLVMVGController on request, name: "%s" starts`, request.Name)) + log.Info(fmt.Sprintf(`Reconcile of RunLVMVolumeGroupWatcherController on request, name: "%s" starts`, request.Name)) shouldRequeue, err := ReconcileLVMVG(ctx, metrics, request.Name, request.Namespace, cfg.NodeName, log, cl) if shouldRequeue { @@ -68,14 +68,14 @@ func RunWatcherLVMVGController( RequeueAfter: cfg.VolumeGroupScanInterval * time.Second, }, nil } - log.Info(fmt.Sprintf(`Reconcile of RunWatcherLVMVGController on request, name: "%s" ends`, request.Name)) + log.Info(fmt.Sprintf(`Reconcile of RunLVMVolumeGroupWatcherController on request, name: "%s" ends`, request.Name)) return reconcile.Result{}, nil }), }) if err != nil { - log.Error(err, "[RunWatcherLVMVGController] Unable to create controller RunWatcherLVMVGController") + log.Error(err, "[RunLVMVolumeGroupWatcherController] Unable to create controller RunLVMVolumeGroupWatcherController") return nil, err } @@ -85,31 +85,31 @@ func RunWatcherLVMVGController( request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.Object.GetNamespace(), Name: e.Object.GetName()}} shouldRequeue, err := ReconcileLVMVG(ctx, metrics, e.Object.GetName(), e.Object.GetNamespace(), cfg.NodeName, log, cl) if shouldRequeue { - log.Error(err, fmt.Sprintf("[RunWatcherLVMVGController] An error has occured in ReconcileLVMVG. Adds to retry after %d seconds.", cfg.VolumeGroupScanInterval)) + log.Error(err, fmt.Sprintf("[RunLVMVolumeGroupWatcherController] An error has occured in ReconcileLVMVG. Adds to retry after %d seconds.", cfg.VolumeGroupScanInterval)) q.AddAfter(request, cfg.VolumeGroupScanInterval*time.Second) log.Warning(fmt.Sprintf(`Added request, namespace: "%s" name: "%s", to requeue`, request.Namespace, request.Name)) } } updateFunc := func(ctx context.Context, e event.UpdateEvent, q workqueue.RateLimitingInterface) { - log.Info(fmt.Sprintf("[RunWatcherLVMVGController] update LVMVolumeGroupn, name: %s", e.ObjectNew.GetName())) + log.Info(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] update LVMVolumeGroupn, name: %s", e.ObjectNew.GetName())) newLVG, ok := e.ObjectNew.(*v1alpha1.LvmVolumeGroup) if !ok { - log.Error(err, "[RunWatcherLVMVGController] error get ObjectNew LinstorStoragePool") + log.Error(err, "[RunLVMVolumeGroupWatcherController] error get ObjectNew LinstorStoragePool") } oldLVG, ok := e.ObjectOld.(*v1alpha1.LvmVolumeGroup) if !ok { - log.Error(err, "[RunWatcherLVMVGController] error get ObjectOld LinstorStoragePool") + log.Error(err, "[RunLVMVolumeGroupWatcherController] error get ObjectOld LinstorStoragePool") } if !reflect.DeepEqual(oldLVG.Annotations, newLVG.Annotations) { - log.Info("[RunWatcherLVMVGController] annotations update") + log.Info("[RunLVMVolumeGroupWatcherController] annotations update") request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.ObjectNew.GetNamespace(), Name: e.ObjectNew.GetName()}} shouldRequeue, err := ReconcileLVMVG(ctx, metrics, e.ObjectNew.GetName(), e.ObjectNew.GetNamespace(), cfg.NodeName, log, cl) if shouldRequeue { - log.Error(err, fmt.Sprintf("[RunWatcherLVMVGController] An error has occured in ReconcileLVMVG. Adds to retry after %d seconds.", cfg.VolumeGroupScanInterval)) + log.Error(err, fmt.Sprintf("[RunLVMVolumeGroupWatcherController] An error has occured in ReconcileLVMVG. Adds to retry after %d seconds.", cfg.VolumeGroupScanInterval)) q.AddAfter(request, cfg.VolumeGroupScanInterval*time.Second) log.Warning(fmt.Sprintf(`Added request, namespace: "%s" name: "%s", to requeue`, request.Namespace, request.Name)) } @@ -117,12 +117,12 @@ func RunWatcherLVMVGController( } if !reflect.DeepEqual(oldLVG.Spec, newLVG.Spec) { - log.Info("[RunWatcherLVMVGController] lvg spec changed") + log.Info("[RunLVMVolumeGroupWatcherController] lvg spec changed") request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.ObjectNew.GetNamespace(), Name: e.ObjectNew.GetName()}} shouldRequeue, err := ReconcileLVMVG(ctx, metrics, e.ObjectNew.GetName(), e.ObjectNew.GetNamespace(), cfg.NodeName, log, cl) if shouldRequeue { - log.Error(err, fmt.Sprintf("[RunWatcherLVMVGController] An error has occured in ReconcileLVMVG. Adds to retry after %d seconds.", cfg.VolumeGroupScanInterval)) + log.Error(err, fmt.Sprintf("[RunLVMVolumeGroupWatcherController] An error has occured in ReconcileLVMVG. Adds to retry after %d seconds.", cfg.VolumeGroupScanInterval)) q.AddAfter(request, cfg.VolumeGroupScanInterval*time.Second) log.Warning(fmt.Sprintf(`Added request, namespace: "%s" name: "%s", to requeue`, request.Namespace, request.Name)) } @@ -133,38 +133,38 @@ func RunWatcherLVMVGController( request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.ObjectNew.GetNamespace(), Name: e.ObjectNew.GetName()}} shouldRequeue, err := ReconcileLVMVG(ctx, metrics, e.ObjectNew.GetName(), e.ObjectNew.GetNamespace(), cfg.NodeName, log, cl) if shouldRequeue { - log.Error(err, fmt.Sprintf("[RunWatcherLVMVGController] An error has occured in ReconcileLVMVG. Adds to retry after %d seconds.", cfg.VolumeGroupScanInterval)) + log.Error(err, fmt.Sprintf("[RunLVMVolumeGroupWatcherController] An error has occured in ReconcileLVMVG. Adds to retry after %d seconds.", cfg.VolumeGroupScanInterval)) q.AddAfter(request, cfg.VolumeGroupScanInterval*time.Second) log.Warning(fmt.Sprintf(`Added request, namespace: "%s" name: "%s", to requeue`, request.Namespace, request.Name)) } } else { - log.Info("[RunWatcherLVMVGController] lvg check dev size") + log.Info("[RunLVMVolumeGroupWatcherController] lvg check dev size") for _, node := range newLVG.Status.Nodes { for _, device := range node.Devices { if device.DevSize.Value() == 0 { - log.Warning(fmt.Sprintf("[RunWatcherLVMVGController] check dev size device.DevSize = %s", device.DevSize.String())) + log.Warning(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] check dev size device.DevSize = %s", device.DevSize.String())) return } - log.Debug(fmt.Sprintf("[RunWatcherLVMVGController] update spec check resize device.PVSize = %s", device.PVSize)) + log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] update spec check resize device.PVSize = %s", device.PVSize)) dPVSizeTmp := resource.MustParse(device.PVSize) if dPVSizeTmp.Value() == 0 { - log.Warning(fmt.Sprintf("[RunWatcherLVMVGController] check dev PV size device.PVSize = %s", device.PVSize)) + log.Warning(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] check dev PV size device.PVSize = %s", device.PVSize)) return } delta, _ := utils.QuantityToBytes(internal.ResizeDelta) - log.Debug(fmt.Sprintf("[RunWatcherLVMVGController] resize flag = %t", device.DevSize.Value()-dPVSizeTmp.Value() > delta)) + log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] resize flag = %t", device.DevSize.Value()-dPVSizeTmp.Value() > delta)) if device.DevSize.Value()-dPVSizeTmp.Value() > delta { - log.Info("[RunWatcherLVMVGController] lvg status device and PV changed") + log.Info("[RunLVMVolumeGroupWatcherController] lvg status device and PV changed") request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.ObjectNew.GetNamespace(), Name: e.ObjectNew.GetName()}} shouldRequeue, err := ReconcileLVMVG(ctx, metrics, e.ObjectNew.GetName(), e.ObjectNew.GetNamespace(), cfg.NodeName, log, cl) if shouldRequeue { - log.Error(err, fmt.Sprintf("[RunWatcherLVMVGController] An error has occured in ReconcileLVMVG. Adds to retry after %d seconds.", cfg.VolumeGroupScanInterval)) + log.Error(err, fmt.Sprintf("[RunLVMVolumeGroupWatcherController] An error has occured in ReconcileLVMVG. Adds to retry after %d seconds.", cfg.VolumeGroupScanInterval)) q.AddAfter(request, cfg.VolumeGroupScanInterval*time.Second) log.Warning(fmt.Sprintf(`Added request, namespace: "%s" name: "%s", to requeue`, request.Namespace, request.Name)) } @@ -180,7 +180,7 @@ func RunWatcherLVMVGController( }) if err != nil { - log.Error(err, "[RunWatcherLVMVGController] error Watch controller RunWatcherLVMVGController") + log.Error(err, "[RunLVMVolumeGroupWatcherController] error Watch controller RunLVMVolumeGroupWatcherController") return nil, err } return c, err @@ -405,12 +405,12 @@ func ReconcileLVMVG( } start := time.Now() command, err := utils.CreateLV(pool, group.Spec.ActualVGNameOnTheNode) - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "lvcreate").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "lvcreate").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "lvcreate").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "lvcreate").Inc() log.Debug(command) if err != nil { log.Error(err, fmt.Sprintf("[ReconcileLVMVG] error CreateLV, thin pool: %s", pool.Name)) - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "lvcreate").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "lvcreate").Inc() if err = updateLVMVolumeGroupHealthStatus(ctx, cl, metrics, group.Name, group.Namespace, err.Error(), NonOperational); err != nil { log.Error(err, fmt.Sprintf("[ReconcileLVMVG] unable to update LVMVolumeGroupStatus, resource name: %s", group.Name)) } @@ -456,11 +456,11 @@ func ReconcileLVMVG( newLVSizeStr := strconv.FormatInt(pool.Size.Value()/1024, 10) start := time.Now() cmd, err := utils.ExtendLV(newLVSizeStr+"K", group.Spec.ActualVGNameOnTheNode, pool.Name) - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "lvextend").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "lvextend").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "lvextend").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "lvextend").Inc() log.Debug(cmd) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "lvextend").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "lvextend").Inc() log.Error(err, fmt.Sprintf("[ReconcileLVMVG] error ExtendLV, pool name: %s", pool.Name)) return true, err } @@ -497,11 +497,11 @@ func ReconcileLVMVG( for _, v := range group.Spec.ThinPools { start := time.Now() command, err := utils.CreateLV(v, group.Spec.ActualVGNameOnTheNode) - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "lvcreate").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "lvcreate").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "lvcreate").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "lvcreate").Inc() log.Debug(command) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "lvcreate").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "lvcreate").Inc() log.Error(err, fmt.Sprintf("[ReconcileLVMVG] error CreateLV, thin pool: %s", v.Name)) if err = updateLVMVolumeGroupHealthStatus(ctx, cl, metrics, group.Name, group.Namespace, err.Error(), NonOperational); err != nil { log.Error(err, fmt.Sprintf("[ReconcileLVMVG] unable to update LVMVolumeGroupStatus, resource name: %s", group.Name)) diff --git a/images/agent/pkg/controller/watcher_lvm_volume_group_constants.go b/images/agent/pkg/controller/lvm_volume_group_watcher_constants.go similarity index 100% rename from images/agent/pkg/controller/watcher_lvm_volume_group_constants.go rename to images/agent/pkg/controller/lvm_volume_group_watcher_constants.go diff --git a/images/agent/pkg/controller/watcher_lvm_volume_group_func.go b/images/agent/pkg/controller/lvm_volume_group_watcher_func.go similarity index 69% rename from images/agent/pkg/controller/watcher_lvm_volume_group_func.go rename to images/agent/pkg/controller/lvm_volume_group_watcher_func.go index 53d1a0d5..bd8b38f1 100644 --- a/images/agent/pkg/controller/watcher_lvm_volume_group_func.go +++ b/images/agent/pkg/controller/lvm_volume_group_watcher_func.go @@ -45,10 +45,10 @@ func getLVMVolumeGroup(ctx context.Context, cl client.Client, metrics monitoring Name: name, Namespace: namespace, }, obj) - metrics.ApiMethodsDuration(watcherLVMVGCtrlName, "get").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.ApiMethodsExecutionCount(watcherLVMVGCtrlName, "get").Inc() + metrics.ApiMethodsDuration(LVMVolumeGroupWatcherCtrlName, "get").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.ApiMethodsExecutionCount(LVMVolumeGroupWatcherCtrlName, "get").Inc() if err != nil { - metrics.ApiMethodsErrors(watcherLVMVGCtrlName, "get").Inc() + metrics.ApiMethodsErrors(LVMVolumeGroupWatcherCtrlName, "get").Inc() return nil, err } return obj, nil @@ -62,10 +62,10 @@ func updateLVMVolumeGroupHealthStatus(ctx context.Context, cl client.Client, met Name: name, Namespace: namespace, }, obj) - metrics.ApiMethodsDuration(watcherLVMVGCtrlName, "get").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.ApiMethodsExecutionCount(watcherLVMVGCtrlName, "get").Inc() + metrics.ApiMethodsDuration(LVMVolumeGroupWatcherCtrlName, "get").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.ApiMethodsExecutionCount(LVMVolumeGroupWatcherCtrlName, "get").Inc() if err != nil { - metrics.ApiMethodsErrors(watcherLVMVGCtrlName, "get").Inc() + metrics.ApiMethodsErrors(LVMVolumeGroupWatcherCtrlName, "get").Inc() return err } @@ -82,10 +82,10 @@ func updateLVMVolumeGroupHealthStatus(ctx context.Context, cl client.Client, met start = time.Now() err = cl.Update(ctx, obj) - metrics.ApiMethodsDuration(watcherLVMVGCtrlName, "update").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.ApiMethodsExecutionCount(watcherLVMVGCtrlName, "update").Inc() + metrics.ApiMethodsDuration(LVMVolumeGroupWatcherCtrlName, "update").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.ApiMethodsExecutionCount(LVMVolumeGroupWatcherCtrlName, "update").Inc() if err != nil { - metrics.ApiMethodsErrors(watcherLVMVGCtrlName, "update").Inc() + metrics.ApiMethodsErrors(LVMVolumeGroupWatcherCtrlName, "update").Inc() return err } return nil @@ -99,10 +99,10 @@ func getBlockDevice(ctx context.Context, cl client.Client, metrics monitoring.Me Name: name, Namespace: namespace, }, obj) - metrics.ApiMethodsDuration(watcherLVMVGCtrlName, "get").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.ApiMethodsExecutionCount(watcherLVMVGCtrlName, "get").Inc() + metrics.ApiMethodsDuration(LVMVolumeGroupWatcherCtrlName, "get").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.ApiMethodsExecutionCount(LVMVolumeGroupWatcherCtrlName, "get").Inc() if err != nil { - metrics.ApiMethodsErrors(watcherLVMVGCtrlName, "get").Inc() + metrics.ApiMethodsErrors(LVMVolumeGroupWatcherCtrlName, "get").Inc() return nil, err } return obj, nil @@ -240,16 +240,16 @@ func CreateEventLVMVolumeGroup(ctx context.Context, cl client.Client, metrics mo }, Action: actions, ReportingInstance: nodeName, - ReportingController: watcherLVMVGCtrlName, + ReportingController: LVMVolumeGroupWatcherCtrlName, Message: "Event Message", } start := time.Now() err := cl.Create(ctx, e) - metrics.ApiMethodsDuration(watcherLVMVGCtrlName, "create").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.ApiMethodsExecutionCount(watcherLVMVGCtrlName, "create").Inc() + metrics.ApiMethodsDuration(LVMVolumeGroupWatcherCtrlName, "create").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.ApiMethodsExecutionCount(LVMVolumeGroupWatcherCtrlName, "create").Inc() if err != nil { - metrics.ApiMethodsErrors(watcherLVMVGCtrlName, "create").Inc() + metrics.ApiMethodsErrors(LVMVolumeGroupWatcherCtrlName, "create").Inc() return err } return nil @@ -259,11 +259,11 @@ func DeleteVG(vgName string, log logger.Logger, metrics monitoring.Metrics) erro // if VG exist start := time.Now() vgs, command, _, err := utils.GetAllVGs() - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "vgs").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "vgs").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "vgs").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "vgs").Inc() log.Debug(command) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "vgs").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "vgs").Inc() log.Error(err, "GetAllVGs "+command) return err } @@ -275,11 +275,11 @@ func DeleteVG(vgName string, log logger.Logger, metrics monitoring.Metrics) erro // if exist LV in VG start = time.Now() lvs, command, _, err := utils.GetAllLVs() - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "lvs").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "lvs").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "lvs").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "lvs").Inc() log.Debug(command) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "lvs").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "lvs").Inc() log.Error(err, "GetAllLVs "+command) return err } @@ -292,22 +292,22 @@ func DeleteVG(vgName string, log logger.Logger, metrics monitoring.Metrics) erro start = time.Now() pvs, command, _, err := utils.GetAllPVs() - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "pvs").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "pvs").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "pvs").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "pvs").Inc() log.Debug(command) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "pvs").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "pvs").Inc() log.Error(err, "RemoveVG "+command) return err } start = time.Now() command, err = utils.RemoveVG(vgName) - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "vgremove").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "vgremove").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "vgremove").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "vgremove").Inc() log.Debug(command) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "vgremove").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "vgremove").Inc() log.Error(err, "RemoveVG "+command) return err } @@ -322,11 +322,11 @@ func DeleteVG(vgName string, log logger.Logger, metrics monitoring.Metrics) erro start = time.Now() command, err = utils.RemovePV(listDeletingPV) - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "pvremove").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "pvremove").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "pvremove").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "pvremove").Inc() log.Debug(command) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "pvremove").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "pvremove").Inc() log.Error(err, "RemovePV "+command) return err } @@ -337,11 +337,11 @@ func DeleteVG(vgName string, log logger.Logger, metrics monitoring.Metrics) erro func ExistVG(vgName string, log logger.Logger, metrics monitoring.Metrics) (bool, error) { start := time.Now() vg, command, _, err := utils.GetAllVGs() - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "vgs").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "vgs").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "vgs").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "vgs").Inc() log.Debug(command) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "vgs").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "vgs").Inc() log.Error(err, " error CreateEventLVMVolumeGroup") return false, err } @@ -394,11 +394,11 @@ func ExtendVGComplex(metrics monitoring.Metrics, extendPVs []string, VGName stri for _, pvPath := range extendPVs { start := time.Now() command, err := utils.CreatePV(pvPath) - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "pvcreate").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "pvcreate").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "pvcreate").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "pvcreate").Inc() l.Debug(command) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "pvcreate").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "pvcreate").Inc() l.Error(err, "CreatePV ") return err } @@ -406,11 +406,11 @@ func ExtendVGComplex(metrics monitoring.Metrics, extendPVs []string, VGName stri start := time.Now() command, err := utils.ExtendVG(VGName, extendPVs) - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "vgextend").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "vgextend").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "vgextend").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "vgextend").Inc() l.Debug(command) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "vgextend").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "vgextend").Inc() l.Error(err, "ExtendVG ") return err } @@ -437,11 +437,11 @@ func CreateVGComplex(ctx context.Context, cl client.Client, metrics monitoring.M p := path start := time.Now() command, err := utils.CreatePV(p) - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "pvcreate").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "pvcreate").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "pvcreate").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "pvcreate").Inc() l.Debug(command) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "pvcreate").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "pvcreate").Inc() l.Error(err, "CreatePV "+p) return err } @@ -450,11 +450,11 @@ func CreateVGComplex(ctx context.Context, cl client.Client, metrics monitoring.M if group.Spec.Type == Local { start := time.Now() cmd, err := utils.CreateVGLocal(group.Spec.ActualVGNameOnTheNode, group.Name, paths) - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "vgcreate").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "vgcreate").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "vgcreate").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "vgcreate").Inc() l.Debug(cmd) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "vgcreate").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "vgcreate").Inc() l.Error(err, "error CreateVGLocal") return err } @@ -463,11 +463,11 @@ func CreateVGComplex(ctx context.Context, cl client.Client, metrics monitoring.M if group.Spec.Type == Shared { start := time.Now() cmd, err := utils.CreateVGShared(group.Spec.ActualVGNameOnTheNode, group.Name, paths) - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "vgcreate").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "vgcreate").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "vgcreate").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "vgcreate").Inc() l.Debug(cmd) if err != nil { - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "vgcreate").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "vgcreate").Inc() l.Error(err, "error CreateVGShared") return err } @@ -480,12 +480,12 @@ func UpdateLVMVolumeGroupTagsName(log logger.Logger, metrics monitoring.Metrics, start := time.Now() vgs, cmd, _, err := utils.GetAllVGs() - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "vgs").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "vgs").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "vgs").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "vgs").Inc() log.Debug(fmt.Sprintf("[ReconcileLVMVG] exec cmd: %s", cmd)) if err != nil { log.Error(err, fmt.Sprintf("[ReconcileLVMVG] unable to get VG by resource, name: %s", lvg.Name)) - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "vgs").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "vgs").Inc() return false, err } @@ -500,23 +500,23 @@ func UpdateLVMVolumeGroupTagsName(log logger.Logger, metrics monitoring.Metrics, if found && lvg.Name != tagName { start = time.Now() cmd, err = utils.VGChangeDelTag(vg.VGName, fmt.Sprintf("%s=%s", tag, tagName)) - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "vgchange").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "vgchange").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "vgchange").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "vgchange").Inc() log.Debug(fmt.Sprintf("[UpdateLVMVolumeGroupTagsName] exec cmd: %s", cmd)) if err != nil { log.Error(err, fmt.Sprintf("[UpdateLVMVolumeGroupTagsName] unable to delete tag: %s=%s, vg: %s", tag, tagName, vg.VGName)) - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "vgchange").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "vgchange").Inc() return false, err } start = time.Now() cmd, err = utils.VGChangeAddTag(vg.VGName, fmt.Sprintf("%s=%s", tag, lvg.Name)) - metrics.UtilsCommandsDuration(watcherLVMVGCtrlName, "vgchange").Observe(metrics.GetEstimatedTimeInSeconds(start)) - metrics.UtilsCommandsExecutionCount(watcherLVMVGCtrlName, "vgchange").Inc() + metrics.UtilsCommandsDuration(LVMVolumeGroupWatcherCtrlName, "vgchange").Observe(metrics.GetEstimatedTimeInSeconds(start)) + metrics.UtilsCommandsExecutionCount(LVMVolumeGroupWatcherCtrlName, "vgchange").Inc() log.Debug(fmt.Sprintf("[UpdateLVMVolumeGroupTagsName] exec cmd: %s", cmd)) if err != nil { log.Error(err, fmt.Sprintf("[UpdateLVMVolumeGroupTagsName] unable to add tag: %s=%s, vg: %s", tag, lvg.Name, vg.VGName)) - metrics.UtilsCommandsErrorsCount(watcherLVMVGCtrlName, "vgchange").Inc() + metrics.UtilsCommandsErrorsCount(LVMVolumeGroupWatcherCtrlName, "vgchange").Inc() return false, err } diff --git a/images/agent/pkg/controller/watcher_lvm_volume_group_test.go b/images/agent/pkg/controller/lvm_volume_group_watcher_test.go similarity index 99% rename from images/agent/pkg/controller/watcher_lvm_volume_group_test.go rename to images/agent/pkg/controller/lvm_volume_group_watcher_test.go index 5ee7fa81..661d86a4 100644 --- a/images/agent/pkg/controller/watcher_lvm_volume_group_test.go +++ b/images/agent/pkg/controller/lvm_volume_group_watcher_test.go @@ -10,7 +10,7 @@ import ( "testing" ) -func TestWatcherLVMVolumeGroupCtrl(t *testing.T) { +func TestLVMVolumeGroupWatcherCtrl(t *testing.T) { cl := NewFakeClient() ctx := context.Background() metrics := monitoring.GetMetrics("") @@ -872,7 +872,7 @@ func TestWatcherLVMVolumeGroupCtrl(t *testing.T) { assert.Equal(t, v1.EventTypeNormal, event.Type) assert.Equal(t, EventActionDeleting, event.Action) assert.Equal(t, nodeName, event.ReportingInstance) - assert.Equal(t, watcherLVMVGCtrlName, event.ReportingController) + assert.Equal(t, LVMVolumeGroupWatcherCtrlName, event.ReportingController) assert.Equal(t, "Event Message", event.Message) err = cl.Delete(ctx, &event)