Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error clearly if there are no nodes on the Kubernetes cluster #1553

Merged
merged 5 commits into from Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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