Skip to content

Commit

Permalink
chore: fix golangci-lint errors on 1.22
Browse files Browse the repository at this point in the history
  • Loading branch information
grdryn committed Nov 28, 2024
1 parent 1d3d1c6 commit 07b1ad5
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 15 deletions.
5 changes: 4 additions & 1 deletion Dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Build the manager binary
ARG GOLANG_VERSION=1.22

################################################################################
FROM registry.access.redhat.com/ubi8/toolbox as manifests
ARG USE_LOCAL=false
Expand All @@ -12,7 +15,7 @@ RUN if [ "${USE_LOCAL}" != "true" ]; then \
fi

################################################################################
FROM registry.access.redhat.com/ubi8/go-toolset:latest as builder
FROM registry.access.redhat.com/ubi8/go-toolset:$GOLANG_VERSION as builder
ARG CGO_ENABLED=1
USER root
WORKDIR /workspace
Expand Down
1 change: 0 additions & 1 deletion components/kserve/kserve_config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func (k *Kserve) setDefaultDeploymentMode(ctx context.Context, cli client.Client
return fmt.Errorf("failed to list pods: %w", err)
}
for _, pod := range podList.Items {
pod := pod
if err := cli.Delete(ctx, &pod); err != nil {
return fmt.Errorf("failed to delete pod %s: %w", pod.Name, err)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/secretgenerator/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func generateSecretValue(secret *Secret) error {
switch secret.Type {
case "random":
randomValue := make([]byte, secret.Complexity)
for i := 0; i < secret.Complexity; i++ {
for i := range secret.Complexity {
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(letterRunes))))
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion controllers/secretgenerator/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func TestNewSecret(t *testing.T) {
}

for name, tc := range cases {
tc := tc
t.Run(name, func(t *testing.T) {
secret, err := secretgenerator.NewSecretFrom(tc.annotations)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions pkg/upgrade/uninstallation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func OperatorUninstall(ctx context.Context, cli client.Client, platform cluster.
}

for _, namespace := range generatedNamespaces.Items {
namespace := namespace
if namespace.Status.Phase == corev1.NamespaceActive {
if err := cli.Delete(ctx, &namespace); err != nil {
return fmt.Errorf("error deleting namespace %v: %w", namespace.Name, err)
Expand Down Expand Up @@ -95,7 +94,6 @@ func removeDSCInitialization(ctx context.Context, cli client.Client) error {

var multiErr *multierror.Error
for _, dsciInstance := range instanceList.Items {
dsciInstance := dsciInstance
if err := cli.Delete(ctx, &dsciInstance); !k8serr.IsNotFound(err) {
multiErr = multierror.Append(multiErr, err)
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ func deleteOneResource(ctx context.Context, c client.Client, res ResourceSpec) e
}

for _, item := range list.Items {
item := item
v, ok, err := unstructured.NestedString(item.Object, res.Path...)
if err != nil {
return fmt.Errorf("failed to get field %v for %s %s/%s: %w", res.Path, res.Gvk.Kind, res.Namespace, item.GetName(), err)
Expand Down Expand Up @@ -352,7 +351,7 @@ func deleteDeprecatedResources(ctx context.Context, cli client.Client, namespace
multiErr = multierror.Append(multiErr, err)
}
items := reflect.ValueOf(resourceType).Elem().FieldByName("Items")
for i := 0; i < items.Len(); i++ {
for i := range items.Len() {
item := items.Index(i).Addr().Interface().(client.Object) //nolint:errcheck,forcetypeassert
for _, name := range resourceList {
if name == item.GetName() {
Expand Down Expand Up @@ -383,7 +382,6 @@ func deleteDeprecatedServiceMonitors(ctx context.Context, cli client.Client, nam
}

for _, servicemonitor := range servicemonitors.Items {
servicemonitor := servicemonitor
for _, name := range resourceList {
if name == servicemonitor.Name {
log.Info("Attempting to delete " + servicemonitor.Name + " in namespace " + namespace)
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func (tc *testContext) testAllComponentCreation(t *testing.T) error { //nolint:f
}

for _, c := range components {
c := c
name := c.GetComponentName()
t.Run("Validate "+name, func(t *testing.T) {
t.Parallel()
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/deletion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (tc *testContext) testAllApplicationDeletion(t *testing.T) error { //nolint
}

for _, c := range components {
c := c
t.Run("Delete "+c.GetComponentName(), func(t *testing.T) {
t.Parallel()
err = tc.testComponentDeletion(c)
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func getCSV(ctx context.Context, cli client.Client, name string, namespace strin
}

// do not use range Items to avoid pointer to the loop variable
for i := 0; i < len(csvList.Items); i++ {
for i := range len(csvList.Items) {
csv := &csvList.Items[i]
if isMatched(csv, name) {
return csv, nil
Expand Down Expand Up @@ -409,15 +409,14 @@ func ensureServicemeshOperators(t *testing.T, tc *testContext) error { //nolint:
c := make(chan error)

for _, op := range ops {
op := op // to avoid loop variable in the closures
t.Logf("Ensuring %s is installed", op)
go func(op string) {
err := ensureOperator(tc, op, servicemeshNamespace)
c <- err
}(op)
}

for i := 0; i < len(ops); i++ {
for range len(ops) {
err := <-c
errors = multierror.Append(errors, err)
}
Expand Down
1 change: 0 additions & 1 deletion tests/envtestutil/cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func CreateCleaner(c client.Client, config *rest.Config, timeout, interval time.

func (c *Cleaner) DeleteAll(ctx context.Context, objects ...client.Object) {
for _, obj := range objects {
obj := obj
Expect(client.IgnoreNotFound(c.client.Delete(ctx, obj))).Should(Succeed())

if ns, ok := obj.(*corev1.Namespace); ok {
Expand Down

0 comments on commit 07b1ad5

Please sign in to comment.