Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bmclib Provider ordering to API spec, bmclib fix for system name: #264

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions api/v1alpha1/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions config/crd/bases/bmc.tinkerbell.org_machines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/bmc.tinkerbell.org_tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 10 additions & 2 deletions controller/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down