diff --git a/cmd/web-console-validator/main.go b/cmd/web-console-validator/main.go index f45bd4a15..1183e2cf5 100644 --- a/cmd/web-console-validator/main.go +++ b/cmd/web-console-validator/main.go @@ -4,6 +4,7 @@ package main import ( + "errors" "flag" "net/http" "os" @@ -93,7 +94,7 @@ func main() { } logger.Info("Starting the web-console validation server", "port", *serverPort, "path", *serverPath) - if err := server.Run(); err != nil && err != http.ErrServerClosed { + if err := server.Run(); err != nil && !errors.Is(err, http.ErrServerClosed) { logger.Error(err, "Failed to run the web-console validation server") os.Exit(1) } diff --git a/controllers/infra/zone/zone_controller.go b/controllers/infra/zone/zone_controller.go index da451f7ef..35db92912 100644 --- a/controllers/infra/zone/zone_controller.go +++ b/controllers/infra/zone/zone_controller.go @@ -5,6 +5,7 @@ package zone import ( "context" + "errors" "fmt" "reflect" "strings" @@ -131,7 +132,7 @@ func (r *Reconciler) ReconcileDelete( }, fmt.Sprintf("%s/%s", obj.Namespace, obj.Name)); err != nil { - if err != watcher.ErrAsyncSignalDisabled { + if !errors.Is(err, watcher.ErrAsyncSignalDisabled) { return ctrl.Result{}, err } } @@ -157,7 +158,7 @@ func (r *Reconciler) ReconcileNormal( }, fmt.Sprintf("%s/%s", obj.Namespace, obj.Name)); err != nil { - if err != watcher.ErrAsyncSignalDisabled { + if !errors.Is(err, watcher.ErrAsyncSignalDisabled) { return ctrl.Result{}, err } } diff --git a/controllers/virtualmachine/virtualmachine/virtualmachine_controller.go b/controllers/virtualmachine/virtualmachine/virtualmachine_controller.go index f96e8be1c..9e76db362 100644 --- a/controllers/virtualmachine/virtualmachine/virtualmachine_controller.go +++ b/controllers/virtualmachine/virtualmachine/virtualmachine_controller.go @@ -546,10 +546,10 @@ func getIsDefaultVMClassController(ctx context.Context) bool { // ignoredCreateErr is written this way in order to illustrate coverage more // accurately. func ignoredCreateErr(err error) bool { - if err == providers.ErrDuplicateCreate { + if errors.Is(err, providers.ErrDuplicateCreate) { return true } - if err == providers.ErrTooManyCreates { + if errors.Is(err, providers.ErrTooManyCreates) { return true } return false diff --git a/pkg/util/vsphere/vm/power_state.go b/pkg/util/vsphere/vm/power_state.go index a9280216d..7b52ee15c 100644 --- a/pkg/util/vsphere/vm/power_state.go +++ b/pkg/util/vsphere/vm/power_state.go @@ -382,7 +382,7 @@ func doAndWaitOnSoftPowerOp( defer cancel() if err := waitForPowerStateFn(ctx, desiredPowerState); err != nil { - if ctx.Err() == context.DeadlineExceeded { + if errors.Is(ctx.Err(), context.DeadlineExceeded) { return 0, fmt.Errorf("timed out waiting for power state %s", desiredPowerState) } return 0, fmt.Errorf("failed to wait for power state %s %w", desiredPowerState, err) @@ -606,7 +606,7 @@ func doAndWaitOnSoftRestart( defer cancel() if err := powerOpFn(ctx); err != nil { - if ctx.Err() == context.DeadlineExceeded { + if errors.Is(ctx.Err(), context.DeadlineExceeded) { return 0, errors.New("timed out while soft restarting vm") } return 0, fmt.Errorf("failed to soft restart vm %w", err) diff --git a/pkg/vmconfig/crypto/crypto_reconciler_pre.go b/pkg/vmconfig/crypto/crypto_reconciler_pre.go index 3d5cb2f61..2c8c83039 100644 --- a/pkg/vmconfig/crypto/crypto_reconciler_pre.go +++ b/pkg/vmconfig/crypto/crypto_reconciler_pre.go @@ -383,7 +383,7 @@ func (r reconciler) reconcileUpdateDefaultKeyProvider( } func setConditionAndReturnErr(args reconcileArgs, err error, r Reason) error { - if err == ErrInvalidKeyProvider || err == ErrInvalidKeyID { + if errors.Is(err, ErrInvalidKeyProvider) || errors.Is(err, ErrInvalidKeyID) { r = ReasonEncryptionClassInvalid } else if apierrors.IsNotFound(err) { r = ReasonEncryptionClassNotFound diff --git a/webhooks/virtualmachine/mutation/virtualmachine_mutator.go b/webhooks/virtualmachine/mutation/virtualmachine_mutator.go index 547170d6f..e0593749a 100644 --- a/webhooks/virtualmachine/mutation/virtualmachine_mutator.go +++ b/webhooks/virtualmachine/mutation/virtualmachine_mutator.go @@ -6,6 +6,7 @@ package mutation import ( "context" "encoding/json" + "errors" "fmt" "net/http" "reflect" @@ -596,7 +597,7 @@ func SetDefaultEncryptionClass( k8sClient, vm.Namespace) if err != nil { - if err == kubeutil.ErrNoDefaultEncryptionClass { + if errors.Is(err, kubeutil.ErrNoDefaultEncryptionClass) { return false, nil } return false, err