Skip to content

Commit

Permalink
KUBESAW-250: Updating GolangCiLint to v1.63.1 (#1116)
Browse files Browse the repository at this point in the history
* Updating GolangCiLint to v1.63.1

Signed-off-by: Feny Mehta <[email protected]>

* Fixing the Linter errors

Signed-off-by: Feny Mehta <[email protected]>

* comments for gosec

Signed-off-by: Feny Mehta <[email protected]>

* changing the comments

Signed-off-by: Feny Mehta <[email protected]>

* Update controllers/spaceprovisionerconfig/spaceprovisionerconfig_controller.go

Co-authored-by: Matous Jobanek <[email protected]>

* Update pkg/capacity/manager.go

Co-authored-by: Matous Jobanek <[email protected]>

* Update pkg/capacity/manager.go

Co-authored-by: Matous Jobanek <[email protected]>

* Update controllers/spaceprovisionerconfig/spaceprovisionerconfig_controller.go

Co-authored-by: Matous Jobanek <[email protected]>

* updating comments

Signed-off-by: Feny Mehta <[email protected]>

* rc on comments

Signed-off-by: Feny Mehta <[email protected]>

---------

Signed-off-by: Feny Mehta <[email protected]>
Co-authored-by: Matous Jobanek <[email protected]>
  • Loading branch information
fbm3307 and MatousJobanek authored Jan 13, 2025
1 parent 69a195d commit 7841eba
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-golang-sbom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.52.0
version: v1.63.1
skip-pkg-cache: true
skip-build-cache: true
args: --config=./.golangci.yml --verbose
Expand Down
2 changes: 1 addition & 1 deletion controllers/space/space_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (r *Reconciler) ensureNSTemplateSet(ctx context.Context, space *toolchainv1

return norequeue, r.setStatusProvisioned(ctx, space)
default:
return norequeue, r.setStatusProvisioningFailed(ctx, space, fmt.Errorf(nsTmplSetReady.Message))
return norequeue, r.setStatusProvisioningFailed(ctx, space, fmt.Errorf("%s", nsTmplSetReady.Message))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ func (r *Reconciler) determineCapacityReadyState(spc *toolchainv1alpha1.SpacePro
// It always knows this fact so returning a bool is ok, in contrast to determinMemoryUtilizationReadyState.
func determineSpaceCountReadyState(spc *toolchainv1alpha1.SpaceProvisionerConfig) bool {
max := spc.Spec.CapacityThresholds.MaxNumberOfSpaces
return max == 0 || max > uint(spc.Status.ConsumedCapacity.SpaceCount)
// we don't expect that the max number of spaces would ever go above the max size of int, so we don't have to worry about the overflow error, hence its okay to ignore the linter here
return max == 0 || int(max) > spc.Status.ConsumedCapacity.SpaceCount // nolint:gosec
}

// determineMemoryUtilizationReadyState checks that the cluster has enough free memory. It may not be able to tell the fact
Expand All @@ -203,7 +204,8 @@ func determineMemoryUtilizationReadyState(spc *toolchainv1alpha1.SpaceProvisione

// the memory utilitzation is ok if it is below the threshold in all node types
for _, val := range spc.Status.ConsumedCapacity.MemoryUsagePercentPerNodeRole {
if uint(val) >= spc.Spec.CapacityThresholds.MaxMemoryUtilizationPercent {
// the MaxMemoryUtilizationPercent won't go over 100, so it's safe to cast it to int and to not worry about overflow error, thus ignoring the linter
if val >= int(spc.Spec.CapacityThresholds.MaxMemoryUtilizationPercent) { // nolint:gosec
return corev1.ConditionFalse
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/toolchainconfig/toolchainconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.

if syncErrs := sync.SyncMemberConfigs(ctx, toolchainConfig); len(syncErrs) > 0 {
for cluster, errMsg := range syncErrs {
err := fmt.Errorf(errMsg)
err := fmt.Errorf("%s", errMsg)
reqLogger.Error(err, "error syncing configuration to member cluster", "cluster", cluster)
}
return DefaultReconcile, r.updateSyncStatus(ctx, toolchainConfig, syncErrs, ToSyncFailure())
Expand Down
2 changes: 1 addition & 1 deletion controllers/toolchainstatus/toolchainstatus_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ func (s *regServiceSubstatusHandler) addRegistrationServiceHealthAndRevisionChec
// add the health status to the toolchainstatus
toolchainStatus.Status.RegistrationService.Health = healthStatus
if !healthValues.Alive {
err = fmt.Errorf(errMsgRegistrationServiceHealthStatusUnhealthy)
err = fmt.Errorf("%s", errMsgRegistrationServiceHealthStatusUnhealthy)
logger.Error(err, "registration service is unhealthy")
errCondition := status.NewComponentErrorCondition(toolchainv1alpha1.ToolchainStatusRegServiceNotReadyReason, err.Error())
toolchainStatus.Status.RegistrationService.Health.Conditions = []toolchainv1alpha1.Condition{*errCondition}
Expand Down
7 changes: 4 additions & 3 deletions controllers/usersignup/usersignup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"strconv"

recaptcha "cloud.google.com/go/recaptchaenterprise/v2/apiv1"
recaptchapb "cloud.google.com/go/recaptchaenterprise/v2/apiv1/recaptchaenterprisepb"
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
Expand Down Expand Up @@ -36,7 +38,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"strconv"
)

type StatusUpdaterFunc func(ctx context.Context, userAcc *toolchainv1alpha1.UserSignup, message string) error
Expand Down Expand Up @@ -610,7 +611,7 @@ func (r *Reconciler) generateCompliantUsername(
} else if mur.Labels[toolchainv1alpha1.MasterUserRecordOwnerLabelKey] == instance.Name {
// If the found MUR has the same UserID as the UserSignup, then *it* is the correct MUR -
// Return an error here and allow the reconcile() function to pick it up on the next loop
return "", fmt.Errorf(fmt.Sprintf("INFO: could not generate compliant username as MasterUserRecord with the same name [%s] and user id [%s] already exists. The next reconcile loop will pick it up.", mur.Name, instance.Name))
return "", fmt.Errorf("INFO: could not generate compliant username as MasterUserRecord with the same name [%s] and user id [%s] already exists. The next reconcile loop will pick it up", mur.Name, instance.Name)
}

if len(transformed) > maxlengthWithSuffix {
Expand All @@ -620,7 +621,7 @@ func (r *Reconciler) generateCompliantUsername(
}
}

return "", fmt.Errorf(fmt.Sprintf("unable to transform username [%s] even after 100 attempts", instance.Spec.IdentityClaims.PreferredUsername))
return "", fmt.Errorf("unable to transform username [%s] even after 100 attempts", instance.Spec.IdentityClaims.PreferredUsername)
}

// provisionMasterUserRecord does the work of provisioning the MasterUserRecord
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,10 @@ func addMemberClusters(mgr ctrl.Manager, cl runtimeclient.Client, namespace stri
}
})
if err != nil {
return nil, errors.Wrapf(err, "unable to create member cluster definition for "+memberConfig.Name)
return nil, fmt.Errorf("unable to create member cluster definition for '%s': %w", memberConfig.Name, err)
}
if err := mgr.Add(memberCluster); err != nil {
return nil, errors.Wrapf(err, "unable to add member cluster to the manager for "+memberConfig.Name)
return nil, fmt.Errorf("unable to add member cluster to the manager for '%s' : %w", memberConfig.Name, err)
}
// These fields need to be set when using the REST client
memberConfig.RestConfig.ContentConfig = rest.ContentConfig{
Expand All @@ -476,7 +476,7 @@ func addMemberClusters(mgr ctrl.Manager, cl runtimeclient.Client, namespace stri
}
restClient, err := rest.RESTClientFor(memberConfig.RestConfig)
if err != nil {
return nil, errors.Wrapf(err, "unable to create member cluster rest client "+memberConfig.Name)
return nil, fmt.Errorf("unable to create member cluster rest client '%s' : %w", memberConfig.Name, err)
}
memberClusters[memberConfig.Name] = cluster.Cluster{
Config: memberConfig,
Expand Down
6 changes: 4 additions & 2 deletions pkg/capacity/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type (

func hasNotReachedMaxNumberOfSpacesThreshold(counts counter.Counts) spaceProvisionerConfigPredicate {
return func(spc *toolchainv1alpha1.SpaceProvisionerConfig) bool {
numberOfSpaces := uint(counts.SpacesPerClusterCounts[spc.Spec.ToolchainCluster])
// the numbers of Spaces per cluster shouldn't be negative, so it's fine to cast it to uint without worrying about the overflow error, and thus also ignore the linter
numberOfSpaces := uint(counts.SpacesPerClusterCounts[spc.Spec.ToolchainCluster]) // nolint:gosec
threshold := spc.Spec.CapacityThresholds.MaxNumberOfSpaces
return threshold == 0 || numberOfSpaces < threshold
}
Expand All @@ -45,7 +46,8 @@ func hasEnoughMemoryCapacity(status *toolchainv1alpha1.ToolchainStatus) spacePro
func hasMemberEnoughMemoryCapacity(memberStatus toolchainv1alpha1.Member, threshold uint) bool {
if len(memberStatus.MemberStatus.ResourceUsage.MemoryUsagePerNodeRole) > 0 {
for _, usagePerNode := range memberStatus.MemberStatus.ResourceUsage.MemoryUsagePerNodeRole {
if uint(usagePerNode) >= threshold {
// the memory utilization threshold should be max 100, so it's fine to cast it to int without worrying about the overflow error, thus ignoring the linter here
if usagePerNode >= int(threshold) { // nolint:gosec
return false
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func NewSpaceWithFeatureToggles(userSignup *toolchainv1alpha1.UserSignup, target
func addFeatureToggles(space *toolchainv1alpha1.Space, toggles []toolchainconfig.FeatureToggle) {
var winners []string
for _, t := range toggles {
weight := int(t.Weight())
//the value of weight is not expected to go beyond 100, it won't overflow, hence its okay to ignore the overflow linter error
weight := int(t.Weight()) // nolint:gosec
// We generate a random number between 0 and 100. If the number is equal to or lower than the weight
// then the feature wins.
// We don't use recommended crypto/rand here because we don't need crypto grade random generator
Expand Down

0 comments on commit 7841eba

Please sign in to comment.