Skip to content

Commit

Permalink
fix: error clearly if there are no nodes on the Kubernetes cluster (#…
Browse files Browse the repository at this point in the history
…1553)

## Description:
An AWS EKS cluster starts with no nodes which is quite confusing for the
user if the engine doesn't start. This checks if there are any nodes and
otherwise tells the user there aren't

## Is this change user facing?
YES

## References (if applicable):
#1507
  • Loading branch information
h4ck3rk3y committed Oct 17, 2023
1 parent 6411c8f commit 77f9ad4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Expand Up @@ -42,6 +42,14 @@ func CreateEngine(
*engine.Engine,
error,
) {
hasNodes, err := kubernetesManager.HasComputeNodes(ctx)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred while verifying whether the Kubernetes cluster has any compute nodes")
}
if !hasNodes {
return nil, stacktrace.NewError("Can't start engine on the Kubernetes cluster as it has no compute nodes")
}

engineGuidStr, err := uuid_generator.GenerateUUIDString()
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred generating a UUID string for the engine")
Expand Down
Expand Up @@ -122,6 +122,22 @@ var (
},
ResourceVersion: "",
}
globalListOptions = metav1.ListOptions{
TypeMeta: metav1.TypeMeta{
Kind: "",
APIVersion: "",
},
LabelSelector: "",
FieldSelector: "",
Watch: false,
AllowWatchBookmarks: false,
ResourceVersion: "",
ResourceVersionMatch: "",
TimeoutSeconds: nil,
Limit: 0,
Continue: "",
SendInitialEvents: nil,
}
)

type KubernetesManager struct {
Expand Down Expand Up @@ -1729,6 +1745,14 @@ func (manager *KubernetesManager) GetExecStream(ctx context.Context, pod *apiv1.
})
}

func (manager *KubernetesManager) HasComputeNodes(ctx context.Context) (bool, error) {
nodes, err := manager.kubernetesClientSet.CoreV1().Nodes().List(ctx, globalListOptions)
if err != nil {
return false, stacktrace.Propagate(err, "An error occurred while checking if the Kubernetes cluster has any nodes")
}
return len(nodes.Items) != 0, nil
}

// TODO Delete this after 2022-08-01 if we're not using Jobs
/*
func (manager *KubernetesManager) CreateJobWithContainerAndVolume(ctx context.Context,
Expand Down

0 comments on commit 77f9ad4

Please sign in to comment.