Skip to content

Commit

Permalink
Address new linter errors introduced with Go 1.22
Browse files Browse the repository at this point in the history
  • Loading branch information
grdryn committed Dec 11, 2024
1 parent 29019b9 commit 58103cc
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 13 deletions.
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++ { //nolint: intrange
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 //nolint: copyloopvar
t.Run(name, func(t *testing.T) {
secret, err := secretgenerator.NewSecretFrom(tc.annotations)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestRenderResourcesWithCacheAction(t *testing.T) {

render.RenderedResourcesTotal.Reset()

for i := int64(0); i < 3; i++ { //nolint: intrange
for i := range 3 {
d := componentApi.Dashboard{}

if i >= 1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestRenderTemplateWithCache(t *testing.T) {
},
}

for i := int64(0); i < 3; i++ { //nolint: intrange
for i := range 3 {
d := componentApi.Dashboard{
ObjectMeta: metav1.ObjectMeta{
Name: ns,
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 //nolint: copyloopvar
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 //nolint: copyloopvar
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 @@ -313,7 +313,6 @@ func deleteOneResource(ctx context.Context, c client.Client, res ResourceSpec) e
}

for _, item := range list.Items {
item := item //nolint: copyloopvar
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 @@ -345,7 +344,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++ { //nolint: intrange
for i := range items.Len() {

Check warning on line 347 in pkg/upgrade/upgrade.go

View check run for this annotation

Codecov / codecov/patch

pkg/upgrade/upgrade.go#L347

Added line #L347 was not covered by tests
item := items.Index(i).Addr().Interface().(client.Object) //nolint:errcheck,forcetypeassert
for _, name := range resourceList {
if name == item.GetName() {
Expand Down Expand Up @@ -376,7 +375,6 @@ func deleteDeprecatedServiceMonitors(ctx context.Context, cli client.Client, nam
}

for _, servicemonitor := range servicemonitors.Items {
servicemonitor := servicemonitor //nolint: copyloopvar
for _, name := range resourceList {
if name == servicemonitor.Name {
log.Info("Attempting to delete " + servicemonitor.Name + " in namespace " + namespace)
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 @@ -256,7 +256,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++ { //nolint: intrange
for i := range len(csvList.Items) {
csv := &csvList.Items[i]
if isMatched(csv, name) {
return csv, nil
Expand Down Expand Up @@ -416,15 +416,14 @@ func ensureServicemeshOperators(t *testing.T, tc *testContext) error { //nolint:
c := make(chan error)

for _, op := range ops {
op := op //nolint: copyloopvar
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++ { //nolint: intrange
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 //nolint: copyloopvar
Expect(client.IgnoreNotFound(c.client.Delete(ctx, obj))).Should(Succeed())

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

0 comments on commit 58103cc

Please sign in to comment.