From 80bb236aaf3f67498e72e5c14f7a2c6efe38df0b Mon Sep 17 00:00:00 2001 From: Kashif Khan Date: Thu, 28 Mar 2024 15:52:32 +0200 Subject: [PATCH] Enabled last batch of linters Signed-off-by: Kashif Khan --- .golangci.yaml | 27 +++- .../metal3.io/v1alpha1/baremetalhost_types.go | 2 +- .../v1alpha1/baremetalhost_types_test.go | 1 - .../v1alpha1/baremetalhost_validation.go | 1 - .../v1alpha1/baremetalhost_webhook.go | 3 +- .../v1alpha1/bmceventsubscription_webhook.go | 3 +- .../hostfirmwaresettings_types_test.go | 1 - cmd/get-hardware-details/main.go | 3 +- cmd/make-virt-host/main.go | 16 ++- controllers/metal3.io/action_result.go | 3 +- .../metal3.io/baremetalhost_controller.go | 30 +++-- .../baremetalhost_controller_test.go | 39 +++--- .../bmceventsubscription_controller.go | 10 +- controllers/metal3.io/controller_test.go | 6 +- controllers/metal3.io/demo_test.go | 11 +- controllers/metal3.io/host_config_data.go | 5 +- .../metal3.io/host_config_data_test.go | 21 ++- controllers/metal3.io/host_state_machine.go | 13 +- .../metal3.io/host_state_machine_test.go | 10 +- .../hostfirmwaresettings_controller.go | 6 +- .../metal3.io/hostfirmwaresettings_test.go | 10 +- controllers/metal3.io/metrics.go | 4 +- .../preprovisioningimage_controller.go | 9 +- main.go | 20 ++- main_test.go | 8 +- pkg/hardwareutils/bmc/ilo4.go | 2 +- pkg/hardwareutils/bmc/ilo5.go | 2 +- pkg/hardwareutils/bmc/irmc.go | 2 +- pkg/imageprovider/default.go | 1 - pkg/imageprovider/imageprovider.go | 4 +- pkg/provisioner/demo/demo.go | 10 +- pkg/provisioner/fixture/fixture.go | 5 +- pkg/provisioner/ironic/adopt_test.go | 3 +- pkg/provisioner/ironic/bios_test.go | 3 +- pkg/provisioner/ironic/capabilities_test.go | 3 +- pkg/provisioner/ironic/configdrive_test.go | 3 +- pkg/provisioner/ironic/delete_test.go | 3 +- pkg/provisioner/ironic/dependencies.go | 4 +- .../ironic/devicehints/devicehints_test.go | 3 +- pkg/provisioner/ironic/factory.go | 1 - pkg/provisioner/ironic/findhost_test.go | 1 - .../ironic/hardwaredetails/hardwaredetails.go | 1 - .../hardwaredetails/hardwaredetails_test.go | 3 +- .../ironic/inspecthardware_test.go | 3 +- pkg/provisioner/ironic/ironic.go | 122 +++++++++--------- pkg/provisioner/ironic/ironic_test.go | 9 +- pkg/provisioner/ironic/power_test.go | 3 +- pkg/provisioner/ironic/prepare_test.go | 3 +- pkg/provisioner/ironic/provision_test.go | 5 +- .../ironic/provisioncapacity_test.go | 3 +- pkg/provisioner/ironic/raid.go | 23 ++-- pkg/provisioner/ironic/raid_test.go | 3 +- pkg/provisioner/ironic/ready_test.go | 3 +- pkg/provisioner/ironic/testbmc/testbmc.go | 2 +- pkg/provisioner/ironic/testserver/ironic.go | 8 +- pkg/provisioner/ironic/update_opts.go | 1 - .../ironic/updatehardwarestate_test.go | 3 +- pkg/provisioner/ironic/updateopts_test.go | 12 +- .../ironic/validatemanagementaccess_test.go | 3 +- pkg/provisioner/provisioner.go | 3 +- pkg/secretutils/secret_manager.go | 5 +- test/e2e/basic_ops_test.go | 6 +- test/e2e/cert_manager.go | 16 ++- test/e2e/common.go | 21 +-- test/e2e/e2e_config.go | 12 +- test/e2e/e2e_suite_test.go | 7 +- test/e2e/external_inspection_test.go | 3 +- test/e2e/inspection_test.go | 3 +- test/e2e/live_iso_test.go | 9 +- test/e2e/provisioning_and_annotation_test.go | 9 +- test/e2e/re_inspection_test.go | 6 +- test/e2e/upgrade_test.go | 18 ++- 72 files changed, 298 insertions(+), 342 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 4d49565531..aea3cebebe 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -8,27 +8,37 @@ run: linters: disable-all: true enable: + - asasalint - asciicheck + - bidichk - bodyclose + # - containedctx - dogsled - # - errcheck - # - errorlint + - dupword + - durationcheck + - errcheck + - errchkjson - exportloopref + - gci + - ginkgolinter - goconst - gocritic - godot - gofmt - goimports + - goprintffuncname + - gosec - gosimple - govet - importas - - gosec - ineffassign + - loggercheck - misspell - # - nakedret - # - nilerr - # - noctx + - nakedret + - nilerr + - noctx - nolintlint + - nosprintfhostport - prealloc - predeclared - revive @@ -38,7 +48,9 @@ linters: - thelper - typecheck - unconvert + - unparam - unused + - usestdlibvars - whitespace # Run with --fast=false for more extensive checks fast: true @@ -114,6 +126,9 @@ issues: - unused - revive - stylecheck + - noctx + - unparam + - gci # Specific exclude rules for deprecated fields that are still part of the codebase. # These should be removed as the referenced deprecated item is removed from the project. - linters: diff --git a/apis/metal3.io/v1alpha1/baremetalhost_types.go b/apis/metal3.io/v1alpha1/baremetalhost_types.go index 08c05d102e..32dfedb6f0 100644 --- a/apis/metal3.io/v1alpha1/baremetalhost_types.go +++ b/apis/metal3.io/v1alpha1/baremetalhost_types.go @@ -132,7 +132,7 @@ const ( OperationalStatusOK OperationalStatus = "OK" // OperationalStatusDiscovered is the status value for when the - // host is only partially configured, such as when when the BMC + // host is only partially configured, such as when the BMC // address is known but the login credentials are not. OperationalStatusDiscovered OperationalStatus = "discovered" diff --git a/apis/metal3.io/v1alpha1/baremetalhost_types_test.go b/apis/metal3.io/v1alpha1/baremetalhost_types_test.go index 7ee7f7bb71..b4a07a37e0 100644 --- a/apis/metal3.io/v1alpha1/baremetalhost_types_test.go +++ b/apis/metal3.io/v1alpha1/baremetalhost_types_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/apis/metal3.io/v1alpha1/baremetalhost_validation.go b/apis/metal3.io/v1alpha1/baremetalhost_validation.go index 59db52b7f6..35d85d0722 100644 --- a/apis/metal3.io/v1alpha1/baremetalhost_validation.go +++ b/apis/metal3.io/v1alpha1/baremetalhost_validation.go @@ -11,7 +11,6 @@ import ( "strings" "github.com/google/uuid" - "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" ) diff --git a/apis/metal3.io/v1alpha1/baremetalhost_webhook.go b/apis/metal3.io/v1alpha1/baremetalhost_webhook.go index f4138c1b8c..fe552ec55d 100644 --- a/apis/metal3.io/v1alpha1/baremetalhost_webhook.go +++ b/apis/metal3.io/v1alpha1/baremetalhost_webhook.go @@ -15,9 +15,8 @@ package v1alpha1 import ( "fmt" - kerrors "k8s.io/apimachinery/pkg/util/errors" - "k8s.io/apimachinery/pkg/runtime" + kerrors "k8s.io/apimachinery/pkg/util/errors" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" ) diff --git a/apis/metal3.io/v1alpha1/bmceventsubscription_webhook.go b/apis/metal3.io/v1alpha1/bmceventsubscription_webhook.go index 3c3870bc61..1ce61827e7 100644 --- a/apis/metal3.io/v1alpha1/bmceventsubscription_webhook.go +++ b/apis/metal3.io/v1alpha1/bmceventsubscription_webhook.go @@ -15,9 +15,8 @@ package v1alpha1 import ( "fmt" - kerrors "k8s.io/apimachinery/pkg/util/errors" - "k8s.io/apimachinery/pkg/runtime" + kerrors "k8s.io/apimachinery/pkg/util/errors" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" ) diff --git a/apis/metal3.io/v1alpha1/hostfirmwaresettings_types_test.go b/apis/metal3.io/v1alpha1/hostfirmwaresettings_types_test.go index fc2f78b694..56f14848d1 100644 --- a/apis/metal3.io/v1alpha1/hostfirmwaresettings_types_test.go +++ b/apis/metal3.io/v1alpha1/hostfirmwaresettings_types_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/cmd/get-hardware-details/main.go b/cmd/get-hardware-details/main.go index 39f4631a05..b782bc7b83 100644 --- a/cmd/get-hardware-details/main.go +++ b/cmd/get-hardware-details/main.go @@ -12,10 +12,9 @@ import ( "strings" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "k8s.io/klog/v2" - "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/hardwaredetails" + "k8s.io/klog/v2" ) type options struct { diff --git a/cmd/make-virt-host/main.go b/cmd/make-virt-host/main.go index 9b94c7265c..d78e43266d 100644 --- a/cmd/make-virt-host/main.go +++ b/cmd/make-virt-host/main.go @@ -156,7 +156,14 @@ func main() { } domainResult := Domain{} - xml.Unmarshal(virshOut, &domainResult) + err = xml.Unmarshal(virshOut, &domainResult) + if err != nil { + fmt.Fprintf(os.Stderr, + "ERROR: Could not unmarshal details of domain %s: %s\n", + virshDomain, err) + os.Exit(1) + } + if *verbose { fmt.Printf("%v\n", domainResult) } @@ -192,7 +199,12 @@ func main() { } var vbmcResult []VBMC - json.Unmarshal(vbmcOut, &vbmcResult) + _ = json.Unmarshal(vbmcOut, &vbmcResult) + if err != nil { + fmt.Fprintf(os.Stderr, "ERROR: Could not unmarshal details of vbmc: %s\n", err) + os.Exit(1) + } + nameToPort := make(map[string]int) for _, vbmc := range vbmcResult { if *verbose { diff --git a/controllers/metal3.io/action_result.go b/controllers/metal3.io/action_result.go index 903a7f122d..650ecc4f20 100644 --- a/controllers/metal3.io/action_result.go +++ b/controllers/metal3.io/action_result.go @@ -6,10 +6,9 @@ import ( "math/rand" "time" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/provisioner" + "sigs.k8s.io/controller-runtime/pkg/reconcile" ) // This is an upper limit for the ErrorCount, so that the max backoff diff --git a/controllers/metal3.io/baremetalhost_controller.go b/controllers/metal3.io/baremetalhost_controller.go index 7b9d83460b..04f482bc97 100644 --- a/controllers/metal3.io/baremetalhost_controller.go +++ b/controllers/metal3.io/baremetalhost_controller.go @@ -24,9 +24,15 @@ import ( "time" "github.com/go-logr/logr" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1/profile" + "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" + "github.com/metal3-io/baremetal-operator/pkg/imageprovider" + "github.com/metal3-io/baremetal-operator/pkg/provisioner" + "github.com/metal3-io/baremetal-operator/pkg/secretutils" + "github.com/metal3-io/baremetal-operator/pkg/utils" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" - corev1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -39,14 +45,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1/profile" - "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" - "github.com/metal3-io/baremetal-operator/pkg/imageprovider" - "github.com/metal3-io/baremetal-operator/pkg/provisioner" - "github.com/metal3-io/baremetal-operator/pkg/secretutils" - "github.com/metal3-io/baremetal-operator/pkg/utils" ) const ( @@ -224,7 +222,7 @@ func (r *BareMetalHostReconciler) Reconcile(ctx context.Context, request ctrl.Re if err != nil { err = errors.Wrap(err, fmt.Sprintf("action %q failed", initialState)) - return + return result, err } // Only save status when we're told to, otherwise we @@ -253,7 +251,7 @@ func (r *BareMetalHostReconciler) Reconcile(ctx context.Context, request ctrl.Re logResult(info, result) - return + return result, nil } // Consume inspect.metal3.io/hardwaredetails when either @@ -717,7 +715,11 @@ func (r *BareMetalHostReconciler) getPreprovImage(info *reconcileInfo, formats [ }, Spec: expectedSpec, } - controllerutil.SetControllerReference(info.host, &preprovImage, r.Scheme()) + err = controllerutil.SetControllerReference(info.host, &preprovImage, r.Scheme()) + if err != nil { + return nil, errors.Wrap(err, "failed to set controller reference for PreprovisioningImage") + } + err = r.Create(info.ctx, &preprovImage) return nil, err } @@ -1459,7 +1461,7 @@ func saveHostProvisioningSettings(host *metal3api.BareMetalHost, info *reconcile // Root device hints may change as a result of RAID dirty, err = updateRootDeviceHints(host, info) if err != nil { - return + return dirty, err } // Copy RAID settings @@ -1494,7 +1496,7 @@ func saveHostProvisioningSettings(host *metal3api.BareMetalHost, info *reconcile dirty = true } - return + return dirty, nil } func (r *BareMetalHostReconciler) createHostFirmwareSettings(info *reconcileInfo) error { diff --git a/controllers/metal3.io/baremetalhost_controller_test.go b/controllers/metal3.io/baremetalhost_controller_test.go index 52c3515179..cba36eb4ea 100644 --- a/controllers/metal3.io/baremetalhost_controller_test.go +++ b/controllers/metal3.io/baremetalhost_controller_test.go @@ -8,29 +8,25 @@ import ( "fmt" "testing" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" + "github.com/metal3-io/baremetal-operator/pkg/provisioner/fixture" + "github.com/metal3-io/baremetal-operator/pkg/secretutils" + "github.com/metal3-io/baremetal-operator/pkg/utils" + promutil "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/assert" - corev1 "k8s.io/api/core/v1" - k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" - - promutil "github.com/prometheus/client_golang/prometheus/testutil" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" "sigs.k8s.io/controller-runtime/pkg/event" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" - "github.com/metal3-io/baremetal-operator/pkg/provisioner/fixture" - "github.com/metal3-io/baremetal-operator/pkg/secretutils" - "github.com/metal3-io/baremetal-operator/pkg/utils" ) const ( @@ -142,7 +138,7 @@ func newTestReconcilerWithFixture(fix *fixture.Fixture, initObjs ...runtime.Obje c := clientBuilder.Build() // Add a default secret that can be used by most hosts. bmcSecret := newBMCCredsSecret(defaultSecretName, "User", "Pass") - c.Create(context.TODO(), bmcSecret) + _ = c.Create(context.TODO(), bmcSecret) return &BareMetalHostReconciler{ Client: c, @@ -551,7 +547,8 @@ func TestDoNotAddSecretFinalizersDuringDelete(t *testing.T) { // The fake client will immediately remove the host // from its cache, so let's keep the latest updated // host - r.Get(context.TODO(), request.NamespacedName, host) + err = r.Get(context.TODO(), request.NamespacedName, host) + assert.NoError(t, err) _, err = r.Reconcile(context.Background(), request) assert.NoError(t, err) @@ -559,7 +556,8 @@ func TestDoNotAddSecretFinalizersDuringDelete(t *testing.T) { // secret update (and a slow host deletion), let's push // back the host in the client cache. host.ResourceVersion = "" - r.Client.Create(context.TODO(), host) + err = r.Client.Create(context.TODO(), host) + assert.NoError(t, err) previousSecret := getHostSecret(t, r, host) _, err = r.Reconcile(context.Background(), request) assert.NoError(t, err) @@ -776,7 +774,8 @@ func TestRebootWithSuffixedAnnotation(t *testing.T) { ) delete(host.Annotations, annotation) - r.Update(context.TODO(), host) + err := r.Update(context.TODO(), host) + assert.NoError(t, err) tryReconcile(t, r, host, func(host *metal3api.BareMetalHost, result reconcile.Result) bool { @@ -2683,7 +2682,8 @@ func TestHostFirmwareSettings(t *testing.T) { i.request = newRequest(host) hfs := newHostFirmwareSettings(host, tc.Conditions) - r.Create(context.TODO(), hfs) + err := r.Create(context.TODO(), hfs) + assert.NoError(t, err) dirty, _, err := r.getHostFirmwareSettings(i) if err != nil { @@ -2751,7 +2751,8 @@ func TestHFSTransitionToPreparing(t *testing.T) { }, } - r.Update(context.TODO(), hfs) + err := r.Update(context.TODO(), hfs) + assert.NoError(t, err) waitForProvisioningState(t, r, host, metal3api.StatePreparing) } @@ -2783,7 +2784,8 @@ func TestHFSEmptyStatusSettings(t *testing.T) { }, } - r.Update(context.TODO(), hfs) + err := r.Update(context.TODO(), hfs) + assert.NoError(t, err) tryReconcile(t, r, host, func(host *metal3api.BareMetalHost, result reconcile.Result) bool { @@ -2799,7 +2801,8 @@ func TestHFSEmptyStatusSettings(t *testing.T) { }, } - r.Update(context.TODO(), hfs) + err = r.Update(context.TODO(), hfs) + assert.NoError(t, err) tryReconcile(t, r, host, func(host *metal3api.BareMetalHost, result reconcile.Result) bool { return host.Status.Provisioning.State == metal3api.StateAvailable diff --git a/controllers/metal3.io/bmceventsubscription_controller.go b/controllers/metal3.io/bmceventsubscription_controller.go index 919a044487..994cc56ddd 100644 --- a/controllers/metal3.io/bmceventsubscription_controller.go +++ b/controllers/metal3.io/bmceventsubscription_controller.go @@ -22,8 +22,10 @@ import ( "time" "github.com/go-logr/logr" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + "github.com/metal3-io/baremetal-operator/pkg/provisioner" + "github.com/metal3-io/baremetal-operator/pkg/utils" "github.com/pkg/errors" - corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" @@ -34,10 +36,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/predicate" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - "github.com/metal3-io/baremetal-operator/pkg/provisioner" - "github.com/metal3-io/baremetal-operator/pkg/utils" ) const ( @@ -125,7 +123,7 @@ func (r *BMCEventSubscriptionReconciler) Reconcile(ctx context.Context, request return ctrl.Result{}, nil } - return + return result, nil } func (r *BMCEventSubscriptionReconciler) handleError(ctx context.Context, subscription *metal3api.BMCEventSubscription, e error, message string, requeue bool) (ctrl.Result, error) { diff --git a/controllers/metal3.io/controller_test.go b/controllers/metal3.io/controller_test.go index b5c060524d..fff8997f6c 100644 --- a/controllers/metal3.io/controller_test.go +++ b/controllers/metal3.io/controller_test.go @@ -1,15 +1,15 @@ package controllers import ( + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "k8s.io/client-go/kubernetes/scheme" logf "sigs.k8s.io/controller-runtime/pkg/log" logz "sigs.k8s.io/controller-runtime/pkg/log/zap" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" ) func init() { logf.SetLogger(logz.New(logz.UseDevMode(true))) // Register our package types with the global scheme - metal3api.AddToScheme(scheme.Scheme) + err := metal3api.AddToScheme(scheme.Scheme) + logf.Log.Error(err, "Cannot Add scheme into metal3api") } diff --git a/controllers/metal3.io/demo_test.go b/controllers/metal3.io/demo_test.go index be47348e09..e849eba42d 100644 --- a/controllers/metal3.io/demo_test.go +++ b/controllers/metal3.io/demo_test.go @@ -4,16 +4,13 @@ import ( goctx "context" "testing" - "sigs.k8s.io/controller-runtime/pkg/client" - + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + "github.com/metal3-io/baremetal-operator/pkg/provisioner/demo" "k8s.io/apimachinery/pkg/runtime" - ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" "sigs.k8s.io/controller-runtime/pkg/reconcile" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - "github.com/metal3-io/baremetal-operator/pkg/provisioner/demo" ) func newDemoReconciler(initObjs ...runtime.Object) *BareMetalHostReconciler { @@ -25,7 +22,7 @@ func newDemoReconciler(initObjs ...runtime.Object) *BareMetalHostReconciler { // Add a default secret that can be used by most hosts. bmcSecret := newSecret(defaultSecretName, map[string]string{"username": "User", "password": "Pass"}) - c.Create(goctx.TODO(), bmcSecret) + _ = c.Create(goctx.TODO(), bmcSecret) return &BareMetalHostReconciler{ Client: c, diff --git a/controllers/metal3.io/host_config_data.go b/controllers/metal3.io/host_config_data.go index 0a298e24d9..3fd92dada0 100644 --- a/controllers/metal3.io/host_config_data.go +++ b/controllers/metal3.io/host_config_data.go @@ -2,11 +2,10 @@ package controllers import ( "github.com/go-logr/logr" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/types" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/secretutils" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/types" ) // hostConfigData is an implementation of host configuration data interface. diff --git a/controllers/metal3.io/host_config_data_test.go b/controllers/metal3.io/host_config_data_test.go index 24824e4e29..dd3e4ac925 100644 --- a/controllers/metal3.io/host_config_data_test.go +++ b/controllers/metal3.io/host_config_data_test.go @@ -8,14 +8,11 @@ import ( metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/secretutils" - + "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" - ctrl "sigs.k8s.io/controller-runtime" fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" - - "github.com/stretchr/testify/assert" ) func TestLabelSecrets(t *testing.T) { @@ -73,13 +70,15 @@ func TestLabelSecrets(t *testing.T) { } secret := newSecret(tc.name, map[string]string{"value": "somedata"}) - c.Create(context.TODO(), secret) + err := c.Create(context.TODO(), secret) + assert.NoError(t, err) - _, err := tc.getter(hcd) + _, err = tc.getter(hcd) assert.NoError(t, err) actualSecret := &corev1.Secret{} - c.Get(context.TODO(), types.NamespacedName{Name: tc.name, Namespace: namespace}, actualSecret) + err = c.Get(context.TODO(), types.NamespacedName{Name: tc.name, Namespace: namespace}, actualSecret) + assert.NoError(t, err) assert.Equal(t, "baremetal", actualSecret.Labels["environment.metal3.io"]) }) } @@ -335,10 +334,10 @@ func TestProvisionWithHostConfig(t *testing.T) { tc.Host.Spec.Online = true c := fakeclient.NewClientBuilder().WithObjects(tc.Host).Build() - c.Create(context.TODO(), testBMCSecret) - c.Create(context.TODO(), tc.UserDataSecret) - c.Create(context.TODO(), tc.NetworkDataSecret) - c.Create(context.TODO(), tc.PreprovNetworkDataSecret) + _ = c.Create(context.TODO(), testBMCSecret) + _ = c.Create(context.TODO(), tc.UserDataSecret) + _ = c.Create(context.TODO(), tc.NetworkDataSecret) + _ = c.Create(context.TODO(), tc.PreprovNetworkDataSecret) baselog := ctrl.Log.WithName("controllers").WithName("BareMetalHost") hcd := &hostConfigData{ host: tc.Host, diff --git a/controllers/metal3.io/host_state_machine.go b/controllers/metal3.io/host_state_machine.go index 7b97d6a3a9..28290e5082 100644 --- a/controllers/metal3.io/host_state_machine.go +++ b/controllers/metal3.io/host_state_machine.go @@ -4,10 +4,9 @@ import ( "encoding/json" "fmt" + "github.com/go-logr/logr" metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/provisioner" - - "github.com/go-logr/logr" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -325,20 +324,20 @@ func (hsm *hostStateMachine) ensureRegistered(info *reconcileInfo) (result actio // If we are in the process of deletion (which may start with // deprovisioning) and we have been unable to obtain any credentials, // don't attempt to re-register the Host as this will always fail. - return + return result } switch hsm.NextState { case metal3api.StateNone, metal3api.StateUnmanaged: // We haven't yet reached the Registration state, so don't attempt // to register the Host. - return + return result case metal3api.StateMatchProfile: // Backward compatibility, remove eventually - return + return result case metal3api.StateDeleting: // In the deleting state the whole idea is to de-register the host - return + return result case metal3api.StateRegistering: default: if hsm.Host.Status.ErrorType == metal3api.RegistrationError || @@ -359,7 +358,7 @@ func (hsm *hostStateMachine) ensureRegistered(info *reconcileInfo) (result actio if complete { result = actionUpdate{} } - return + return result } func (hsm *hostStateMachine) handleNone(info *reconcileInfo) actionResult { diff --git a/controllers/metal3.io/host_state_machine_test.go b/controllers/metal3.io/host_state_machine_test.go index fd02ecd2c0..446920ead9 100644 --- a/controllers/metal3.io/host_state_machine_test.go +++ b/controllers/metal3.io/host_state_machine_test.go @@ -6,7 +6,9 @@ import ( "time" metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - + "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1/profile" + "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" + "github.com/metal3-io/baremetal-operator/pkg/provisioner" promutil "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" @@ -14,10 +16,6 @@ import ( ctrl "sigs.k8s.io/controller-runtime" fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" logf "sigs.k8s.io/controller-runtime/pkg/log" - - "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1/profile" - "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" - "github.com/metal3-io/baremetal-operator/pkg/provisioner" ) func testStateMachine(host *metal3api.BareMetalHost) *hostStateMachine { @@ -1194,7 +1192,7 @@ func (hb *hostBuilder) build() *metal3api.BareMetalHost { func (hb *hostBuilder) SaveHostProvisioningSettings() *hostBuilder { info := makeDefaultReconcileInfo(&hb.BareMetalHost) - saveHostProvisioningSettings(&hb.BareMetalHost, info) + _, _ = saveHostProvisioningSettings(&hb.BareMetalHost, info) return hb } diff --git a/controllers/metal3.io/hostfirmwaresettings_controller.go b/controllers/metal3.io/hostfirmwaresettings_controller.go index 46e2394516..38f1fb5a2d 100644 --- a/controllers/metal3.io/hostfirmwaresettings_controller.go +++ b/controllers/metal3.io/hostfirmwaresettings_controller.go @@ -27,8 +27,9 @@ import ( "time" "github.com/go-logr/logr" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + "github.com/metal3-io/baremetal-operator/pkg/provisioner" "github.com/pkg/errors" - corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" @@ -39,9 +40,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - "github.com/metal3-io/baremetal-operator/pkg/provisioner" ) const ( diff --git a/controllers/metal3.io/hostfirmwaresettings_test.go b/controllers/metal3.io/hostfirmwaresettings_test.go index 828df70e53..bdaad9f2a2 100644 --- a/controllers/metal3.io/hostfirmwaresettings_test.go +++ b/controllers/metal3.io/hostfirmwaresettings_test.go @@ -4,14 +4,11 @@ import ( "context" "testing" - "github.com/stretchr/testify/assert" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/provisioner" - + "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" @@ -209,7 +206,7 @@ func createBaremetalHost() *metal3api.BareMetalHost { Log: ctrl.Log.WithName("bmh_reconciler").WithName("BareMetalHost"), } - reconciler.Create(context.TODO(), bmh) + _ = reconciler.Create(context.TODO(), bmh) return bmh } @@ -570,7 +567,8 @@ func TestStoreHostFirmwareSettings(t *testing.T) { firmwareSchema := getSchema() firmwareSchema.Spec.Schema = getCurrentSchemaSettings() - r.Client.Create(ctx, firmwareSchema) + err := r.Client.Create(ctx, firmwareSchema) + assert.NoError(t, err) } currentSettings, schema, err := prov.GetFirmwareSettings(true) diff --git a/controllers/metal3.io/metrics.go b/controllers/metal3.io/metrics.go index b926a9796c..3aac50528e 100644 --- a/controllers/metal3.io/metrics.go +++ b/controllers/metal3.io/metrics.go @@ -1,12 +1,10 @@ package controllers import ( + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/prometheus/client_golang/prometheus" - ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/metrics" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" ) const ( diff --git a/controllers/metal3.io/preprovisioningimage_controller.go b/controllers/metal3.io/preprovisioningimage_controller.go index b0801e45f7..1dc3cfd055 100644 --- a/controllers/metal3.io/preprovisioningimage_controller.go +++ b/controllers/metal3.io/preprovisioningimage_controller.go @@ -21,6 +21,10 @@ import ( "time" "github.com/go-logr/logr" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + "github.com/metal3-io/baremetal-operator/pkg/imageprovider" + "github.com/metal3-io/baremetal-operator/pkg/secretutils" + "github.com/metal3-io/baremetal-operator/pkg/utils" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" @@ -32,11 +36,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - "github.com/metal3-io/baremetal-operator/pkg/imageprovider" - "github.com/metal3-io/baremetal-operator/pkg/secretutils" - "github.com/metal3-io/baremetal-operator/pkg/utils" ) const ( diff --git a/main.go b/main.go index 47ce07e478..83ae12585d 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,15 @@ import ( "strconv" "strings" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + metal3iocontroller "github.com/metal3-io/baremetal-operator/controllers/metal3.io" + "github.com/metal3-io/baremetal-operator/pkg/imageprovider" + "github.com/metal3-io/baremetal-operator/pkg/provisioner" + "github.com/metal3-io/baremetal-operator/pkg/provisioner/demo" + "github.com/metal3-io/baremetal-operator/pkg/provisioner/fixture" + "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic" + "github.com/metal3-io/baremetal-operator/pkg/secretutils" + "github.com/metal3-io/baremetal-operator/pkg/version" "github.com/pkg/errors" "go.uber.org/zap/zapcore" k8sruntime "k8s.io/apimachinery/pkg/runtime" @@ -36,17 +45,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - metal3iocontroller "github.com/metal3-io/baremetal-operator/controllers/metal3.io" - "github.com/metal3-io/baremetal-operator/pkg/imageprovider" - "github.com/metal3-io/baremetal-operator/pkg/provisioner" - "github.com/metal3-io/baremetal-operator/pkg/provisioner/demo" - "github.com/metal3-io/baremetal-operator/pkg/provisioner/fixture" - "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic" - "github.com/metal3-io/baremetal-operator/pkg/secretutils" - "github.com/metal3-io/baremetal-operator/pkg/version" - // +kubebuilder:scaffold:imports ) // Constants for TLS versions. diff --git a/main_test.go b/main_test.go index f3a1131112..6e4c65945e 100644 --- a/main_test.go +++ b/main_test.go @@ -40,7 +40,7 @@ func TestTLSInsecureCiperSuite(t *testing.T) { klog.SetOutput(bufWriter) klog.LogToStderr(false) // this is important, because klog by default logs to stderr only _, err := GetTLSOptionOverrideFuncs(tlsMockOptions) - g.Expect(err).Should(BeNil()) + g.Expect(err).ShouldNot(HaveOccurred()) g.Expect(bufWriter.String()).Should(ContainSubstring("use of insecure cipher 'TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256' detected.")) }) } @@ -76,7 +76,7 @@ func Test13CipherSuite(t *testing.T) { klog.LogToStderr(false) // this is important, because klog by default logs to stderr only _, err := GetTLSOptionOverrideFuncs(tlsMockOptions) g.Expect(bufWriter.String()).Should(ContainSubstring("warning: Cipher suites should not be set for TLS version 1.3. Ignoring ciphers")) - g.Expect(err).Should(BeNil()) + g.Expect(err).ShouldNot(HaveOccurred()) }) } @@ -93,7 +93,7 @@ func TestGetTLSVersion(t *testing.T) { tlsVersion := "TLS12" version, err := GetTLSVersion(tlsVersion) g.Expect(version).To(Equal(VersionTLS12)) - g.Expect(err).Should(BeNil()) + g.Expect(err).ShouldNot(HaveOccurred()) }) } @@ -106,6 +106,6 @@ func TestTLSOptions(t *testing.T) { TLSCipherSuites: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", } _, err := GetTLSOptionOverrideFuncs(tlsMockOptions) - g.Expect(err).Should(BeNil()) + g.Expect(err).ShouldNot(HaveOccurred()) }) } diff --git a/pkg/hardwareutils/bmc/ilo4.go b/pkg/hardwareutils/bmc/ilo4.go index 993ee08aa2..a5fe785cc2 100644 --- a/pkg/hardwareutils/bmc/ilo4.go +++ b/pkg/hardwareutils/bmc/ilo4.go @@ -170,5 +170,5 @@ func (a *iLOAccessDetails) BuildBIOSSettings(firmwareConfig *FirmwareConfig) (se ) } - return + return settings, nil } diff --git a/pkg/hardwareutils/bmc/ilo5.go b/pkg/hardwareutils/bmc/ilo5.go index 5bb8de769a..d1d29cd442 100644 --- a/pkg/hardwareutils/bmc/ilo5.go +++ b/pkg/hardwareutils/bmc/ilo5.go @@ -155,5 +155,5 @@ func (a *iLO5AccessDetails) BuildBIOSSettings(firmwareConfig *FirmwareConfig) (s ) } - return + return settings, nil } diff --git a/pkg/hardwareutils/bmc/irmc.go b/pkg/hardwareutils/bmc/irmc.go index a3368d8952..06a9741c59 100644 --- a/pkg/hardwareutils/bmc/irmc.go +++ b/pkg/hardwareutils/bmc/irmc.go @@ -161,5 +161,5 @@ func (a *iRMCAccessDetails) BuildBIOSSettings(firmwareConfig *FirmwareConfig) (s ) } - return + return settings, nil } diff --git a/pkg/imageprovider/default.go b/pkg/imageprovider/default.go index 99b3b7dd9f..4b90e7cedf 100644 --- a/pkg/imageprovider/default.go +++ b/pkg/imageprovider/default.go @@ -5,7 +5,6 @@ import ( "os" "github.com/go-logr/logr" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" ) diff --git a/pkg/imageprovider/imageprovider.go b/pkg/imageprovider/imageprovider.go index 638de1aea4..459fdf2dfe 100644 --- a/pkg/imageprovider/imageprovider.go +++ b/pkg/imageprovider/imageprovider.go @@ -1,11 +1,9 @@ package imageprovider import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/go-logr/logr" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // ImageData contains information about the image type being requested, and diff --git a/pkg/provisioner/demo/demo.go b/pkg/provisioner/demo/demo.go index f6741975d5..94ed0c8230 100644 --- a/pkg/provisioner/demo/demo.go +++ b/pkg/provisioner/demo/demo.go @@ -4,14 +4,12 @@ import ( "context" "time" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/go-logr/logr" - logz "sigs.k8s.io/controller-runtime/pkg/log/zap" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + logz "sigs.k8s.io/controller-runtime/pkg/log/zap" ) var log = logz.New().WithName("provisioner").WithName("demo") @@ -129,7 +127,7 @@ func (p *demoProvisioner) InspectHardware(_ provisioner.InspectData, _, _, _ boo // state in Reconcile() result.Dirty = true result.RequeueAfter = time.Second * 5 - return + return result, started, nil, nil } p.log.Info("continuing inspection by setting details") @@ -178,7 +176,7 @@ func (p *demoProvisioner) InspectHardware(_ provisioner.InspectData, _, _, _ boo } p.publisher("InspectionComplete", "Hardware inspection completed") - return + return result, started, details, nil } // UpdateHardwareState fetches the latest hardware state of the server diff --git a/pkg/provisioner/fixture/fixture.go b/pkg/provisioner/fixture/fixture.go index 8005d07ab4..0e595fd753 100644 --- a/pkg/provisioner/fixture/fixture.go +++ b/pkg/provisioner/fixture/fixture.go @@ -5,11 +5,10 @@ import ( "time" "github.com/go-logr/logr" - logz "sigs.k8s.io/controller-runtime/pkg/log/zap" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner" + logz "sigs.k8s.io/controller-runtime/pkg/log/zap" ) var log = logz.New().WithName("provisioner").WithName("fixture") @@ -178,7 +177,7 @@ func (p *fixtureProvisioner) InspectHardware(_ provisioner.InspectData, _, _, _ } p.publisher("InspectionComplete", "Hardware inspection completed") - return + return result, started, details, nil } // UpdateHardwareState fetches the latest hardware state of the server diff --git a/pkg/provisioner/ironic/adopt_test.go b/pkg/provisioner/ironic/adopt_test.go index 0ea0478f9a..7bff4d770d 100644 --- a/pkg/provisioner/ironic/adopt_test.go +++ b/pkg/provisioner/ironic/adopt_test.go @@ -5,12 +5,11 @@ import ( "time" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/stretchr/testify/assert" - "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" + "github.com/stretchr/testify/assert" ) func TestAdopt(t *testing.T) { diff --git a/pkg/provisioner/ironic/bios_test.go b/pkg/provisioner/ironic/bios_test.go index f13ef7f755..2e28358a9a 100644 --- a/pkg/provisioner/ironic/bios_test.go +++ b/pkg/provisioner/ironic/bios_test.go @@ -3,12 +3,11 @@ package ironic import ( "testing" - "github.com/stretchr/testify/assert" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" + "github.com/stretchr/testify/assert" ) func TestGetFirmwareSettings(t *testing.T) { diff --git a/pkg/provisioner/ironic/capabilities_test.go b/pkg/provisioner/ironic/capabilities_test.go index e46882930e..207542df9d 100644 --- a/pkg/provisioner/ironic/capabilities_test.go +++ b/pkg/provisioner/ironic/capabilities_test.go @@ -4,9 +4,8 @@ import ( "testing" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/stretchr/testify/assert" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + "github.com/stretchr/testify/assert" ) func TestBuildCapabilitiesValue(t *testing.T) { diff --git a/pkg/provisioner/ironic/configdrive_test.go b/pkg/provisioner/ironic/configdrive_test.go index c2b69e8fa3..2f463c5ae6 100644 --- a/pkg/provisioner/ironic/configdrive_test.go +++ b/pkg/provisioner/ironic/configdrive_test.go @@ -4,14 +4,13 @@ import ( "testing" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/stretchr/testify/assert" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner" "github.com/metal3-io/baremetal-operator/pkg/provisioner/fixture" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" + "github.com/stretchr/testify/assert" ) func TestEmpty(t *testing.T) { diff --git a/pkg/provisioner/ironic/delete_test.go b/pkg/provisioner/ironic/delete_test.go index 76d14e0628..3d54b8ed68 100644 --- a/pkg/provisioner/ironic/delete_test.go +++ b/pkg/provisioner/ironic/delete_test.go @@ -6,12 +6,11 @@ import ( "time" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/stretchr/testify/assert" - "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" + "github.com/stretchr/testify/assert" ) type TestFunc func(string) diff --git a/pkg/provisioner/ironic/dependencies.go b/pkg/provisioner/ironic/dependencies.go index 45ad62b957..97cc0d62fa 100644 --- a/pkg/provisioner/ironic/dependencies.go +++ b/pkg/provisioner/ironic/dependencies.go @@ -5,7 +5,6 @@ import ( "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/drivers" "github.com/gophercloud/gophercloud/v2/pagination" - "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" ) @@ -36,7 +35,7 @@ func (p *ironicProvisioner) checkIronicConductor() (ready bool, err error) { } driverCount := 0 - pager.EachPage(p.ctx, func(_ context.Context, page pagination.Page) (bool, error) { + _ = pager.EachPage(p.ctx, func(_ context.Context, page pagination.Page) (bool, error) { actual, driverErr := drivers.ExtractDrivers(page) if driverErr != nil { return false, driverErr @@ -44,6 +43,7 @@ func (p *ironicProvisioner) checkIronicConductor() (ready bool, err error) { driverCount += len(actual) return true, nil }) + // If we have any drivers, conductor is up. ready = driverCount > 0 diff --git a/pkg/provisioner/ironic/devicehints/devicehints_test.go b/pkg/provisioner/ironic/devicehints/devicehints_test.go index 974408eecb..3434595238 100644 --- a/pkg/provisioner/ironic/devicehints/devicehints_test.go +++ b/pkg/provisioner/ironic/devicehints/devicehints_test.go @@ -3,9 +3,8 @@ package devicehints import ( "testing" - "github.com/stretchr/testify/assert" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + "github.com/stretchr/testify/assert" ) func TestMakeHintMap(t *testing.T) { diff --git a/pkg/provisioner/ironic/factory.go b/pkg/provisioner/ironic/factory.go index 65c6e4ad45..19571eb05e 100644 --- a/pkg/provisioner/ironic/factory.go +++ b/pkg/provisioner/ironic/factory.go @@ -11,7 +11,6 @@ import ( "github.com/go-logr/logr" "github.com/gophercloud/gophercloud/v2" - "github.com/metal3-io/baremetal-operator/pkg/provisioner" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" ) diff --git a/pkg/provisioner/ironic/findhost_test.go b/pkg/provisioner/ironic/findhost_test.go index 01053891e4..16c8c4d369 100644 --- a/pkg/provisioner/ironic/findhost_test.go +++ b/pkg/provisioner/ironic/findhost_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" diff --git a/pkg/provisioner/ironic/hardwaredetails/hardwaredetails.go b/pkg/provisioner/ironic/hardwaredetails/hardwaredetails.go index 0445ee51da..e969603b42 100644 --- a/pkg/provisioner/ironic/hardwaredetails/hardwaredetails.go +++ b/pkg/provisioner/ironic/hardwaredetails/hardwaredetails.go @@ -10,7 +10,6 @@ import ( "github.com/gophercloud/gophercloud/v2/openstack/baremetal/inventory" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" "github.com/gophercloud/gophercloud/v2/openstack/baremetalintrospection/v1/introspection" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" ) diff --git a/pkg/provisioner/ironic/hardwaredetails/hardwaredetails_test.go b/pkg/provisioner/ironic/hardwaredetails/hardwaredetails_test.go index f78e55325e..ba31d4eb71 100644 --- a/pkg/provisioner/ironic/hardwaredetails/hardwaredetails_test.go +++ b/pkg/provisioner/ironic/hardwaredetails/hardwaredetails_test.go @@ -6,9 +6,8 @@ import ( "github.com/gophercloud/gophercloud/v2/openstack/baremetal/inventory" "github.com/gophercloud/gophercloud/v2/openstack/baremetalintrospection/v1/introspection" - "github.com/stretchr/testify/assert" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + "github.com/stretchr/testify/assert" ) func TestGetVLANs(t *testing.T) { diff --git a/pkg/provisioner/ironic/inspecthardware_test.go b/pkg/provisioner/ironic/inspecthardware_test.go index 32d4bd0a2f..178554069f 100644 --- a/pkg/provisioner/ironic/inspecthardware_test.go +++ b/pkg/provisioner/ironic/inspecthardware_test.go @@ -7,13 +7,12 @@ import ( "github.com/gophercloud/gophercloud/v2/openstack/baremetal/inventory" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/stretchr/testify/assert" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" + "github.com/stretchr/testify/assert" ) func TestInspectHardware(t *testing.T) { diff --git a/pkg/provisioner/ironic/ironic.go b/pkg/provisioner/ironic/ironic.go index 5fe505e837..b0a27b5fc6 100644 --- a/pkg/provisioner/ironic/ironic.go +++ b/pkg/provisioner/ironic/ironic.go @@ -11,23 +11,20 @@ import ( "time" "github.com/go-logr/logr" - "github.com/pkg/errors" - "github.com/gophercloud/gophercloud/v2" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/drivers" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/ports" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/intstr" - "sigs.k8s.io/yaml" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/devicehints" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/hardwaredetails" + "github.com/pkg/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" + "sigs.k8s.io/yaml" ) var ( @@ -239,7 +236,7 @@ func (p *ironicProvisioner) findExistingHost(bootMACAddress string) (ironicNode // Try to load the node by UUID ironicNode, err = p.getNode() if !errors.Is(err, provisioner.ErrNeedsRegistration) { - return + return ironicNode, err } // Try to load the node by name @@ -270,7 +267,7 @@ func (p *ironicProvisioner) findExistingHost(bootMACAddress string) (ironicNode if err != nil { p.log.Info("failed to find an existing port with address", "MAC", bootMACAddress) - return nil, nil + return nil, nil //nolint:nilerr } if len(allPorts) > 0 { @@ -345,7 +342,7 @@ func (p *ironicProvisioner) ValidateManagementAccess(data provisioner.Management bmcAccess, err := p.bmcAccess() if err != nil { result, err = operationFailed(err.Error()) - return + return result, "", err } var ironicNode *nodes.Node @@ -361,7 +358,7 @@ func (p *ironicProvisioner) ValidateManagementAccess(data provisioner.Management default: result, err = transientError(errors.Wrap(err, "failed to find existing host")) } - return + return result, "", err } // Some BMC types require a MAC address, so ensure we have one @@ -370,7 +367,7 @@ func (p *ironicProvisioner) ValidateManagementAccess(data provisioner.Management msg := fmt.Sprintf("BMC driver %s requires a BootMACAddress value", bmcAccess.Type()) p.log.Info(msg) result, err = operationFailed(msg) - return + return result, "", err } driverInfo := bmcAccess.DriverInfo(p.bmcCreds) @@ -384,13 +381,13 @@ func (p *ironicProvisioner) ValidateManagementAccess(data provisioner.Management msg := fmt.Sprintf("BMC driver %s does not support secure boot", bmcAccess.Type()) p.log.Info(msg) result, err = operationFailed(msg) - return + return result, "", err } inspectInterface, driverErr := p.getInspectInterface(bmcAccess) if driverErr != nil { result, err = transientError(driverErr) - return + return result, "", err } nodeCreateOpts := nodes.CreateOpts{ @@ -421,10 +418,10 @@ func (p *ironicProvisioner) ValidateManagementAccess(data provisioner.Management case gophercloud.ErrDefault409: p.log.Info("could not register host in ironic, busy") result, err = retryAfterDelay(provisionRequeueDelay) - return + return result, "", err default: result, err = transientError(errors.Wrap(err, "failed to register host in ironic")) - return + return result, "", err } // Store the ID so other methods can assume it is set and so @@ -437,7 +434,7 @@ func (p *ironicProvisioner) ValidateManagementAccess(data provisioner.Management err = p.createPXEEnabledNodePort(ironicNode.UUID, p.bootMACAddress) if err != nil { result, err = transientError(err) - return + return result, provID, err } } } else { @@ -477,21 +474,21 @@ func (p *ironicProvisioner) ValidateManagementAccess(data provisioner.Management nodeHasAssignedPort, err = p.nodeHasAssignedPort(ironicNode) if err != nil { result, err = transientError(err) - return + return result, provID, err } if !nodeHasAssignedPort { addressIsAllocatedToPort, err = p.isAddressAllocatedToPort(p.bootMACAddress) if err != nil { result, err = transientError(err) - return + return result, provID, err } if !addressIsAllocatedToPort { err = p.createPXEEnabledNodePort(ironicNode.UUID, p.bootMACAddress) if err != nil { result, err = transientError(err) - return + return result, provID, err } } } @@ -520,7 +517,7 @@ func (p *ironicProvisioner) ValidateManagementAccess(data provisioner.Management if yamlErr := yaml.Unmarshal([]byte(networkDataRaw), &networkData); yamlErr != nil { p.log.Info("failed to unmarshal networkData from PreprovisioningNetworkData") result, err = transientError(fmt.Errorf("invalid preprovisioningNetworkData: %w", yamlErr)) - return + return result, provID, err } numUpdates := len(updater.Updates) updater.SetTopLevelOpt("network_data", networkData, ironicNode.NetworkData) @@ -532,7 +529,7 @@ func (p *ironicProvisioner) ValidateManagementAccess(data provisioner.Management ironicNode, success, result, err := p.tryUpdateNode(ironicNode, updater) if !success { - return + return result, provID, err } p.log.Info("current provision state", @@ -548,28 +545,28 @@ func (p *ironicProvisioner) ValidateManagementAccess(data provisioner.Management // If ironic is reporting an error, stop working on the node. if ironicNode.LastError != "" && !(credentialsChanged || restartOnFailure) { result, err = operationFailed(ironicNode.LastError) - return + return result, provID, err } if ironicNode.TargetProvisionState == string(nodes.TargetManage) { // We have already tried to manage the node and did not // get an error, so do nothing and keep trying. result, err = operationContinuing(provisionRequeueDelay) - return + return result, provID, err } result, err = p.changeNodeProvisionState( ironicNode, nodes.ProvisionStateOpts{Target: nodes.TargetManage}, ) - return + return result, provID, err case nodes.Verifying: // If we're still waiting for the state to change in Ironic, // return true to indicate that we're dirty and need to be // reconciled again. result, err = operationContinuing(provisionRequeueDelay) - return + return result, provID, err case nodes.CleanWait, nodes.Cleaning, @@ -578,7 +575,7 @@ func (p *ironicProvisioner) ValidateManagementAccess(data provisioner.Management nodes.Inspecting: // Do not try to update the node if it's in a transient state other than InspectWait - will fail anyway. result, err = operationComplete() - return + return result, provID, err case nodes.Active: // The host is already running, maybe it's a controlplane host? @@ -587,7 +584,7 @@ func (p *ironicProvisioner) ValidateManagementAccess(data provisioner.Management default: result, err = p.configureImages(data, ironicNode, bmcAccess) - return + return result, provID, err } } @@ -607,10 +604,13 @@ func (p *ironicProvisioner) configureImages(data provisioner.ManagementAccessDat _, success, result, err := p.tryUpdateNode(ironicNode, updater) if !success { - return + return result, err } result, err = operationComplete() + if err != nil { + return result, err + } switch data.State { case metal3api.StateProvisioning, @@ -618,12 +618,12 @@ func (p *ironicProvisioner) configureImages(data provisioner.ManagementAccessDat if data.State == metal3api.StateProvisioning { if data.CurrentImage.IsLiveISO() { // Live ISO doesn't need pre-provisioning image - return + return result, nil } } else { if data.AutomatedCleaningMode == metal3api.CleaningModeDisabled { // No need for pre-provisioning image if cleaning disabled - return + return result, nil } } fallthrough @@ -635,11 +635,11 @@ func (p *ironicProvisioner) configureImages(data provisioner.ManagementAccessDat } else { result, err = operationFailed("no preprovisioning image available") } - return + return result, err } } - return + return result, nil } // PreprovisioningImageFormats returns a list of acceptable formats for a @@ -788,12 +788,12 @@ func (p *ironicProvisioner) tryChangeNodeProvisionState(ironicNode *nodes.Node, if ironicNode.Fault != "" { p.log.Info("node has a fault, will retry", "fault", ironicNode.Fault, "reason", ironicNode.MaintenanceReason) result, err = retryAfterDelay(provisionRequeueDelay) - return + return success, result, err } if ironicNode.Maintenance { p.log.Info("trying to change a provision state for a node in maintenance, removing maintenance first", "reason", ironicNode.MaintenanceReason) result, err = p.setMaintenanceFlag(ironicNode, false, "") - return + return success, result, err } changeResult := nodes.ChangeProvisionState(p.ctx, p.client, ironicNode.UUID, opts) @@ -803,15 +803,15 @@ func (p *ironicProvisioner) tryChangeNodeProvisionState(ironicNode *nodes.Node, case gophercloud.ErrDefault409: p.log.Info("could not change state of host, busy") result, err = retryAfterDelay(provisionRequeueDelay) - return + return success, result, err default: result, err = transientError(errors.Wrap(changeResult.Err, fmt.Sprintf("failed to change provisioning state to %q", opts.Target))) - return + return success, result, err } result, err = operationContinuing(provisionRequeueDelay) - return + return success, result, err } func (p *ironicProvisioner) changeNodeProvisionState(ironicNode *nodes.Node, opts nodes.ProvisionStateOpts) (result provisioner.Result, err error) { @@ -862,7 +862,7 @@ func (p *ironicProvisioner) InspectHardware(data provisioner.InspectData, restar ironicNode, err := p.getNode() if err != nil { result, err = transientError(err) - return + return result, started, details, err } if ironicNode.ProvisionState == string(nodes.InspectFail) && strings.Contains(ironicNode.LastError, "aborted") { @@ -877,7 +877,7 @@ func (p *ironicProvisioner) InspectHardware(data provisioner.InspectData, restar ironicNode, nodes.ProvisionStateOpts{Target: nodes.TargetManage}, ) - return + return result, started, details, err case nodes.InspectWait: if forceReboot { return p.abortInspection(ironicNode) @@ -887,7 +887,7 @@ func (p *ironicProvisioner) InspectHardware(data provisioner.InspectData, restar case nodes.Inspecting: p.log.Info("inspection in progress") result, err = operationContinuing(introspectionRequeueDelay) - return + return result, started, details, err case nodes.InspectFail: if !restartOnFailure { failure := ironicNode.LastError @@ -896,20 +896,20 @@ func (p *ironicProvisioner) InspectHardware(data provisioner.InspectData, restar } p.log.Info("inspection failed", "error", failure) result, err = operationFailed(failure) - return + return result, started, details, err } refresh = true fallthrough case nodes.Manageable: if refresh { result, started, err = p.startInspection(data, ironicNode) - return + return result, started, details, err } default: p.log.Info("unexpected provisioning state for inspection", "provisionState", ironicNode.ProvisionState, "targetProvisionState", ironicNode.TargetProvisionState, "lastError", ironicNode.LastError) result, err = transientError(errors.Errorf("unexpected provision state %s", ironicNode.ProvisionState)) - return + return result, started, details, err } p.log.Info("getting hardware details from inspection") @@ -919,10 +919,10 @@ func (p *ironicProvisioner) InspectHardware(data provisioner.InspectData, restar if _, isNotFound := err.(gophercloud.ErrDefault404); isNotFound { // The node has just been enrolled, inspection hasn't been started yet. result, started, err = p.startInspection(data, ironicNode) - return + return result, started, details, err } result, err = transientError(errors.Wrap(err, "failed to retrieve hardware introspection data")) - return + return result, started, details, err } // Introspection is done @@ -931,7 +931,7 @@ func (p *ironicProvisioner) InspectHardware(data provisioner.InspectData, restar details = hardwaredetails.GetHardwareDetails(introData, p.log) p.publisher("InspectionComplete", "Hardware inspection completed") result, err = operationComplete() - return + return result, started, details, err } // UpdateHardwareState fetches the latest hardware state of the server @@ -1189,7 +1189,7 @@ func (p *ironicProvisioner) setUpForProvisioning(ironicNode *nodes.Node, data pr ironicNode, success, result, err := p.tryUpdateNode(ironicNode, p.getUpdateOptsForNode(ironicNode, data)) if !success { - return + return result, err } p.log.Info("validating host settings") @@ -1217,7 +1217,7 @@ func (p *ironicProvisioner) setUpForProvisioning(ironicNode *nodes.Node, data pr ) p.publisher("ProvisioningStarted", fmt.Sprintf("Image provisioning started for %s", data.Image.URL)) - return + return result, nil } func (p *ironicProvisioner) deployInterface(data provisioner.ManagementAccessData) (result string) { @@ -1389,7 +1389,7 @@ func (p *ironicProvisioner) buildManualCleaningSteps(bmcAccess bmc.AccessDetails // TODO: Add manual cleaning steps for host configuration - return + return cleanSteps, nil } func buildFirmwareSettings(settings []map[string]interface{}, name string, value intstr.IntOrString) []map[string]interface{} { @@ -1444,13 +1444,13 @@ func (p *ironicProvisioner) Prepare(data provisioner.PrepareData, unprepared boo bmcAccess, err := p.bmcAccess() if err != nil { result, err = transientError(err) - return + return result, started, err } ironicNode, err := p.getNode() if err != nil { result, err = transientError(err) - return + return result, started, err } switch nodes.ProvisionState(ironicNode.ProvisionState) { @@ -1460,7 +1460,7 @@ func (p *ironicProvisioner) Prepare(data provisioner.PrepareData, unprepared boo cleanSteps, err = p.buildManualCleaningSteps(bmcAccess, data) if err != nil { result, err = operationFailed(err.Error()) - return + return result, started, err } if len(cleanSteps) != 0 { p.log.Info("the node needs to be reconfigured", "clean steps", cleanSteps) @@ -1468,7 +1468,7 @@ func (p *ironicProvisioner) Prepare(data provisioner.PrepareData, unprepared boo ironicNode, nodes.ProvisionStateOpts{Target: nodes.TargetManage}, ) - return + return result, started, err } // nothing to do started = true @@ -1481,7 +1481,7 @@ func (p *ironicProvisioner) Prepare(data provisioner.PrepareData, unprepared boo if unprepared { started, result, err = p.startManualCleaning(bmcAccess, ironicNode, data) if started || result.Dirty || result.ErrorMessage != "" || err != nil { - return + return result, started, err } // nothing to do started = true @@ -1495,12 +1495,12 @@ func (p *ironicProvisioner) Prepare(data provisioner.PrepareData, unprepared boo // So we can't set the node's state to manageable, until the settings are cleared. if !restartOnFailure { result, err = operationFailed(ironicNode.LastError) - return + return result, started, err } if ironicNode.Maintenance { p.log.Info("clearing maintenance flag") result, err = p.setMaintenanceFlag(ironicNode, false, "") - return + return result, started, err } result, err = p.changeNodeProvisionState( ironicNode, @@ -1516,7 +1516,7 @@ func (p *ironicProvisioner) Prepare(data provisioner.PrepareData, unprepared boo default: result, err = transientError(fmt.Errorf("have unexpected ironic node state %s", ironicNode.ProvisionState)) } - return + return result, started, err } func (p *ironicProvisioner) getConfigDrive(data provisioner.ProvisionData) (configDrive nodes.ConfigDrive, err error) { @@ -1526,7 +1526,7 @@ func (p *ironicProvisioner) getConfigDrive(data provisioner.ProvisionData) (conf // try it. if data.Image.IsLiveISO() { p.log.Info("not providing config drive for live ISO") - return + return configDrive, nil } // Retrieve instance specific user data (cloud-init, ignition, etc). @@ -1570,7 +1570,7 @@ func (p *ironicProvisioner) getConfigDrive(data provisioner.ProvisionData) (conf } } - return + return configDrive, nil } func (p *ironicProvisioner) getCustomDeploySteps(customDeploy *metal3api.CustomDeploy) (deploySteps []nodes.DeployStep) { @@ -1688,7 +1688,7 @@ func (p *ironicProvisioner) Provision(data provisioner.ProvisionData, forceReboo ironicNode, nodes.ProvisionStateOpts{Target: nodes.TargetDeleted}, ) - return + return result, err } fallthrough diff --git a/pkg/provisioner/ironic/ironic_test.go b/pkg/provisioner/ironic/ironic_test.go index d0e56d5fc1..b6c1afb214 100644 --- a/pkg/provisioner/ironic/ironic_test.go +++ b/pkg/provisioner/ironic/ironic_test.go @@ -4,11 +4,6 @@ import ( "context" "testing" - "github.com/stretchr/testify/assert" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - logf "sigs.k8s.io/controller-runtime/pkg/log" - logz "sigs.k8s.io/controller-runtime/pkg/log/zap" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner" @@ -18,6 +13,10 @@ import ( // so it registers its test fixture with the other BMC access // types. _ "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testbmc" + "github.com/stretchr/testify/assert" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + logf "sigs.k8s.io/controller-runtime/pkg/log" + logz "sigs.k8s.io/controller-runtime/pkg/log/zap" ) func init() { diff --git a/pkg/provisioner/ironic/power_test.go b/pkg/provisioner/ironic/power_test.go index 518e35cf17..b360cfad9b 100644 --- a/pkg/provisioner/ironic/power_test.go +++ b/pkg/provisioner/ironic/power_test.go @@ -7,12 +7,11 @@ import ( "time" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/stretchr/testify/assert" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" + "github.com/stretchr/testify/assert" ) func TestPowerOn(t *testing.T) { diff --git a/pkg/provisioner/ironic/prepare_test.go b/pkg/provisioner/ironic/prepare_test.go index b54928230e..f30377486b 100644 --- a/pkg/provisioner/ironic/prepare_test.go +++ b/pkg/provisioner/ironic/prepare_test.go @@ -6,13 +6,12 @@ import ( "time" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/stretchr/testify/assert" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" + "github.com/stretchr/testify/assert" ) type RAIDTestBMC struct{} diff --git a/pkg/provisioner/ironic/provision_test.go b/pkg/provisioner/ironic/provision_test.go index cbb3928962..ccc242f29b 100644 --- a/pkg/provisioner/ironic/provision_test.go +++ b/pkg/provisioner/ironic/provision_test.go @@ -6,9 +6,6 @@ import ( "time" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/stretchr/testify/assert" - "k8s.io/apimachinery/pkg/util/intstr" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner" @@ -16,6 +13,8 @@ import ( "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testbmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" + "github.com/stretchr/testify/assert" + "k8s.io/apimachinery/pkg/util/intstr" ) func TestProvision(t *testing.T) { diff --git a/pkg/provisioner/ironic/provisioncapacity_test.go b/pkg/provisioner/ironic/provisioncapacity_test.go index e0882e2f99..cbc65187fc 100644 --- a/pkg/provisioner/ironic/provisioncapacity_test.go +++ b/pkg/provisioner/ironic/provisioncapacity_test.go @@ -5,11 +5,10 @@ import ( "testing" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/stretchr/testify/assert" - "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" + "github.com/stretchr/testify/assert" ) func TestHasCapacity(t *testing.T) { diff --git a/pkg/provisioner/ironic/raid.go b/pkg/provisioner/ironic/raid.go index 9e56ba63ee..67476f7616 100644 --- a/pkg/provisioner/ironic/raid.go +++ b/pkg/provisioner/ironic/raid.go @@ -5,11 +5,10 @@ import ( "reflect" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/pkg/errors" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/provisioner" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/devicehints" + "github.com/pkg/errors" ) const ( @@ -95,7 +94,7 @@ func buildTargetHardwareRAIDCfg(volumes []metal3api.HardwareRAIDVolume) (logical ) if len(volumes) == 0 { - return + return nil, nil } for index, volume := range volumes { @@ -149,7 +148,7 @@ func buildTargetHardwareRAIDCfg(volumes []metal3api.HardwareRAIDVolume) (logical logicalDisks = append(logicalDisks, logicalDisk) } - return + return logicalDisks, nil } // A private method to build software RAID disks. @@ -199,10 +198,10 @@ func BuildRAIDCleanSteps(raidInterface string, target *metal3api.RAIDConfig, act actual.HardwareRAIDVolumes = nil } if reflect.DeepEqual(target, actual) { - return + return cleanSteps, nil } if len(target.SoftwareRAIDVolumes) == 0 && (actual == nil || len(actual.SoftwareRAIDVolumes) == 0) { - return + return cleanSteps, nil } cleanSteps = append( @@ -221,7 +220,7 @@ func BuildRAIDCleanSteps(raidInterface string, target *metal3api.RAIDConfig, act // If software raid configuration is empty, only need to clear old configuration if len(target.SoftwareRAIDVolumes) == 0 { - return + return cleanSteps, nil } cleanSteps = append( @@ -231,14 +230,14 @@ func BuildRAIDCleanSteps(raidInterface string, target *metal3api.RAIDConfig, act Step: "create_configuration", }, ) - return + return cleanSteps, nil } // Hardware RAID // If hardware RAID configuration is nil, // keep old hardware RAID configuration if raidInterface == noRAIDInterface || target == nil || target.HardwareRAIDVolumes == nil { - return + return cleanSteps, nil } // Ignore SoftwareRAIDVolumes @@ -247,7 +246,7 @@ func BuildRAIDCleanSteps(raidInterface string, target *metal3api.RAIDConfig, act actual.SoftwareRAIDVolumes = nil } if reflect.DeepEqual(target, actual) { - return + return cleanSteps, nil } // Add ‘delete_configuration’ before ‘create_configuration’ to make sure @@ -262,7 +261,7 @@ func BuildRAIDCleanSteps(raidInterface string, target *metal3api.RAIDConfig, act // If hardware raid configuration is empty, only need to clear old configuration if len(target.HardwareRAIDVolumes) == 0 { - return + return cleanSteps, nil } // ‘create_configuration’ doesn’t remove existing disks. It is recommended @@ -274,7 +273,7 @@ func BuildRAIDCleanSteps(raidInterface string, target *metal3api.RAIDConfig, act Step: "create_configuration", }, ) - return + return cleanSteps, nil } // CheckRAIDInterface checks the current RAID interface against the requested configuration. diff --git a/pkg/provisioner/ironic/raid_test.go b/pkg/provisioner/ironic/raid_test.go index da8d09b581..6900fef974 100644 --- a/pkg/provisioner/ironic/raid_test.go +++ b/pkg/provisioner/ironic/raid_test.go @@ -6,9 +6,8 @@ import ( "testing" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/stretchr/testify/assert" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + "github.com/stretchr/testify/assert" ) func TestBuildTargetRAIDCfg(t *testing.T) { diff --git a/pkg/provisioner/ironic/ready_test.go b/pkg/provisioner/ironic/ready_test.go index 4ddbc5018a..03791c667e 100644 --- a/pkg/provisioner/ironic/ready_test.go +++ b/pkg/provisioner/ironic/ready_test.go @@ -4,11 +4,10 @@ import ( "net/http" "testing" - "github.com/stretchr/testify/assert" - "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" + "github.com/stretchr/testify/assert" ) func TestProvisionerIsReady(t *testing.T) { diff --git a/pkg/provisioner/ironic/testbmc/testbmc.go b/pkg/provisioner/ironic/testbmc/testbmc.go index ac5449b925..76dacf7fe5 100644 --- a/pkg/provisioner/ironic/testbmc/testbmc.go +++ b/pkg/provisioner/ironic/testbmc/testbmc.go @@ -152,5 +152,5 @@ func (a *testAccessDetails) BuildBIOSSettings(firmwareConfig *bmc.FirmwareConfig ) } - return + return settings, nil } diff --git a/pkg/provisioner/ironic/testserver/ironic.go b/pkg/provisioner/ironic/testserver/ironic.go index be42cd54f5..a85351bda1 100644 --- a/pkg/provisioner/ironic/testserver/ironic.go +++ b/pkg/provisioner/ironic/testserver/ironic.go @@ -133,7 +133,7 @@ func (m *IronicMock) Node(node nodes.Node) *IronicMock { return m } -// NodeUpdateError configures configures the server with an error response for [PATCH] /v1/nodes/{id}. +// NodeUpdateError configures the server with an error response for [PATCH] /v1/nodes/{id}. func (m *IronicMock) NodeUpdateError(id string, errorCode int) *IronicMock { m.ResponseWithCode(m.buildURL(v1node+id, http.MethodPatch), "", errorCode) return m @@ -154,7 +154,7 @@ func (m *IronicMock) NodeUpdate(node nodes.Node) *IronicMock { // GetLastNodeUpdateRequestFor returns the content of the last update request for the specified node. func (m *IronicMock) GetLastNodeUpdateRequestFor(id string) (updates []nodes.UpdateOperation) { if bodyRaw, ok := m.GetLastRequestFor(v1node+id, http.MethodPatch); ok { - json.Unmarshal([]byte(bodyRaw), &updates) + _ = json.Unmarshal([]byte(bodyRaw), &updates) } return @@ -163,13 +163,13 @@ func (m *IronicMock) GetLastNodeUpdateRequestFor(id string) (updates []nodes.Upd // GetLastNodeStatesProvisionUpdateRequestFor returns the content of the last provisioning request for the specified node. func (m *IronicMock) GetLastNodeStatesProvisionUpdateRequestFor(id string) (update nodes.ProvisionStateOpts) { if bodyRaw, ok := m.GetLastRequestFor(v1node+id+"/states/provision", http.MethodPut); ok { - json.Unmarshal([]byte(bodyRaw), &update) + _ = json.Unmarshal([]byte(bodyRaw), &update) } return } -// NodeMaintenanceError configures configures the server with an error response for [PUT] /v1/nodes/{id}/maintenance. +// NodeMaintenanceError configures the server with an error response for [PUT] /v1/nodes/{id}/maintenance. func (m *IronicMock) NodeMaintenanceError(id string, errorCode int) *IronicMock { m.ResponseWithCode(m.buildURL(v1node+id+maintenance, http.MethodPut), "", errorCode) return m diff --git a/pkg/provisioner/ironic/update_opts.go b/pkg/provisioner/ironic/update_opts.go index 39c1cb2f88..cdb14d80f1 100644 --- a/pkg/provisioner/ironic/update_opts.go +++ b/pkg/provisioner/ironic/update_opts.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/go-logr/logr" - "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" ) diff --git a/pkg/provisioner/ironic/updatehardwarestate_test.go b/pkg/provisioner/ironic/updatehardwarestate_test.go index b3c0e03d89..09432b1f35 100644 --- a/pkg/provisioner/ironic/updatehardwarestate_test.go +++ b/pkg/provisioner/ironic/updatehardwarestate_test.go @@ -5,11 +5,10 @@ import ( "testing" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - "github.com/stretchr/testify/assert" - "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" + "github.com/stretchr/testify/assert" ) func TestUpdateHardwareState(t *testing.T) { diff --git a/pkg/provisioner/ironic/updateopts_test.go b/pkg/provisioner/ironic/updateopts_test.go index b3f8828e00..a2a92dee9f 100644 --- a/pkg/provisioner/ironic/updateopts_test.go +++ b/pkg/provisioner/ironic/updateopts_test.go @@ -5,19 +5,17 @@ import ( "testing" "github.com/go-logr/logr" - "github.com/pkg/errors" - "github.com/stretchr/testify/assert" - "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" - logf "sigs.k8s.io/controller-runtime/pkg/log" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1/profile" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/provisioner" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/pointer" + logf "sigs.k8s.io/controller-runtime/pkg/log" ) func TestOptionValueEqual(t *testing.T) { diff --git a/pkg/provisioner/ironic/validatemanagementaccess_test.go b/pkg/provisioner/ironic/validatemanagementaccess_test.go index 4121808d7f..4de75aae23 100644 --- a/pkg/provisioner/ironic/validatemanagementaccess_test.go +++ b/pkg/provisioner/ironic/validatemanagementaccess_test.go @@ -7,14 +7,13 @@ import ( "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/nodes" "github.com/gophercloud/gophercloud/v2/openstack/baremetal/v1/ports" - "github.com/stretchr/testify/assert" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/imageprovider" "github.com/metal3-io/baremetal-operator/pkg/provisioner" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients" "github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/testserver" + "github.com/stretchr/testify/assert" ) func TestValidateManagementAccessNoMAC(t *testing.T) { diff --git a/pkg/provisioner/provisioner.go b/pkg/provisioner/provisioner.go index 29a15d54c1..bcf537bb25 100644 --- a/pkg/provisioner/provisioner.go +++ b/pkg/provisioner/provisioner.go @@ -5,12 +5,11 @@ import ( "errors" "time" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1/profile" "github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc" "github.com/metal3-io/baremetal-operator/pkg/imageprovider" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) /* diff --git a/pkg/secretutils/secret_manager.go b/pkg/secretutils/secret_manager.go index f2bbc164a3..96d16af7bd 100644 --- a/pkg/secretutils/secret_manager.go +++ b/pkg/secretutils/secret_manager.go @@ -5,6 +5,8 @@ import ( "fmt" "github.com/go-logr/logr" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + "github.com/metal3-io/baremetal-operator/pkg/utils" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -12,9 +14,6 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - "github.com/metal3-io/baremetal-operator/pkg/utils" ) const ( diff --git a/test/e2e/basic_ops_test.go b/test/e2e/basic_ops_test.go index 2844c440b8..020d4b16f7 100644 --- a/test/e2e/basic_ops_test.go +++ b/test/e2e/basic_ops_test.go @@ -4,6 +4,8 @@ import ( "context" "fmt" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -11,10 +13,6 @@ import ( "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/cluster-api/util" - - capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" ) var _ = Describe("basic", Label("required", "basic"), func() { diff --git a/test/e2e/cert_manager.go b/test/e2e/cert_manager.go index 53ed547e47..38149c8f15 100644 --- a/test/e2e/cert_manager.go +++ b/test/e2e/cert_manager.go @@ -6,14 +6,12 @@ import ( "io" "net/http" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "sigs.k8s.io/cluster-api/test/framework" - "sigs.k8s.io/controller-runtime/pkg/client" - cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1" "github.com/pkg/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/cluster-api/test/framework" + "sigs.k8s.io/controller-runtime/pkg/client" ) func checkCertManagerAPI(clusterProxy framework.ClusterProxy) error { @@ -24,7 +22,7 @@ func checkCertManagerAPI(clusterProxy framework.ClusterProxy) error { } func installCertManager(ctx context.Context, clusterProxy framework.ClusterProxy, cmVersion string) error { - response, err := http.Get(fmt.Sprintf("https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml", cmVersion)) + response, err := http.Get(fmt.Sprintf("https://github.com/cert-manager/cert-manager/releases/download/%s/cert-manager.yaml", cmVersion)) //nolint: noctx if err != nil { return errors.Wrapf(err, "Error downloading cert-manager manifest") } @@ -46,7 +44,11 @@ func installCertManager(ctx context.Context, clusterProxy framework.ClusterProxy func checkCertManagerWebhook(ctx context.Context, clusterProxy framework.ClusterProxy) error { scheme := clusterProxy.GetScheme() const ns = "cert-manager" - cmapi.AddToScheme(scheme) + err := cmapi.AddToScheme(scheme) + if err != nil { + return err + } + cl, err := client.New(clusterProxy.GetRESTConfig(), client.Options{ Scheme: scheme, }) diff --git a/test/e2e/common.go b/test/e2e/common.go index ba76442bf6..0ed04f5388 100644 --- a/test/e2e/common.go +++ b/test/e2e/common.go @@ -7,25 +7,18 @@ import ( "os" "strings" - "golang.org/x/crypto/ssh" - - "github.com/pkg/errors" - + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e" . "github.com/onsi/gomega" - + "github.com/pkg/errors" + "golang.org/x/crypto/ssh" v1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - testexec "sigs.k8s.io/cluster-api/test/framework/exec" - - capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e" - "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/cluster-api/test/framework" - + testexec "sigs.k8s.io/cluster-api/test/framework/exec" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/kustomize/api/krusty" "sigs.k8s.io/kustomize/kyaml/filesys" @@ -337,7 +330,7 @@ func (input *BuildAndApplyKustomizationInput) validate() error { // BuildAndApplyKustomization takes input from BuildAndApplyKustomizationInput. It builds the provided kustomization // and apply it to the cluster provided by clusterProxy. func BuildAndApplyKustomization(ctx context.Context, input *BuildAndApplyKustomizationInput) error { - Expect(input.validate()).To(BeNil()) + Expect(input.validate()).To(Succeed()) var err error kustomization := input.Kustomization clusterProxy := input.ClusterProxy @@ -386,7 +379,7 @@ func BuildAndApplyKustomization(ctx context.Context, input *BuildAndApplyKustomi func DeploymentRolledOut(ctx context.Context, clusterProxy framework.ClusterProxy, name string, namespace string, desiredGeneration int64) bool { clientSet := clusterProxy.GetClientSet() deploy, err := clientSet.AppsV1().Deployments(namespace).Get(ctx, name, metav1.GetOptions{}) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) if deploy != nil { // When the number of replicas is equal to the number of available and updated // replicas, we know that only "new" pods are running. When we also diff --git a/test/e2e/e2e_config.go b/test/e2e/e2e_config.go index 7483a13818..ea0e8a1861 100644 --- a/test/e2e/e2e_config.go +++ b/test/e2e/e2e_config.go @@ -2,19 +2,15 @@ package e2e import ( "fmt" + "os" + "runtime" + "strings" + "time" . "github.com/onsi/gomega" - "github.com/pkg/errors" "gopkg.in/yaml.v2" - - "os" - "runtime" - "sigs.k8s.io/cluster-api/test/framework/clusterctl" - - "strings" - "time" ) // LoadImageBehavior indicates the behavior when loading an image. diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index fd8d163e10..7c10cbd4b8 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -8,6 +8,7 @@ import ( "strings" "testing" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/runtime" @@ -15,8 +16,6 @@ import ( "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/cluster-api/test/framework/bootstrap" ctrl "sigs.k8s.io/controller-runtime" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" ) var ( @@ -168,8 +167,8 @@ var _ = SynchronizedBeforeSuite(func() []byte { kubeconfigPath := parts[0] scheme := runtime.NewScheme() framework.TryAddDefaultSchemes(scheme) - metal3api.AddToScheme(scheme) - + err := metal3api.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) e2eConfig = LoadE2EConfig(configPath) bmcs = LoadBMCConfig(bmcConfigPath) bmc = (*bmcs)[GinkgoParallelProcess()-1] diff --git a/test/e2e/external_inspection_test.go b/test/e2e/external_inspection_test.go index a576b60f95..1acb1448c2 100644 --- a/test/e2e/external_inspection_test.go +++ b/test/e2e/external_inspection_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -12,8 +13,6 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/cluster-api/util" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" ) const hardwareDetails = ` diff --git a/test/e2e/inspection_test.go b/test/e2e/inspection_test.go index 1417451567..0303beec47 100644 --- a/test/e2e/inspection_test.go +++ b/test/e2e/inspection_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -11,8 +12,6 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/cluster-api/util" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" ) var _ = Describe("Inspection", Label("required", "inspection"), func() { diff --git a/test/e2e/live_iso_test.go b/test/e2e/live_iso_test.go index efd5a25014..3b5ab607c3 100644 --- a/test/e2e/live_iso_test.go +++ b/test/e2e/live_iso_test.go @@ -4,20 +4,17 @@ import ( "context" "fmt" - "golang.org/x/crypto/ssh" - + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "golang.org/x/crypto/ssh" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/patch" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - - capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e" ) var _ = Describe("Live-ISO", Label("required", "live-iso"), func() { diff --git a/test/e2e/provisioning_and_annotation_test.go b/test/e2e/provisioning_and_annotation_test.go index 6a21580830..186c100d43 100644 --- a/test/e2e/provisioning_and_annotation_test.go +++ b/test/e2e/provisioning_and_annotation_test.go @@ -7,10 +7,11 @@ import ( "os" "time" - "golang.org/x/crypto/ssh" - + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "golang.org/x/crypto/ssh" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -18,10 +19,6 @@ import ( "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/patch" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - - capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e" ) var _ = Describe("Provision, detach, recreate from status and deprovision", Label("required", "provision", "detach", "status", "deprovision"), diff --git a/test/e2e/re_inspection_test.go b/test/e2e/re_inspection_test.go index b4b9f72fcd..a9e074cef2 100644 --- a/test/e2e/re_inspection_test.go +++ b/test/e2e/re_inspection_test.go @@ -5,6 +5,8 @@ import ( "fmt" "strings" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -13,10 +15,6 @@ import ( "k8s.io/utils/pointer" "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/cluster-api/util" - - capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" ) var _ = Describe("Re-Inspection", Label("required", "re-inspection"), func() { diff --git a/test/e2e/upgrade_test.go b/test/e2e/upgrade_test.go index 98f75e68f9..ef6890baac 100644 --- a/test/e2e/upgrade_test.go +++ b/test/e2e/upgrade_test.go @@ -5,9 +5,9 @@ import ( "os" "path/filepath" + metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -15,8 +15,6 @@ import ( "sigs.k8s.io/cluster-api/test/framework/bootstrap" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/patch" - - metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" ) const hardwareDetailsRelease04 = ` @@ -200,7 +198,8 @@ var _ = Describe("BMO Upgrade", Label("optional", "upgrade"), func() { Expect(kubeconfigPath).To(BeAnExistingFile(), "Failed to get the kubeconfig file for the cluster") scheme := runtime.NewScheme() framework.TryAddDefaultSchemes(scheme) - metal3api.AddToScheme(scheme) + err := metal3api.AddToScheme(scheme) + Expect(err).NotTo(HaveOccurred()) upgradeClusterProxy = framework.NewClusterProxy("bmo-e2e-upgrade", kubeconfigPath, scheme) if e2eConfig.GetVariable("UPGRADE_DEPLOY_CERT_MANAGER") != "false" { @@ -235,7 +234,8 @@ var _ = Describe("BMO Upgrade", Label("optional", "upgrade"), func() { Expect(err).NotTo(HaveOccurred()) DeferCleanup(func() { By("Removing Ironic on the upgrade cluster") - BuildAndRemoveKustomization(ctx, ironicKustomization, upgradeClusterProxy) + err := BuildAndRemoveKustomization(ctx, ironicKustomization, upgradeClusterProxy) + Expect(err).NotTo(HaveOccurred()) }) } @@ -255,8 +255,11 @@ var _ = Describe("BMO Upgrade", Label("optional", "upgrade"), func() { }) Expect(err).NotTo(HaveOccurred()) DeferCleanup(func() { + // We suppress the error since DeferCleanup in upgrading BMO stage might + // already have cleaned up BMO in which case this step wouldn't find it + // and end up throwing an error By(fmt.Sprintf("Removing BMO from %s on the upgrade cluster", bmoFromKustomization)) - BuildAndRemoveKustomization(ctx, bmoFromKustomization, upgradeClusterProxy) + _ = BuildAndRemoveKustomization(ctx, bmoFromKustomization, upgradeClusterProxy) }) } @@ -324,7 +327,8 @@ var _ = Describe("BMO Upgrade", Label("optional", "upgrade"), func() { }) DeferCleanup(func() { By("Removing BMO main e2e deployment") - BuildAndRemoveKustomization(ctx, bmoKustomization, upgradeClusterProxy) + err := BuildAndRemoveKustomization(ctx, bmoKustomization, upgradeClusterProxy) + Expect(err).NotTo(HaveOccurred()) }) Expect(err).NotTo(HaveOccurred()) By("Waiting for BMO update to rollout")