Skip to content

Commit 9496863

Browse files
Add bmclib Provider ordering to API spec:
And update bmclib client creation to take in this ordering. Signed-off-by: Jacob Weinstock <[email protected]>
1 parent 0b6d3cf commit 9496863

8 files changed

+58
-6
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
8181
go run ./main.go
8282

8383
.PHONY: docker-build
84-
docker-build: test ## Build docker image with the manager.
84+
docker-build: ## Build docker image with the manager.
8585
docker build -t ${IMG} .
8686

8787
.PHONY: docker-push

api/v1alpha1/machine.go

+15
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,22 @@ type MachineSpec struct {
5252
Connection Connection `json:"connection"`
5353
}
5454

55+
// ProviderName is the bmclib specific provider name. Names are case insensitive.
56+
// +kubebuilder:validation:Pattern=(?i)^(ipmitool|asrockrack|gofish|IntelAMT|dell|supermicro|openbmc)$
57+
type ProviderName string
58+
59+
func (p ProviderName) String() string {
60+
return string(p)
61+
}
62+
63+
// ProviderOptions hold provider specific configurable options.
5564
type ProviderOptions struct {
65+
// PreferredOrder allows customizing the order that BMC providers are called.
66+
// Providers added to this list will be moved to the front of the default order.
67+
// Provider names are case insensitive.
68+
// The default order is: ipmitool, asrockrack, gofish, intelamt, dell, supermicro, openbmc.
69+
// +optional
70+
PreferredOrder []ProviderName `json:"preferredOrder,omitempty"`
5671
// IntelAMT contains the options to customize the IntelAMT provider.
5772
// +optional
5873
IntelAMT *IntelAMTOptions `json:"intelAMT,omitempty"`

api/v1alpha1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/bmc.tinkerbell.org_machines.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ spec:
102102
description: Port that ipmitool will use for calls.
103103
type: integer
104104
type: object
105+
preferredOrder:
106+
description: |-
107+
PreferredOrder allows customizing the order that BMC providers are called.
108+
Providers added to this list will be moved to the front of the default order.
109+
Provider names are case insensitive.
110+
The default order is: ipmitool, asrockrack, gofish, intelamt, dell, supermicro, openbmc.
111+
items:
112+
description: ProviderName is the bmclib specific provider
113+
name. Names are case insensitive.
114+
pattern: (?i)^(ipmitool|asrockrack|gofish|IntelAMT|dell|supermicro|openbmc)$
115+
type: string
116+
type: array
105117
redfish:
106118
description: Redfish contains the options to customize the
107119
Redfish provider.

config/crd/bases/bmc.tinkerbell.org_tasks.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ spec:
103103
description: Port that ipmitool will use for calls.
104104
type: integer
105105
type: object
106+
preferredOrder:
107+
description: |-
108+
PreferredOrder allows customizing the order that BMC providers are called.
109+
Providers added to this list will be moved to the front of the default order.
110+
Provider names are case insensitive.
111+
The default order is: ipmitool, asrockrack, gofish, intelamt, dell, supermicro, openbmc.
112+
items:
113+
description: ProviderName is the bmclib specific provider
114+
name. Names are case insensitive.
115+
pattern: (?i)^(ipmitool|asrockrack|gofish|IntelAMT|dell|supermicro|openbmc)$
116+
type: string
117+
type: array
106118
redfish:
107119
description: Redfish contains the options to customize the
108120
Redfish provider.

controller/client.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ import (
1414
"github.com/tinkerbell/rufio/api/v1alpha1"
1515
)
1616

17+
// convert a slice of ProviderName to a slice of string.
18+
func toStringSlice(p []v1alpha1.ProviderName) []string {
19+
var s []string
20+
for _, v := range p {
21+
s = append(s, v.String())
22+
}
23+
return s
24+
}
25+
1726
// ClientFunc defines a func that returns a bmclib.Client.
1827
type ClientFunc func(ctx context.Context, log logr.Logger, hostIP, username, password string, opts *BMCOptions) (*bmclib.Client, error)
1928

@@ -32,8 +41,7 @@ func NewClientFunc(timeout time.Duration) ClientFunc {
3241
ctx, cancel := context.WithTimeout(ctx, timeout)
3342
defer cancel()
3443

35-
// TODO (pokearu): Make an option
36-
client.Registry.Drivers = client.Registry.PreferProtocol("redfish")
44+
client.Registry.Drivers = client.Registry.PreferProtocol(toStringSlice(opts.PreferredOrder)...)
3745
if err := client.Open(ctx); err != nil {
3846
md := client.GetMetadata()
3947
log.Info("Failed to open connection to BMC", "error", err, "providersAttempted", md.ProvidersAttempted, "successfulProvider", md.SuccessfulOpenConns)

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.22.2
66

77
require (
88
dario.cat/mergo v1.0.1
9-
github.com/bmc-toolbox/bmclib/v2 v2.3.4-0.20241022160847-8a5f5a1a243c
9+
github.com/bmc-toolbox/bmclib/v2 v2.3.4-0.20241028123729-490323db418f
1010
github.com/ccoveille/go-safecast v1.1.0
1111
github.com/go-logr/logr v1.4.2
1212
github.com/go-logr/zerologr v1.2.3

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ github.com/VictorLowther/soap v0.0.0-20150314151524-8e36fca84b22 h1:a0MBqYm44o0N
88
github.com/VictorLowther/soap v0.0.0-20150314151524-8e36fca84b22/go.mod h1:/B7V22rcz4860iDqstGvia/2+IYWXf3/JdQCVd/1D2A=
99
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
1010
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
11-
github.com/bmc-toolbox/bmclib/v2 v2.3.4-0.20241022160847-8a5f5a1a243c h1:UrzCk+x0r3nsa3aTvuNesgtU5/6EkCrEF7EfwnM2rjI=
12-
github.com/bmc-toolbox/bmclib/v2 v2.3.4-0.20241022160847-8a5f5a1a243c/go.mod h1:t8If/0fHQTRIK/yKDk2H3SgthDNNj+7z2aeftDFRFrU=
11+
github.com/bmc-toolbox/bmclib/v2 v2.3.4-0.20241028123729-490323db418f h1:7w8RNmuc53Vm+dkzDq49OVZiKh3UuM4Z7R4guJ9Wf10=
12+
github.com/bmc-toolbox/bmclib/v2 v2.3.4-0.20241028123729-490323db418f/go.mod h1:t8If/0fHQTRIK/yKDk2H3SgthDNNj+7z2aeftDFRFrU=
1313
github.com/bmc-toolbox/common v0.0.0-20240806132831-ba8adc6a35e3 h1:/BjZSX/sphptIdxpYo4wxAQkgMLyMMgfdl48J9DKNeE=
1414
github.com/bmc-toolbox/common v0.0.0-20240806132831-ba8adc6a35e3/go.mod h1:Cdnkm+edb6C0pVkyCrwh3JTXAe0iUF9diDG/DztPI9I=
1515
github.com/bombsimon/logrusr/v2 v2.0.1 h1:1VgxVNQMCvjirZIYaT9JYn6sAVGVEcNtRE0y4mvaOAM=

0 commit comments

Comments
 (0)