Skip to content

[PMKS] k8sClusterRecommendNode API returns empty results due to incorrect filtering condition #2176

@hanizang77

Description

@hanizang77

What happened
: The k8sClusterRecommendNode API endpoint is returning empty arrays for all tested cloud service providers (Azure koreacentral, AWS ap-northeast-2, GCP asia-east1). Through debugging analysis, we discovered that the RecommendK8sNode function in /src/core/infra/recommendation.go contains incorrect filtering logic that searches for InfraType values containing "k8s" or "kubernetes", but the returned specifications all have InfraType = "vm", resulting in empty recommendation results despite VM specs being perfectly suitable for Kubernetes node deployment.

What you expected to happen
: The k8sClusterRecommendNode API should return appropriate K8s node specifications when valid cloud provider and region combinations are provided, instead of returning empty arrays.

How to reproduce it (as minimally and precisely as possible)
: API Test Command

curl -X 'POST' \
  'http://localhost:1323/tumblebug/k8sClusterRecommendNode' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "filter": {
      "policy": [
        {
          "condition": [
            {"operand": "18", "operator": ">="},
            {"operand": "0", "operator": "<="}
          ],
          "metric": "vCPU"
        },
        {
          "condition": [
            {"operand": "128", "operator": ">="},
            {"operand": "0", "operator": "<="}
          ],
          "metric": "memoryGiB"
        },
        {
          "condition": [{"operand": "azure"}],
          "metric": "providerName"
        },
        {
          "condition": [{"operand": "koreacentral"}],
          "metric": "regionName"
        }
      ]
    }
  }'

Anything else we need to know?
: Technical Analysis

  • Location: /src/core/infra/recommendation.go, lines 1244-1246
  • Current filtering logic: strings.Contains(SpecInfo.InfraType, model.StrK8s) || strings.Contains(SpecInfo.InfraType, model.StrKubernetes)
  • Database reality: All specs have InfraType = "VM"
  • Debug verification: Added log.Info().Msg(SpecInfo.InfraType) at line 1243 confirms all specs are "VM"

Environment

  • cb-tumblebug version: v0.11.13
  • Platform: Docker Compose deployment
  • Testing method: REST API calls with basic authentication

Proposed solution

// Current problematic code (lines 1244-1246):
if strings.Contains(SpecInfo.InfraType, model.StrK8s) ||
   strings.Contains(SpecInfo.InfraType, model.StrKubernetes) {

// Suggested fix:
if strings.Contains(strings.ToLower(SpecInfo.InfraType), "k8s") ||
   strings.Contains(strings.ToLower(SpecInfo.InfraType), "kubernetes") ||
   strings.Contains(strings.ToLower(SpecInfo.InfraType), "vm") {

Any other context

  1. Compatibility Verification Needed: Before implementing this fix, we should verify that VM specifications can successfully create K8s clusters without issues. The current filtering assumes VM specs are suitable for K8s nodes, but this needs validation across different cloud providers.
  2. Future InfraType Classification: This is a temporary fix. In the future, when dedicated K8s specifications or container-optimized specs become available, they should be properly classified with InfraType = "k8s", "kubernetes", or "container" to enable more precise filtering.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions