From ebd5399e14f13fa92e20effc70114813efb8c331 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sun, 27 Apr 2025 21:07:01 -0400 Subject: [PATCH] chore(code): fix code problems reported by Qodana (#1934) Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- proxmox/nodes/vms/custom_storage_device.go | 4 +-- proxmox/nodes/vms/custom_virtiofs_share.go | 2 +- proxmoxtf/resource/vm/vm.go | 39 +++++++++++----------- proxmoxtf/resource/vm/vm_test.go | 12 +++---- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/proxmox/nodes/vms/custom_storage_device.go b/proxmox/nodes/vms/custom_storage_device.go index 0aab1f9a..2504a845 100644 --- a/proxmox/nodes/vms/custom_storage_device.go +++ b/proxmox/nodes/vms/custom_storage_device.go @@ -382,9 +382,7 @@ func (d *CustomStorageDevice) UnmarshalJSON(b []byte) error { // // It will return true if any attribute of the current CustomStorageDevice was changed. func (d *CustomStorageDevice) MergeWith(m CustomStorageDevice) bool { - updated := false - - updated = ptr.UpdateIfChanged(&d.AIO, m.AIO) || updated + updated := ptr.UpdateIfChanged(&d.AIO, m.AIO) updated = ptr.UpdateIfChanged(&d.Backup, m.Backup) || updated updated = ptr.UpdateIfChanged(&d.BurstableReadSpeedMbps, m.BurstableReadSpeedMbps) || updated updated = ptr.UpdateIfChanged(&d.BurstableWriteSpeedMbps, m.BurstableWriteSpeedMbps) || updated diff --git a/proxmox/nodes/vms/custom_virtiofs_share.go b/proxmox/nodes/vms/custom_virtiofs_share.go index 940661ba..c22ff3e1 100644 --- a/proxmox/nodes/vms/custom_virtiofs_share.go +++ b/proxmox/nodes/vms/custom_virtiofs_share.go @@ -73,7 +73,7 @@ func (r *CustomVirtiofsShare) EncodeValues(key string, v *url.Values) error { } // EncodeValues converts a CustomVirtiofsShares dict to multiple URL values. -func (r CustomVirtiofsShares) EncodeValues(key string, v *url.Values) error { +func (r CustomVirtiofsShares) EncodeValues(_ string, v *url.Values) error { for s, d := range r { if err := d.EncodeValues(s, v); err != nil { return fmt.Errorf("failed to encode virtiofs share %s: %w", s, err) diff --git a/proxmoxtf/resource/vm/vm.go b/proxmoxtf/resource/vm/vm.go index 3e4a140e..aae8eb0f 100644 --- a/proxmoxtf/resource/vm/vm.go +++ b/proxmoxtf/resource/vm/vm.go @@ -85,7 +85,6 @@ const ( dvInitializationIPConfigIPv6Address = "" dvInitializationIPConfigIPv6Gateway = "" dvInitializationUserAccountPassword = "" - dvInitializationType = "" dvKeyboardLayout = "en-us" dvKVMArguments = "" dvMachineType = "" @@ -290,9 +289,9 @@ const ( mkVirtiofs = "virtiofs" mkVirtiofsMapping = "mapping" mkVirtiofsCache = "cache" - mkVirtiofsDirectIo = "direct_io" - mkVirtiofsExposeAcl = "expose_acl" - mkVirtiofsExposeXattr = "expose_xattr" + mkVirtiofsDirectIO = "direct_io" + mkVirtiofsExposeACL = "expose_acl" + mkVirtiofsExposeXAttr = "expose_xattr" mkWatchdog = "watchdog" // a workaround for the lack of proper support of default and undefined values in SDK. mkWatchdogEnabled = "enabled" @@ -1495,19 +1494,19 @@ func VM() *schema.Resource { Default: dvVirtiofsCache, ValidateDiagFunc: VirtiofsCacheValidator(), }, - mkVirtiofsDirectIo: { + mkVirtiofsDirectIO: { Type: schema.TypeBool, Description: "Whether to allow direct io", Optional: true, Default: dvVirtiofsDirectIo, }, - mkVirtiofsExposeAcl: { + mkVirtiofsExposeACL: { Type: schema.TypeBool, Description: "Enable POSIX ACLs, implies xattr support", Optional: true, Default: dvVirtiofsExposeAcl, }, - mkVirtiofsExposeXattr: { + mkVirtiofsExposeXAttr: { Type: schema.TypeBool, Description: "Enable support for extended attributes", Optional: true, @@ -3411,15 +3410,15 @@ func vmGetVirtiofsShares(d *schema.ResourceData) vms.CustomVirtiofsShares { mapping, _ := block[mkVirtiofsMapping].(string) cache, _ := block[mkVirtiofsCache].(string) - direct_io := types.CustomBool(block[mkVirtiofsDirectIo].(bool)) - expose_acl := types.CustomBool(block[mkVirtiofsExposeAcl].(bool)) - expose_xattr := types.CustomBool(block[mkVirtiofsExposeXattr].(bool)) + directIO := types.CustomBool(block[mkVirtiofsDirectIO].(bool)) + exposeACL := types.CustomBool(block[mkVirtiofsExposeACL].(bool)) + exposeXAttr := types.CustomBool(block[mkVirtiofsExposeXAttr].(bool)) share := vms.CustomVirtiofsShare{ DirId: mapping, - DirectIo: &direct_io, - ExposeAcl: &expose_acl, - ExposeXattr: &expose_xattr, + DirectIo: &directIO, + ExposeAcl: &exposeACL, + ExposeXattr: &exposeXAttr, } if cache != "" { @@ -4064,25 +4063,25 @@ func vmReadCustom( } if pp.DirectIo != nil { - share[mkVirtiofsDirectIo] = *pp.DirectIo + share[mkVirtiofsDirectIO] = *pp.DirectIo } else { - share[mkVirtiofsDirectIo] = dvVirtiofsDirectIo + share[mkVirtiofsDirectIO] = dvVirtiofsDirectIo } if pp.ExposeAcl != nil { - share[mkVirtiofsExposeAcl] = *pp.ExposeAcl + share[mkVirtiofsExposeACL] = *pp.ExposeAcl } else { - share[mkVirtiofsExposeAcl] = dvVirtiofsExposeAcl + share[mkVirtiofsExposeACL] = dvVirtiofsExposeAcl } switch { case pp.ExposeXattr != nil: - share[mkVirtiofsExposeXattr] = *pp.ExposeXattr + share[mkVirtiofsExposeXAttr] = *pp.ExposeXattr case pp.ExposeAcl != nil && bool(*pp.ExposeAcl): // expose-xattr implies expose-acl - share[mkVirtiofsExposeXattr] = true + share[mkVirtiofsExposeXAttr] = true default: - share[mkVirtiofsExposeXattr] = dvVirtiofsExposeXattr + share[mkVirtiofsExposeXAttr] = dvVirtiofsExposeXattr } virtiofsMap[pi] = share diff --git a/proxmoxtf/resource/vm/vm_test.go b/proxmoxtf/resource/vm/vm_test.go index c072ae70..277f526a 100644 --- a/proxmoxtf/resource/vm/vm_test.go +++ b/proxmoxtf/resource/vm/vm_test.go @@ -388,17 +388,17 @@ func TestVMSchema(t *testing.T) { test.AssertOptionalArguments(t, virtiofsSchema, []string{ mkVirtiofsCache, - mkVirtiofsDirectIo, - mkVirtiofsExposeAcl, - mkVirtiofsExposeXattr, + mkVirtiofsDirectIO, + mkVirtiofsExposeACL, + mkVirtiofsExposeXAttr, }) test.AssertValueTypes(t, virtiofsSchema, map[string]schema.ValueType{ mkVirtiofsMapping: schema.TypeString, mkVirtiofsCache: schema.TypeString, - mkVirtiofsDirectIo: schema.TypeBool, - mkVirtiofsExposeAcl: schema.TypeBool, - mkVirtiofsExposeXattr: schema.TypeBool, + mkVirtiofsDirectIO: schema.TypeBool, + mkVirtiofsExposeACL: schema.TypeBool, + mkVirtiofsExposeXAttr: schema.TypeBool, }) vgaSchema := test.AssertNestedSchemaExistence(t, s, mkVGA)