Skip to content

Commit

Permalink
🌱 Set condition to false if server resource unavailable (#1394)
Browse files Browse the repository at this point in the history
set condition to false if server resource unavailable

mark hcloud machine's "serverCreateSucceeded" condition to false if it
throws server resource unavailable error

Signed-off-by: Dhairya Arora <[email protected]>
  • Loading branch information
Dhairya-Arora01 authored Jul 25, 2024
1 parent e21e3b2 commit d3bd5b5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions api/v1beta1/conditions_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const (
ServerLimitExceededReason = "ServerLimitExceeded"
// ServerTypeNotFoundReason indicates that server type could not be found.
ServerTypeNotFoundReason = "ServerTypeNotFound"
// ServerResourceUnavailableReason indicates that server resource is unavailable.
ServerResourceUnavailableReason = "ServerResourceUnavailable"
// ServerPlacementErrorReason indicates placement error while creating server.
ServerPlacementErrorReason = "ServerPlacementError"
)

const (
Expand Down
32 changes: 26 additions & 6 deletions pkg/services/hcloud/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,34 @@ func (s *Service) createServer(ctx context.Context) (*hcloud.Server, error) {
clusterv1.ConditionSeverityError,
err.Error(),
)
record.Warnf(s.scope.HCloudMachine,
"FailedCreateHCloudServer",
"Failed to create HCloud server %s: %s",
s.scope.Name(),
err,

err = errors.Join(errServerCreateNotPossible, err)
}

if hcloud.IsError(err, hcloud.ErrorCodeResourceUnavailable) {
conditions.MarkFalse(
s.scope.HCloudMachine,
infrav1.ServerCreateSucceededCondition,
infrav1.ServerResourceUnavailableReason,
clusterv1.ConditionSeverityWarning,
err.Error(),
)
return nil, errServerCreateNotPossible

err = errors.Join(errServerCreateNotPossible, err)
}

if hcloud.IsError(err, hcloud.ErrorCodePlacementError) {
conditions.MarkFalse(
s.scope.HCloudMachine,
infrav1.ServerCreateSucceededCondition,
infrav1.ServerPlacementErrorReason,
clusterv1.ConditionSeverityWarning,
err.Error(),
)

err = errors.Join(errServerCreateNotPossible, err)
}

record.Warnf(s.scope.HCloudMachine,
"FailedCreateHCloudServer",
"Failed to create HCloud server %s: %s",
Expand Down

0 comments on commit d3bd5b5

Please sign in to comment.