From 949686337cc65193871c3967646fcefaa7005e3d Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Mon, 28 Oct 2024 11:23:19 -0600 Subject: [PATCH] Add bmclib Provider ordering to API spec: And update bmclib client creation to take in this ordering. Signed-off-by: Jacob Weinstock --- Makefile | 2 +- api/v1alpha1/machine.go | 15 +++++++++++++++ api/v1alpha1/zz_generated.deepcopy.go | 5 +++++ config/crd/bases/bmc.tinkerbell.org_machines.yaml | 12 ++++++++++++ config/crd/bases/bmc.tinkerbell.org_tasks.yaml | 12 ++++++++++++ controller/client.go | 12 ++++++++++-- go.mod | 2 +- go.sum | 4 ++-- 8 files changed, 58 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index d9e08b8..5ab7574 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,7 @@ run: manifests generate fmt vet ## Run a controller from your host. go run ./main.go .PHONY: docker-build -docker-build: test ## Build docker image with the manager. +docker-build: ## Build docker image with the manager. docker build -t ${IMG} . .PHONY: docker-push diff --git a/api/v1alpha1/machine.go b/api/v1alpha1/machine.go index 31b549d..d1db2d9 100644 --- a/api/v1alpha1/machine.go +++ b/api/v1alpha1/machine.go @@ -52,7 +52,22 @@ type MachineSpec struct { Connection Connection `json:"connection"` } +// ProviderName is the bmclib specific provider name. Names are case insensitive. +// +kubebuilder:validation:Pattern=(?i)^(ipmitool|asrockrack|gofish|IntelAMT|dell|supermicro|openbmc)$ +type ProviderName string + +func (p ProviderName) String() string { + return string(p) +} + +// ProviderOptions hold provider specific configurable options. type ProviderOptions struct { + // PreferredOrder allows customizing the order that BMC providers are called. + // Providers added to this list will be moved to the front of the default order. + // Provider names are case insensitive. + // The default order is: ipmitool, asrockrack, gofish, intelamt, dell, supermicro, openbmc. + // +optional + PreferredOrder []ProviderName `json:"preferredOrder,omitempty"` // IntelAMT contains the options to customize the IntelAMT provider. // +optional IntelAMT *IntelAMTOptions `json:"intelAMT,omitempty"` diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index a21aa42..99fed2d 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -459,6 +459,11 @@ func (in *OneTimeBootDeviceAction) DeepCopy() *OneTimeBootDeviceAction { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ProviderOptions) DeepCopyInto(out *ProviderOptions) { *out = *in + if in.PreferredOrder != nil { + in, out := &in.PreferredOrder, &out.PreferredOrder + *out = make([]ProviderName, len(*in)) + copy(*out, *in) + } if in.IntelAMT != nil { in, out := &in.IntelAMT, &out.IntelAMT *out = new(IntelAMTOptions) diff --git a/config/crd/bases/bmc.tinkerbell.org_machines.yaml b/config/crd/bases/bmc.tinkerbell.org_machines.yaml index b52897a..3e49c84 100644 --- a/config/crd/bases/bmc.tinkerbell.org_machines.yaml +++ b/config/crd/bases/bmc.tinkerbell.org_machines.yaml @@ -102,6 +102,18 @@ spec: description: Port that ipmitool will use for calls. type: integer type: object + preferredOrder: + description: |- + PreferredOrder allows customizing the order that BMC providers are called. + Providers added to this list will be moved to the front of the default order. + Provider names are case insensitive. + The default order is: ipmitool, asrockrack, gofish, intelamt, dell, supermicro, openbmc. + items: + description: ProviderName is the bmclib specific provider + name. Names are case insensitive. + pattern: (?i)^(ipmitool|asrockrack|gofish|IntelAMT|dell|supermicro|openbmc)$ + type: string + type: array redfish: description: Redfish contains the options to customize the Redfish provider. diff --git a/config/crd/bases/bmc.tinkerbell.org_tasks.yaml b/config/crd/bases/bmc.tinkerbell.org_tasks.yaml index 76d6753..d2bc904 100644 --- a/config/crd/bases/bmc.tinkerbell.org_tasks.yaml +++ b/config/crd/bases/bmc.tinkerbell.org_tasks.yaml @@ -103,6 +103,18 @@ spec: description: Port that ipmitool will use for calls. type: integer type: object + preferredOrder: + description: |- + PreferredOrder allows customizing the order that BMC providers are called. + Providers added to this list will be moved to the front of the default order. + Provider names are case insensitive. + The default order is: ipmitool, asrockrack, gofish, intelamt, dell, supermicro, openbmc. + items: + description: ProviderName is the bmclib specific provider + name. Names are case insensitive. + pattern: (?i)^(ipmitool|asrockrack|gofish|IntelAMT|dell|supermicro|openbmc)$ + type: string + type: array redfish: description: Redfish contains the options to customize the Redfish provider. diff --git a/controller/client.go b/controller/client.go index e89759c..a1de7a4 100644 --- a/controller/client.go +++ b/controller/client.go @@ -14,6 +14,15 @@ import ( "github.com/tinkerbell/rufio/api/v1alpha1" ) +// convert a slice of ProviderName to a slice of string. +func toStringSlice(p []v1alpha1.ProviderName) []string { + var s []string + for _, v := range p { + s = append(s, v.String()) + } + return s +} + // ClientFunc defines a func that returns a bmclib.Client. type ClientFunc func(ctx context.Context, log logr.Logger, hostIP, username, password string, opts *BMCOptions) (*bmclib.Client, error) @@ -32,8 +41,7 @@ func NewClientFunc(timeout time.Duration) ClientFunc { ctx, cancel := context.WithTimeout(ctx, timeout) defer cancel() - // TODO (pokearu): Make an option - client.Registry.Drivers = client.Registry.PreferProtocol("redfish") + client.Registry.Drivers = client.Registry.PreferProtocol(toStringSlice(opts.PreferredOrder)...) if err := client.Open(ctx); err != nil { md := client.GetMetadata() log.Info("Failed to open connection to BMC", "error", err, "providersAttempted", md.ProvidersAttempted, "successfulProvider", md.SuccessfulOpenConns) diff --git a/go.mod b/go.mod index aed4985..3438a22 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.22.2 require ( dario.cat/mergo v1.0.1 - github.com/bmc-toolbox/bmclib/v2 v2.3.4-0.20241022160847-8a5f5a1a243c + github.com/bmc-toolbox/bmclib/v2 v2.3.4-0.20241028123729-490323db418f github.com/ccoveille/go-safecast v1.1.0 github.com/go-logr/logr v1.4.2 github.com/go-logr/zerologr v1.2.3 diff --git a/go.sum b/go.sum index 1deb8d1..7b77487 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,8 @@ github.com/VictorLowther/soap v0.0.0-20150314151524-8e36fca84b22 h1:a0MBqYm44o0N github.com/VictorLowther/soap v0.0.0-20150314151524-8e36fca84b22/go.mod h1:/B7V22rcz4860iDqstGvia/2+IYWXf3/JdQCVd/1D2A= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bmc-toolbox/bmclib/v2 v2.3.4-0.20241022160847-8a5f5a1a243c h1:UrzCk+x0r3nsa3aTvuNesgtU5/6EkCrEF7EfwnM2rjI= -github.com/bmc-toolbox/bmclib/v2 v2.3.4-0.20241022160847-8a5f5a1a243c/go.mod h1:t8If/0fHQTRIK/yKDk2H3SgthDNNj+7z2aeftDFRFrU= +github.com/bmc-toolbox/bmclib/v2 v2.3.4-0.20241028123729-490323db418f h1:7w8RNmuc53Vm+dkzDq49OVZiKh3UuM4Z7R4guJ9Wf10= +github.com/bmc-toolbox/bmclib/v2 v2.3.4-0.20241028123729-490323db418f/go.mod h1:t8If/0fHQTRIK/yKDk2H3SgthDNNj+7z2aeftDFRFrU= github.com/bmc-toolbox/common v0.0.0-20240806132831-ba8adc6a35e3 h1:/BjZSX/sphptIdxpYo4wxAQkgMLyMMgfdl48J9DKNeE= github.com/bmc-toolbox/common v0.0.0-20240806132831-ba8adc6a35e3/go.mod h1:Cdnkm+edb6C0pVkyCrwh3JTXAe0iUF9diDG/DztPI9I= github.com/bombsimon/logrusr/v2 v2.0.1 h1:1VgxVNQMCvjirZIYaT9JYn6sAVGVEcNtRE0y4mvaOAM=