Skip to content

Commit

Permalink
Fix infinite loop in case of initial credentials error
Browse files Browse the repository at this point in the history
  • Loading branch information
Gchbg committed May 14, 2024
1 parent 9c0a212 commit 5be8ebf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const (
// +kubebuilder:printcolumn:name="Power",type=string,JSONPath=`.status.power`
// +kubebuilder:printcolumn:name="LocatorLED",type=string,JSONPath=`.status.locatorLED`,priority=100
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
// +genclient

// Machine is the Schema for the machines API
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/machineclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const (
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
// +genclient

// MachineClaim is the Schema for the machineclaims API
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/oob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const (
// +kubebuilder:printcolumn:name="SerialNumber",type=string,JSONPath=`.status.serialNumber`,priority=100
// +kubebuilder:printcolumn:name="FirmwareVersion",type=string,JSONPath=`.status.firmwareVersion`,priority=100
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
// +genclient

// OOB is the Schema for the oobs API
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/oobsecret_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type OOBSecretStatus struct {
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:printcolumn:name="MACAddress",type=string,JSONPath=`.spec.macAddress`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
// +genclient

// OOBSecret is the Schema for the oobsecrets API
Expand Down
46 changes: 26 additions & 20 deletions internal/controller/oob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,29 +741,35 @@ func (r *OOBReconciler) processCredentials(ctx context.Context, oob *metalv1alph
return ctx, apply, status, nil
}

oob.Spec.Protocol = &a.Protocol
oob.Spec.Flags = a.Flags
defaultCreds = a.DefaultCredentials
oob.Status.Type = a.Type
log.Debug(ctx, "Setting protocol, flags, and type")
if apply == nil {
var err error
apply, err = metalv1alpha1apply.ExtractOOB(oob, OOBFieldManager)
if err != nil {
return ctx, nil, nil, fmt.Errorf("cannot extract OOB: %w", err)
if !util.NilOrEqual(oob.Spec.Protocol, &a.Protocol) {
oob.Spec.Protocol = &a.Protocol
oob.Spec.Flags = a.Flags
defaultCreds = a.DefaultCredentials
log.Debug(ctx, "Setting protocol and flags")
if apply == nil {
var err error
apply, err = metalv1alpha1apply.ExtractOOB(oob, OOBFieldManager)
if err != nil {
return ctx, nil, nil, fmt.Errorf("cannot extract OOB: %w", err)
}
}
apply = apply.WithSpec(util.Ensure(apply.Spec).
WithProtocol(metalv1alpha1apply.Protocol().
WithName(oob.Spec.Protocol.Name).
WithPort(oob.Spec.Protocol.Port)).
WithFlags(oob.Spec.Flags))
}
apply = apply.WithSpec(util.Ensure(apply.Spec).
WithProtocol(metalv1alpha1apply.Protocol().
WithName(oob.Spec.Protocol.Name).
WithPort(oob.Spec.Protocol.Port)).
WithFlags(oob.Spec.Flags))
applyst, err := metalv1alpha1apply.ExtractOOBStatus(oob, OOBFieldManager)
if err != nil {
return ctx, nil, nil, fmt.Errorf("cannot extract OOB status: %w", err)

if oob.Status.Type != a.Type {
oob.Status.Type = a.Type
log.Debug(ctx, "Setting type")
applyst, err := metalv1alpha1apply.ExtractOOBStatus(oob, OOBFieldManager)
if err != nil {
return ctx, nil, nil, fmt.Errorf("cannot extract OOB status: %w", err)
}
status = util.Ensure(applyst.Status).
WithType(a.Type)
}
status = util.Ensure(applyst.Status).
WithType(a.Type)
}

b, err := bmc.NewBMC(string(oob.Spec.Protocol.Name), oob.Spec.Flags, host, oob.Spec.Protocol.Port, creds, expiration)
Expand Down

0 comments on commit 5be8ebf

Please sign in to comment.