From d442b26b78faea269c5b49f20f825cc7f213c938 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Fri, 16 Aug 2024 16:20:42 +0200 Subject: [PATCH] make golangci-lint version 1.60.1 happy Signed-off-by: Martin Schuppert --- api/v1beta1/common_openstackcontrolplane.go | 4 ++-- api/v1beta1/common_openstacknet.go | 10 +++++----- api/v1beta1/openstackbaremetalset_webhook.go | 4 ++-- api/v1beta1/openstackclient_webhook.go | 4 ++-- api/v1beta1/openstackdeploy_webhook.go | 8 ++++---- api/v1beta2/common_openstackcontrolplane.go | 4 ++-- api/v1beta2/common_webhook.go | 16 ++++++++-------- api/v1beta2/openstackcontrolplane_webhook.go | 4 ++-- api/v1beta2/openstackvmset_webhook.go | 4 ++-- controllers/openstackcontrolplane_controller.go | 2 +- controllers/openstacknetattachment_controller.go | 2 +- controllers/openstacknetconfig_controller.go | 8 ++++---- controllers/openstackvmset_controller.go | 6 +++--- pkg/common/secret.go | 2 +- 14 files changed, 39 insertions(+), 39 deletions(-) diff --git a/api/v1beta1/common_openstackcontrolplane.go b/api/v1beta1/common_openstackcontrolplane.go index 0f92f3a3..b27ba7f9 100644 --- a/api/v1beta1/common_openstackcontrolplane.go +++ b/api/v1beta1/common_openstackcontrolplane.go @@ -70,10 +70,10 @@ func CreateVIPNetworkList( ) if err != nil { if k8s_errors.IsNotFound(err) { - return uniqNetworksList, fmt.Errorf(fmt.Sprintf("OpenStackNet with NameLower %s not found!", netNameLower)) + return uniqNetworksList, fmt.Errorf("OpenStackNet with NameLower %s not found", netNameLower) } // Error reading the object - requeue the request. - return uniqNetworksList, fmt.Errorf(fmt.Sprintf("Error getting OSNet with labelSelector %v", labelSelector)) + return uniqNetworksList, fmt.Errorf("Error getting OSNet with labelSelector %v", labelSelector) } if _, value := networkList[netNameLower]; !value && network.Spec.VIP { diff --git a/api/v1beta1/common_openstacknet.go b/api/v1beta1/common_openstacknet.go index 3c2d681f..94fb68df 100644 --- a/api/v1beta1/common_openstacknet.go +++ b/api/v1beta1/common_openstacknet.go @@ -100,9 +100,9 @@ func AddOSNetConfigRefLabel( } osnet, err := GetOpenStackNetWithLabel(c, namespace, labelSelector) if err != nil && k8s_errors.IsNotFound(err) { - return labels, fmt.Errorf(fmt.Sprintf("OpenStackNet %s not found reconcile again in 10 seconds", subnetName)) + return labels, fmt.Errorf("OpenStackNet %s not found reconcile again in 10 seconds", subnetName) } else if err != nil { - return labels, fmt.Errorf(fmt.Sprintf("Failed to get OpenStackNet %s ", subnetName)) + return labels, fmt.Errorf("Failed to get OpenStackNet %s ", subnetName) } // @@ -215,7 +215,7 @@ func GetOsNetCfg( if err != nil { if k8s_errors.IsNotFound(err) { - return nil, fmt.Errorf(fmt.Sprintf("%s with name %s not found", osNetCfg.DeepCopy().GroupVersionKind().Kind, osNetCfg.Name)) + return nil, fmt.Errorf("%s with name %s not found", osNetCfg.DeepCopy().GroupVersionKind().Kind, osNetCfg.Name) } return nil, err } @@ -234,9 +234,9 @@ func ValidateNetworks(namespace string, networks []string) error { } osnet, err := GetOpenStackNetWithLabel(webhookClient, namespace, labelSelector) if err != nil && k8s_errors.IsNotFound(err) { - return fmt.Errorf(fmt.Sprintf("%s %s not found, validate the object network list!", osnet.GetObjectKind().GroupVersionKind().Kind, subnetName)) + return fmt.Errorf("%s %s not found, validate the object network list", osnet.GetObjectKind().GroupVersionKind().Kind, subnetName) } else if err != nil { - return fmt.Errorf(fmt.Sprintf("Failed to get %s %s", osnet.Kind, subnetName)) + return fmt.Errorf("Failed to get %s %s", osnet.Kind, subnetName) } } diff --git a/api/v1beta1/openstackbaremetalset_webhook.go b/api/v1beta1/openstackbaremetalset_webhook.go index 3013993e..194c21a3 100644 --- a/api/v1beta1/openstackbaremetalset_webhook.go +++ b/api/v1beta1/openstackbaremetalset_webhook.go @@ -65,10 +65,10 @@ func (r *OpenStackBaremetalSet) ValidateCreate() error { // _, err := GetOsNetCfg(webhookClient, r.GetNamespace(), r.GetLabels()[shared.OpenStackNetConfigReconcileLabel]) if err != nil { - return fmt.Errorf(fmt.Sprintf("error getting OpenStackNetConfig %s - %s: %s", + return fmt.Errorf("error getting OpenStackNetConfig %s - %s: %w", r.GetLabels()[shared.OpenStackNetConfigReconcileLabel], r.Name, - err)) + err) } // diff --git a/api/v1beta1/openstackclient_webhook.go b/api/v1beta1/openstackclient_webhook.go index 19a342df..52f9286c 100644 --- a/api/v1beta1/openstackclient_webhook.go +++ b/api/v1beta1/openstackclient_webhook.go @@ -108,10 +108,10 @@ func (r *OpenStackClient) ValidateCreate() error { // _, err := GetOsNetCfg(webhookClient, r.GetNamespace(), r.GetLabels()[shared.OpenStackNetConfigReconcileLabel]) if err != nil { - return fmt.Errorf(fmt.Sprintf("error getting OpenStackNetConfig %s - %s: %s", + return fmt.Errorf("error getting OpenStackNetConfig %s - %s: %w", r.GetLabels()[shared.OpenStackNetConfigReconcileLabel], r.Name, - err)) + err) } // diff --git a/api/v1beta1/openstackdeploy_webhook.go b/api/v1beta1/openstackdeploy_webhook.go index 0b746b54..614bfe2f 100644 --- a/api/v1beta1/openstackdeploy_webhook.go +++ b/api/v1beta1/openstackdeploy_webhook.go @@ -144,7 +144,7 @@ func (r *OpenStackDeploy) validateNNCP() error { nncpReadyCount := 0 for _, nncp := range nncpList.Items { - if nncp.Status.Conditions != nil && len(nncp.Status.Conditions) > 0 { + if len(nncp.Status.Conditions) > 0 { condition := nmstate.GetCurrentCondition(nncp.Status.Conditions) if condition != nil { if condition.Type == nmstateshared.NodeNetworkConfigurationPolicyConditionAvailable && @@ -171,7 +171,7 @@ func (r *OpenStackDeploy) validateNNCP() error { var nnceError string var nnce nmstatev1.NodeNetworkConfigurationEnactment for _, nnce = range nnceList.Items { - if nnce.Status.Conditions != nil && len(nnce.Status.Conditions) > 0 { + if len(nnce.Status.Conditions) > 0 { condition := nmstate.GetCurrentCondition(nnce.Status.Conditions) // if the first nnce has condition.Reason == nmstateshared.NodeNetworkConfigurationEnactmentConditionFailedToConfigure @@ -199,11 +199,11 @@ func (r *OpenStackDeploy) validateNNCP() error { } else { info := "It's recommended to resolve the failures before proceeding with the deployment. If this validation should be skipped add spec.SkipNNCPValidation: true" openstackdeploylog.Error( - fmt.Errorf(msg), + fmt.Errorf("%s", msg), info, "name", r.Name) - return fmt.Errorf(fmt.Sprintf("%s, %s", msg, info)) + return fmt.Errorf("%s, %s", msg, info) } } } diff --git a/api/v1beta2/common_openstackcontrolplane.go b/api/v1beta2/common_openstackcontrolplane.go index fe7665da..c2b0c244 100644 --- a/api/v1beta2/common_openstackcontrolplane.go +++ b/api/v1beta2/common_openstackcontrolplane.go @@ -71,10 +71,10 @@ func CreateVIPNetworkList( ) if err != nil { if k8s_errors.IsNotFound(err) { - return uniqNetworksList, fmt.Errorf(fmt.Sprintf("OpenStackNet with NameLower %s not found!", netNameLower)) + return uniqNetworksList, fmt.Errorf("OpenStackNet with NameLower %s not found", netNameLower) } // Error reading the object - requeue the request. - return uniqNetworksList, fmt.Errorf(fmt.Sprintf("Error getting OSNet with labelSelector %v", labelSelector)) + return uniqNetworksList, fmt.Errorf("Error getting OSNet with labelSelector %v", labelSelector) } if _, value := networkList[netNameLower]; !value && network.Spec.VIP { diff --git a/api/v1beta2/common_webhook.go b/api/v1beta2/common_webhook.go index 0f4e37e7..bb4c0dbc 100644 --- a/api/v1beta2/common_webhook.go +++ b/api/v1beta2/common_webhook.go @@ -125,7 +125,7 @@ func validateAdditionalDisks(newDisks []OpenStackVMSetDisk, currentDisks []OpenS // validate Disk Name is not 'rootdisk' as this is reserved for the boot disk // if disk.Name == "rootdisk" { - return fmt.Errorf(fmt.Sprintf("disk names must not be 'rootdisk' - %v", disk)) + return fmt.Errorf("disk names must not be 'rootdisk' - %v", disk) } // @@ -133,7 +133,7 @@ func validateAdditionalDisks(newDisks []OpenStackVMSetDisk, currentDisks []OpenS // var validDiskName = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`) if !validDiskName.MatchString(disk.Name) { - return fmt.Errorf(fmt.Sprintf("disk names must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character - %s", disk.Name)) + return fmt.Errorf("disk names must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character - %s", disk.Name) } // @@ -142,7 +142,7 @@ func validateAdditionalDisks(newDisks []OpenStackVMSetDisk, currentDisks []OpenS if _, ok := disks[disk.Name]; !ok { disks[disk.Name] = disk } else { - return fmt.Errorf(fmt.Sprintf("disk names must be uniq within a VM role - %v : %v", disks[disk.Name], disk)) + return fmt.Errorf("disk names must be uniq within a VM role - %v : %v", disks[disk.Name], disk) } // @@ -189,7 +189,7 @@ func diskSizeChanged(diskName string, diskSize uint32, curDiskSize uint32) error // validate DiskSize don't change // if diskSize != curDiskSize { - return fmt.Errorf(fmt.Sprintf("disk size must not change %s - new %v / current %v", diskName, diskSize, curDiskSize)) + return fmt.Errorf("disk size must not change %s - new %v / current %v", diskName, diskSize, curDiskSize) } return nil @@ -201,7 +201,7 @@ func storageAccessModeChanged(diskName string, accessMode string, curAccessMode // validate StorageAccessMode don't change // if accessMode != curAccessMode { - return fmt.Errorf(fmt.Sprintf("StorageAccessMode must not change %s - new %v / current %v", diskName, accessMode, curAccessMode)) + return fmt.Errorf("StorageAccessMode must not change %s - new %v / current %v", diskName, accessMode, curAccessMode) } return nil @@ -213,7 +213,7 @@ func storageClassChanged(diskName string, storageClass string, curStorageClass s // validate StorageClass don't change // if storageClass != curStorageClass { - return fmt.Errorf(fmt.Sprintf("StorageClass must not change %s - new %v / current %v", diskName, storageClass, curStorageClass)) + return fmt.Errorf("StorageClass must not change %s - new %v / current %v", diskName, storageClass, curStorageClass) } return nil @@ -225,7 +225,7 @@ func storageVolumeModeChanged(diskName string, volumeMode string, curVolumeMode // validate StorageVolumeMode don't change // if volumeMode != curVolumeMode { - return fmt.Errorf(fmt.Sprintf("StorageVolumeMode must not change %s - new %v / current %v", diskName, volumeMode, curVolumeMode)) + return fmt.Errorf("StorageVolumeMode must not change %s - new %v / current %v", diskName, volumeMode, curVolumeMode) } return nil @@ -237,7 +237,7 @@ func baseImageVolumeNameChanged(diskName string, volumeName string, curVolumeNam // validate BaseImageVolumeName don't change // if volumeName != curVolumeName { - return fmt.Errorf(fmt.Sprintf("BaseImageVolumeName must not change %s - new %v / current %v", diskName, volumeName, curVolumeName)) + return fmt.Errorf("BaseImageVolumeName must not change %s - new %v / current %v", diskName, volumeName, curVolumeName) } return nil diff --git a/api/v1beta2/openstackcontrolplane_webhook.go b/api/v1beta2/openstackcontrolplane_webhook.go index c3962878..44eb3369 100644 --- a/api/v1beta2/openstackcontrolplane_webhook.go +++ b/api/v1beta2/openstackcontrolplane_webhook.go @@ -232,10 +232,10 @@ func (r *OpenStackControlPlane) ValidateCreate() error { // _, err := ospdirectorv1beta1.GetOsNetCfg(webhookClient, r.GetNamespace(), r.GetLabels()[shared.OpenStackNetConfigReconcileLabel]) if err != nil { - return fmt.Errorf(fmt.Sprintf("error getting OpenStackNetConfig %s - %s: %s", + return fmt.Errorf("error getting OpenStackNetConfig %s - %s: %w", r.GetLabels()[shared.OpenStackNetConfigReconcileLabel], r.Name, - err)) + err) } // diff --git a/api/v1beta2/openstackvmset_webhook.go b/api/v1beta2/openstackvmset_webhook.go index 191b0d20..74d671b3 100644 --- a/api/v1beta2/openstackvmset_webhook.go +++ b/api/v1beta2/openstackvmset_webhook.go @@ -132,10 +132,10 @@ func (r *OpenStackVMSet) ValidateCreate() error { // _, err := ospdirectorv1beta1.GetOsNetCfg(webhookClient, r.GetNamespace(), r.GetLabels()[shared.OpenStackNetConfigReconcileLabel]) if err != nil { - return fmt.Errorf(fmt.Sprintf("error getting OpenStackNetConfig %s - %s: %s", + return fmt.Errorf("error getting OpenStackNetConfig %s - %s: %w", r.GetLabels()[shared.OpenStackNetConfigReconcileLabel], r.Name, - err)) + err) } // diff --git a/controllers/openstackcontrolplane_controller.go b/controllers/openstackcontrolplane_controller.go index c2500fc3..3c6d1708 100644 --- a/controllers/openstackcontrolplane_controller.go +++ b/controllers/openstackcontrolplane_controller.go @@ -1088,7 +1088,7 @@ func (r *OpenStackControlPlaneReconciler) ensureStorageVersionMigration( ) cond.Reason = shared.ConditionReason(currentCond.Reason) cond.Type = shared.ConditionType(currentCond.Type) - err := common.WrapErrorForObject(cond.Message, instance, fmt.Errorf(cond.Message)) + err := common.WrapErrorForObject(cond.Message, instance, fmt.Errorf("%s", cond.Message)) return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, err } diff --git a/controllers/openstacknetattachment_controller.go b/controllers/openstacknetattachment_controller.go index e0c69bbe..793c0f9d 100644 --- a/controllers/openstacknetattachment_controller.go +++ b/controllers/openstacknetattachment_controller.go @@ -399,7 +399,7 @@ func (r *OpenStackNetAttachmentReconciler) getNodeNetworkConfigurationPolicyStat // // sync latest status of the nncp object to the osnetattach // - if networkConfigurationPolicy.Status.Conditions != nil && len(networkConfigurationPolicy.Status.Conditions) > 0 { + if len(networkConfigurationPolicy.Status.Conditions) > 0 { condition := nmstate.GetCurrentCondition(networkConfigurationPolicy.Status.Conditions) if condition != nil { cond.Message = fmt.Sprintf("%s %s: %s", networkConfigurationPolicy.Kind, networkConfigurationPolicy.Name, condition.Message) diff --git a/controllers/openstacknetconfig_controller.go b/controllers/openstacknetconfig_controller.go index 02cffb05..1c500288 100644 --- a/controllers/openstacknetconfig_controller.go +++ b/controllers/openstacknetconfig_controller.go @@ -516,7 +516,7 @@ func (r *OpenStackNetConfigReconciler) getNetAttachmentStatus( // // sync latest status of the osnetattach object to the osnetconfig // - if netAttachment.Status.Conditions != nil && len(netAttachment.Status.Conditions) > 0 { + if len(netAttachment.Status.Conditions) > 0 { condition := netAttachment.Status.Conditions.GetCurrentCondition() if condition != nil { @@ -531,7 +531,7 @@ func (r *OpenStackNetConfigReconciler) getNetAttachmentStatus( cond.Message = fmt.Sprintf("OpenStackNetAttachment error: %s", condition.Message) cond.Type = shared.NetConfigError - return fmt.Errorf(cond.Message) + return fmt.Errorf("%s", cond.Message) } } } @@ -708,7 +708,7 @@ func (r *OpenStackNetConfigReconciler) getNetStatus( // // sync latest status of the osnet object to the osnetconfig // - if osNet.Status.Conditions != nil && len(osNet.Status.Conditions) > 0 { + if len(osNet.Status.Conditions) > 0 { condition := osNet.Status.Conditions.GetCurrentCondition() if condition != nil { @@ -722,7 +722,7 @@ func (r *OpenStackNetConfigReconciler) getNetStatus( cond.Type = shared.NetConfigError common.LogForObject(r, cond.Message, instance) - return ctrl.Result{}, fmt.Errorf(cond.Message) + return ctrl.Result{}, fmt.Errorf("%s", cond.Message) } } } diff --git a/controllers/openstackvmset_controller.go b/controllers/openstackvmset_controller.go index 4eeac144..4298e2f9 100644 --- a/controllers/openstackvmset_controller.go +++ b/controllers/openstackvmset_controller.go @@ -131,10 +131,10 @@ func (r *OpenStackVMSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque // if instance.Spec.RootDisk.DiskSize == 0 { return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, - fmt.Errorf(fmt.Sprintf("waiting for runtime object %s %s to be migrated to new API version", + fmt.Errorf("waiting for runtime object %s %s to be migrated to new API version", instance.Kind, instance.Name, - )) + ) } // @@ -975,7 +975,7 @@ func (r *OpenStackVMSetReconciler) vmCreateInstance( cond.Reason = shared.CommonCondReasonOSNetError cond.Type = shared.CommonCondTypeError - return fmt.Errorf(cond.Message) + return fmt.Errorf("%s", cond.Message) } vm.Spec.Template.Spec.Domain.Devices.Interfaces = vmset.MergeVMInterfaces( diff --git a/pkg/common/secret.go b/pkg/common/secret.go index 1aaf63ec..1cb9b50b 100644 --- a/pkg/common/secret.go +++ b/pkg/common/secret.go @@ -405,7 +405,7 @@ func GetDataFromSecret( cond.Reason = conditionDetails.ConditionNotFoundReason cond.Type = conditionDetails.ConditionErrorType - return data, ctrl.Result{}, fmt.Errorf(cond.Message) + return data, ctrl.Result{}, fmt.Errorf("%s", cond.Message) } data = strings.TrimSuffix(string(val), "\n") }