Skip to content

Commit

Permalink
Implement machine control
Browse files Browse the repository at this point in the history
  • Loading branch information
Gchbg committed Jun 3, 2024
1 parent 0840187 commit 58898c1
Show file tree
Hide file tree
Showing 15 changed files with 932 additions and 196 deletions.
12 changes: 9 additions & 3 deletions api/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type MachineSpec struct {
// +optional
Power Power `json:"power,omitempty"`

// +kubebuilder:validation:Enum=On;Off;Blinking
// +kubebuilder:validation:Enum=Lit;Off;Blinking
// +optional
LocatorLED LED `json:"locatorLED,omitempty"`
}
Expand All @@ -53,7 +53,7 @@ const (
type LED string

const (
LEDOn LED = "On"
LEDLit LED = "Lit"
LEDOff LED = "Off"
LEDBlinking LED = "Blinking"
)
Expand All @@ -73,7 +73,7 @@ type MachineStatus struct {
// +optional
Power Power `json:"power,omitempty"`

// +kubebuilder:validation:Enum=On;Off;Blinking
// +kubebuilder:validation:Enum=Lit;Off;Blinking
// +optional
LocatorLED LED `json:"locatorLED,omitempty"`

Expand Down Expand Up @@ -114,6 +114,12 @@ const (
MachineStateError MachineState = "Error"
)

const (
MachineConditionTypeOOBHealthy = "OOBHealthy"
MachineConditionReasonOOBReady = "OOBReady"
MachineConditionReasonOOBError = "OOBError"
)

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha1/oob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Protocol struct {

type ProtocolName string

//goland:noinspection GoUnusedConst
const (
ProtocolNameRedfish ProtocolName = "Redfish"
ProtocolNameIPMI ProtocolName = "IPMI"
Expand All @@ -54,6 +55,7 @@ type ConsoleProtocol struct {

type ConsoleProtocolName string

//goland:noinspection GoUnusedConst
const (
ConsoleProtocolNameIPMI ConsoleProtocolName = "IPMI"
ConsoleProtocolNameSSH ConsoleProtocolName = "SSH"
Expand Down Expand Up @@ -87,6 +89,7 @@ type OOBStatus struct {

type OOBType string

//goland:noinspection GoUnusedConst
const (
OOBTypeMachine OOBType = "Machine"
OOBTypeRouter OOBType = "Router"
Expand Down
1 change: 1 addition & 0 deletions client/applyconfiguration/internal/internal.go

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

28 changes: 19 additions & 9 deletions client/openapi/zz_generated.openapi.go

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

5 changes: 4 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type params struct {
oobIpLabelSelector string
oobMacDB string
oobCredsRenewalBeforeExpiry time.Duration
oobShutdownTimeout time.Duration
oobUsernamePrefix string
oobTemporaryPasswordSecret string
}
Expand All @@ -75,6 +76,7 @@ func parseCmdLine() params {
pflag.String("oob-ip-label-selector", "", "OOB: Filter IP objects by labels.")
pflag.String("oob-mac-db", "", "OOB: Load MAC DB from file.")
pflag.Duration("oob-creds-renewal-before-expiry", time.Hour*24*7, "OOB: Renew expiring credentials this long before they expire.")
pflag.Duration("oob-shutdown-timeout", 7*time.Minute, "Wait this long before issuing an immediate shutdown, if graceful shutdown has not succeeded.")
pflag.String("oob-username-prefix", "metal-", "OOB: Use a prefix when creating BMC users. Cannot be empty.")
pflag.String("oob-temporary-password-secret", "bmc-temporary-password", "OOB: Secret to store a temporary password in. Will be generated if it does not exist.")

Expand Down Expand Up @@ -109,6 +111,7 @@ func parseCmdLine() params {
oobIpLabelSelector: viper.GetString("oob-ip-label-selector"),
oobMacDB: viper.GetString("oob-mac-db"),
oobCredsRenewalBeforeExpiry: viper.GetDuration("oob-creds-renewal-before-expiry"),
oobShutdownTimeout: viper.GetDuration("oob-shutdown-timeout"),
oobUsernamePrefix: viper.GetString("oob-username-prefix"),
oobTemporaryPasswordSecret: viper.GetString("oob-temporary-password-secret"),
}
Expand Down Expand Up @@ -268,7 +271,7 @@ func main() {

if p.enableOOBController {
var oobReconciler *controller.OOBReconciler
oobReconciler, err = controller.NewOOBReconciler(p.systemNamespace, p.oobIpLabelSelector, p.oobMacDB, p.oobCredsRenewalBeforeExpiry, p.oobUsernamePrefix, p.oobTemporaryPasswordSecret)
oobReconciler, err = controller.NewOOBReconciler(p.systemNamespace, p.oobIpLabelSelector, p.oobMacDB, p.oobCredsRenewalBeforeExpiry, p.oobShutdownTimeout, p.oobUsernamePrefix, p.oobTemporaryPasswordSecret)
if err != nil {
log.Error(ctx, fmt.Errorf("cannot create controller: %w", err), "controller", "OOB")
exitCode = 1
Expand Down
14 changes: 12 additions & 2 deletions config/crd/bases/metal.ironcore.dev_machineclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ spec:
referenced object inside the same namespace.
properties:
name:
default: ""
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
Expand All @@ -69,10 +74,15 @@ spec:
referenced object inside the same namespace.
properties:
name:
default: ""
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
Expand Down
39 changes: 32 additions & 7 deletions config/crd/bases/metal.ironcore.dev_machines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,21 @@ spec:
referenced object inside the same namespace.
properties:
name:
default: ""
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
locatorLED:
enum:
- "On"
- Lit
- "Off"
- Blinking
type: string
Expand All @@ -94,10 +99,15 @@ spec:
referenced object inside the same namespace.
properties:
name:
default: ""
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
Expand Down Expand Up @@ -168,10 +178,15 @@ spec:
referenced object inside the same namespace.
properties:
name:
default: ""
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
Expand Down Expand Up @@ -261,7 +276,7 @@ spec:
type: array
locatorLED:
enum:
- "On"
- Lit
- "Off"
- Blinking
type: string
Expand All @@ -276,10 +291,15 @@ spec:
referenced object inside the same namespace.
properties:
name:
default: ""
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
Expand All @@ -294,10 +314,15 @@ spec:
referenced object inside the same namespace.
properties:
name:
default: ""
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
TODO: Add other useful fields. apiVersion, kind, uid?
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Drop `kubebuilder:default` when controller-gen doesn't need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.
type: string
type: object
x-kubernetes-map-type: atomic
Expand Down
Loading

0 comments on commit 58898c1

Please sign in to comment.