From 77f9ad42ba18f00faea5937bf3a971056ea8720b Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Tue, 17 Oct 2023 14:31:12 +0100 Subject: [PATCH] fix: error clearly if there are no nodes on the Kubernetes cluster (#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 --- .../engine_functions/create_engine.go | 8 +++++++ .../kubernetes_manager/kubernetes_manager.go | 24 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/engine_functions/create_engine.go b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/engine_functions/create_engine.go index 8009b58458..fc0e06bb7e 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/engine_functions/create_engine.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/engine_functions/create_engine.go @@ -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") diff --git a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_manager/kubernetes_manager.go b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_manager/kubernetes_manager.go index e4ff86c01e..231c0b6340 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_manager/kubernetes_manager.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_manager/kubernetes_manager.go @@ -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 { @@ -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,