Skip to content

Commit

Permalink
BREAKING: Allow custom condition reasons to be returned from Create (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis authored Jan 22, 2025
1 parent 5128b39 commit af00eb4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkg/cloudprovider/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,14 @@ func IsNodeClassNotReadyError(err error) bool {
// CreateError is an error type returned by CloudProviders when instance creation fails
type CreateError struct {
error
ConditionReason string
ConditionMessage string
}

func NewCreateError(err error, message string) *CreateError {
func NewCreateError(err error, reason, message string) *CreateError {
return &CreateError{
error: err,
ConditionReason: reason,
ConditionMessage: message,
}
}
2 changes: 1 addition & 1 deletion pkg/controllers/nodeclaim/lifecycle/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (l *Launch) launchNodeClaim(ctx context.Context, nodeClaim *v1.NodeClaim) (
default:
var createError *cloudprovider.CreateError
if errors.As(err, &createError) {
nodeClaim.StatusConditions().SetUnknownWithReason(v1.ConditionTypeLaunched, "LaunchFailed", createError.ConditionMessage)
nodeClaim.StatusConditions().SetUnknownWithReason(v1.ConditionTypeLaunched, createError.ConditionReason, createError.ConditionMessage)
} else {
nodeClaim.StatusConditions().SetUnknownWithReason(v1.ConditionTypeLaunched, "LaunchFailed", truncateMessage(err.Error()))
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/controllers/nodeclaim/lifecycle/launch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ var _ = Describe("Launch", func() {
ExpectNotFound(ctx, env.Client, nodeClaim)
})
It("should set nodeClaim status condition from the condition message received if error returned is CreateError", func() {
conditionReason := "CustomReason"
conditionMessage := "instance creation failed"
cloudProvider.NextCreateErr = cloudprovider.NewCreateError(fmt.Errorf("error launching instance"), conditionMessage)
cloudProvider.NextCreateErr = cloudprovider.NewCreateError(fmt.Errorf("error launching instance"), conditionReason, conditionMessage)
nodeClaim := test.NodeClaim()
ExpectApplied(ctx, env.Client, nodeClaim)
_ = ExpectObjectReconcileFailed(ctx, env.Client, nodeClaimController, nodeClaim)
nodeClaim = ExpectExists(ctx, env.Client, nodeClaim)
condition := ExpectStatusConditionExists(nodeClaim, v1.ConditionTypeLaunched)
Expect(condition.Status).To(Equal(metav1.ConditionUnknown))
Expect(condition.Reason).To(Equal(conditionReason))
Expect(condition.Message).To(Equal(conditionMessage))
})
})

0 comments on commit af00eb4

Please sign in to comment.