From 2e8c9503b702a347a1b71c8c92d54f15af0eac2e Mon Sep 17 00:00:00 2001 From: Konstantin Koslowski Date: Fri, 27 Mar 2026 15:51:39 +0100 Subject: [PATCH] Improve BMC connection reliability and error logging Use explicit HTTP/2 transport for Redfish connections instead of relying on gofish defaults, and add structured logging on connection failures with error type and URL error op fields to aid debugging. fixes issues with one bmc ``` ERROR Reconciler error {"controller": "bmc", "controllerGroup": "metal.ironcore.dev", "controllerKind": "BMC", "BMC": {"name":"nodexx"}, "namespace": "", "name": "nodexx", "reconcileID": "", "error": "Get \"https://1.2.3.4:443/redfish/v1/\": net/http: HTTP/1.x transport connection broken: malformed HTTP status code \"bad\""} ``` --- bmc/redfish.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/bmc/redfish.go b/bmc/redfish.go index 1e01ecdce..87223ade7 100644 --- a/bmc/redfish.go +++ b/bmc/redfish.go @@ -6,12 +6,14 @@ package bmc import ( "context" "crypto/rand" + "crypto/tls" "encoding/json" "errors" "fmt" "io" "maps" "math/big" + "net/http" "net/url" "slices" "strings" @@ -19,6 +21,7 @@ import ( "github.com/stmcginnis/gofish" "github.com/stmcginnis/gofish/schemas" + "golang.org/x/net/http2" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/wait" @@ -83,15 +86,28 @@ func (e *InvalidBIOSSettingsError) Error() string { // newRedfishBaseBMCClient creates a new RedfishBaseBMC with the given connection details (internal use only). func newRedfishBaseBMCClient(ctx context.Context, options Options) (*RedfishBaseBMC, error) { + transport := &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec + } + if err := http2.ConfigureTransport(transport); err != nil { + return nil, fmt.Errorf("failed to configure HTTP/2 transport: %w", err) + } clientConfig := gofish.ClientConfig{ - Endpoint: options.Endpoint, - Username: options.Username, - Password: options.Password, - Insecure: true, - BasicAuth: options.BasicAuth, + Endpoint: options.Endpoint, + Username: options.Username, + Password: options.Password, + BasicAuth: options.BasicAuth, + HTTPClient: &http.Client{Transport: transport}, + NoModifyTransport: true, } client, err := gofish.ConnectContext(ctx, clientConfig) if err != nil { + var urlErr *url.Error + if errors.As(err, &urlErr) { + ctrl.LoggerFrom(ctx).V(1).Info("Could not connect to BMC endpoint", "endpoint", options.Endpoint, "op", urlErr.Op, "errorType", fmt.Sprintf("%T", urlErr.Unwrap()), "error", err) + } else { + ctrl.LoggerFrom(ctx).V(1).Info("Could not connect to BMC endpoint", "endpoint", options.Endpoint, "errorType", fmt.Sprintf("%T", err), "error", err) + } return nil, err } bmc := &RedfishBaseBMC{client: client}