From c16d1fd1f99f94f7ad6cf5b66e030d5f3ec59208 Mon Sep 17 00:00:00 2001 From: Viktor Kramarenko Date: Mon, 5 Aug 2024 12:35:45 +0300 Subject: [PATCH] [controller] Code refactor by linter suggestions Signed-off-by: Viktor Kramarenko --- api/v1alpha1/register.go | 8 ++------ api/v1alpha1/zz_generated.deepcopy.go | 3 --- images/agent/src/pkg/controller/block_device.go | 14 ++------------ 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/api/v1alpha1/register.go b/api/v1alpha1/register.go index d7748203..1d94779a 100644 --- a/api/v1alpha1/register.go +++ b/api/v1alpha1/register.go @@ -23,12 +23,8 @@ import ( ) const ( - BlockDeviceKind = "BlockDevice" - LVMVolumeGroupKind = "LvmVolumeGroup" - LVMLogicalVolumeKind = "LVMLogicalVolume" - APIGroup = "storage.deckhouse.io" - APIVersion = "v1alpha1" - TypeMediaAPIVersion = APIGroup + "/" + APIVersion + APIGroup = "storage.deckhouse.io" + APIVersion = "v1alpha1" ) // SchemeGroupVersion is group version used to register these objects diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index cf24bd03..270e883e 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -23,7 +23,6 @@ func (in *BlockDevice) DeepCopyInto(out *BlockDevice) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EmptyBlockDevice. @@ -81,7 +80,6 @@ func (in *LvmVolumeGroup) DeepCopyInto(out *LvmVolumeGroup) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EmptyBlockDevice. @@ -139,7 +137,6 @@ 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. diff --git a/images/agent/src/pkg/controller/block_device.go b/images/agent/src/pkg/controller/block_device.go index 62356d0e..022ead02 100644 --- a/images/agent/src/pkg/controller/block_device.go +++ b/images/agent/src/pkg/controller/block_device.go @@ -190,7 +190,7 @@ func RemoveDeprecatedAPIDevices( for name, device := range apiBlockDevices { if shouldDeleteBlockDevice(device, actualCandidates, nodeName) { - err := DeleteAPIBlockDevice(ctx, cl, metrics, name) + err := DeleteAPIBlockDevice(ctx, cl, metrics, &device) if err != nil { log.Error(err, fmt.Sprintf("[RunBlockDeviceController] unable to delete APIBlockDevice, name: %s", name)) continue @@ -564,17 +564,7 @@ func CreateAPIBlockDevice(ctx context.Context, kc kclient.Client, metrics monito return device, nil } -func DeleteAPIBlockDevice(ctx context.Context, kc kclient.Client, metrics monitoring.Metrics, deviceName string) error { - device := &v1alpha1.BlockDevice{ - ObjectMeta: metav1.ObjectMeta{ - Name: deviceName, - }, - TypeMeta: metav1.TypeMeta{ - Kind: v1alpha1.BlockDeviceKind, - APIVersion: v1alpha1.TypeMediaAPIVersion, - }, - } - +func DeleteAPIBlockDevice(ctx context.Context, kc kclient.Client, metrics monitoring.Metrics, device *v1alpha1.BlockDevice) error { start := time.Now() err := kc.Delete(ctx, device) metrics.ApiMethodsDuration(BlockDeviceCtrlName, "delete").Observe(metrics.GetEstimatedTimeInSeconds(start))