Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Bump golangci to v1.60.2 #11132

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr-golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # tag=v6.1.0
with:
version: v1.59.0
version: v1.60.2
args: --out-format=colored-line-number
working-directory: ${{matrix.working-directory}}
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ linters:
- whitespace # unnecessary newlines

linters-settings:
gosec:
excludes:
# integer overflow conversion int -> int32
- G115
sbueringer marked this conversation as resolved.
Show resolved Hide resolved
gci:
sections:
- standard # Standard section: captures all standard packages.
Expand Down Expand Up @@ -348,3 +352,12 @@ issues:
- gocritic
text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop"
path: _test\.go
# Ignore non-constant format string in call to condition utils
- linters:
- govet
text: "non-constant format string in call to sigs\\.k8s\\.io\\/cluster-api\\/util\\/conditions\\."
exclude-files:
- "zz_generated.*\\.go$"
- "vendored_openapi\\.go$"
# We don't want to invest time to fix new linter findings in old API types.
- "internal/apis/.*"
sbueringer marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion cmd/clusterctl/cmd/describe_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func getRowName(obj ctrlclient.Object) string {

name := objName
if objectPrefix := tree.GetMetaName(obj); objectPrefix != "" {
name = fmt.Sprintf("%s - %s", objectPrefix, gray.Sprintf(name))
name = fmt.Sprintf("%s - %s", objectPrefix, gray.Sprintf("%s", name))
}

if !obj.GetDeletionTimestamp().IsZero() {
Expand Down
8 changes: 4 additions & 4 deletions internal/controllers/machinedeployment/mdutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ func SetDeploymentRevision(deployment *clusterv1.MachineDeployment, revision str
func MaxRevision(ctx context.Context, allMSs []*clusterv1.MachineSet) int64 {
log := ctrl.LoggerFrom(ctx)

max := int64(0)
maxVal := int64(0)
for _, ms := range allMSs {
if v, err := Revision(ms); err != nil {
// Skip the machine sets when it failed to parse their revision information
log.Error(err, fmt.Sprintf("Couldn't parse revision for MachineSet %s, deployment controller will skip it when reconciling revisions", ms.Name))
} else if v > max {
max = v
} else if v > maxVal {
maxVal = v
}
}
return max
return maxVal
}

// Revision returns the revision number of the input object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,13 +580,13 @@ func isAllowedRemediation(mhc *clusterv1.MachineHealthCheck) (bool, int32, error
var remediationAllowed bool
var remediationCount int32
if mhc.Spec.UnhealthyRange != nil {
min, max, err := getUnhealthyRange(mhc)
minVal, maxVal, err := getUnhealthyRange(mhc)
if err != nil {
return false, 0, err
}
unhealthyMachineCount := unhealthyMachineCount(mhc)
remediationAllowed = unhealthyMachineCount >= min && unhealthyMachineCount <= max
remediationCount = int32(max - unhealthyMachineCount)
remediationAllowed = unhealthyMachineCount >= minVal && unhealthyMachineCount <= maxVal
remediationCount = int32(maxVal - unhealthyMachineCount)
return remediationAllowed, remediationCount, nil
}

Expand All @@ -610,21 +610,21 @@ func getUnhealthyRange(mhc *clusterv1.MachineHealthCheck) (int, int, error) {

parts := strings.Split(unhealthyRange, "-")

min, err := strconv.ParseUint(parts[0], 10, 32)
minVal, err := strconv.ParseUint(parts[0], 10, 32)
if err != nil {
return 0, 0, err
}

max, err := strconv.ParseUint(parts[1], 10, 32)
maxVal, err := strconv.ParseUint(parts[1], 10, 32)
if err != nil {
return 0, 0, err
}

if max < min {
return 0, 0, errors.Errorf("max value %d cannot be less than min value %d for unhealthyRange", max, min)
if maxVal < minVal {
return 0, 0, errors.Errorf("max value %d cannot be less than min value %d for unhealthyRange", maxVal, minVal)
}

return int(min), int(max), nil
return int(minVal), int(maxVal), nil
}

func getMaxUnhealthy(mhc *clusterv1.MachineHealthCheck) (int, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func TestHealthCheckTargets(t *testing.T) {
machineFailureMsgCondition := newFailedHealthCheckCondition(clusterv1.MachineHasFailureReason, "FailureMessage: %s", failureMsg)

// Target for when the machine has the remediate machine annotation
annotationRemediationMsg := "Marked for remediation via remediate-machine annotation"
const annotationRemediationMsg = "Marked for remediation via remediate-machine annotation"
testMachineAnnotationRemediation := testMachine.DeepCopy()
testMachineAnnotationRemediation.Annotations = map[string]string{clusterv1.RemediateMachineAnnotation: ""}
machineAnnotationRemediation := healthCheckTarget{
Expand Down
2 changes: 1 addition & 1 deletion test/framework/docker_logcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (k DockerLogCollector) collectLogsFromNode(ctx context.Context, outputPath
"tar", "--hard-dereference", "--dereference", "--directory", containerDir, "--create", "--file", "-", ".",
)
if err != nil {
return errors.Wrapf(err, execErr)
return errors.Wrap(err, execErr)
}

err = os.MkdirAll(outputDir, 0750)
Expand Down
14 changes: 5 additions & 9 deletions test/infrastructure/inmemory/pkg/runtime/cache/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,8 @@ func (c *cache) store(resourceGroup string, obj client.Object, replaceExisting b
return apierrors.NewConflict(unsafeGuessGroupVersionResource(objGVK).GroupResource(), objKey.String(), fmt.Errorf("object has been modified"))
}

if err := c.beforeUpdate(resourceGroup, trackedObj, obj); err != nil {
return err
}
c.beforeUpdate(resourceGroup, trackedObj, obj)

tracker.objects[objGVK][objKey] = obj.DeepCopyObject().(client.Object)
updateTrackerOwnerReferences(tracker, trackedObj, obj, objRef)
c.afterUpdate(resourceGroup, trackedObj, obj)
Expand All @@ -227,9 +226,8 @@ func (c *cache) store(resourceGroup string, obj client.Object, replaceExisting b
return apierrors.NewNotFound(unsafeGuessGroupVersionResource(objGVK).GroupResource(), objKey.String())
}

if err := c.beforeCreate(resourceGroup, obj); err != nil {
return err
}
c.beforeCreate(resourceGroup, obj)

tracker.objects[objGVK][objKey] = obj.DeepCopyObject().(client.Object)
updateTrackerOwnerReferences(tracker, nil, obj, objRef)
c.afterCreate(resourceGroup, obj)
Expand Down Expand Up @@ -424,9 +422,7 @@ func (c *cache) doTryDeleteLocked(resourceGroup string, tracker *resourceGroupTr
oldObj := obj.DeepCopyObject().(client.Object)
now := metav1.Time{Time: time.Now().UTC()}
obj.SetDeletionTimestamp(&now)
if err := c.beforeUpdate(resourceGroup, oldObj, obj); err != nil {
return false, apierrors.NewBadRequest(err.Error())
}
c.beforeUpdate(resourceGroup, oldObj, obj)

objects[objKey] = obj
c.afterUpdate(resourceGroup, oldObj, obj)
Expand Down
6 changes: 2 additions & 4 deletions test/infrastructure/inmemory/pkg/runtime/cache/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,19 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

func (c *cache) beforeCreate(_ string, obj client.Object) error {
func (c *cache) beforeCreate(_ string, obj client.Object) {
now := time.Now().UTC()
obj.SetCreationTimestamp(metav1.Time{Time: now})
// TODO: UID
obj.SetAnnotations(appendAnnotations(obj, lastSyncTimeAnnotation, now.Format(time.RFC3339)))
obj.SetResourceVersion(fmt.Sprintf("v%d", 1))
return nil
}

func (c *cache) afterCreate(resourceGroup string, obj client.Object) {
c.informCreate(resourceGroup, obj)
}

func (c *cache) beforeUpdate(_ string, oldObj, newObj client.Object) error {
func (c *cache) beforeUpdate(_ string, oldObj, newObj client.Object) {
newObj.SetCreationTimestamp(oldObj.GetCreationTimestamp())
newObj.SetResourceVersion(oldObj.GetResourceVersion())
// TODO: UID
Expand All @@ -55,7 +54,6 @@ func (c *cache) beforeUpdate(_ string, oldObj, newObj client.Object) error {
oldResourceVersion, _ := strconv.Atoi(strings.TrimPrefix(oldObj.GetResourceVersion(), "v"))
newObj.SetResourceVersion(fmt.Sprintf("v%d", oldResourceVersion+1))
}
return nil
}

func (c *cache) afterUpdate(resourceGroup string, oldObj, newObj client.Object) {
Expand Down
Loading