Skip to content

test(computing-unit): cover the pod lookup, creation and deletion paths - #7511

Merged
mengw15 merged 2 commits into
apache:mainfrom
aglinxinyuan:cov/kubernetes-client
Aug 10, 2026
Merged

test(computing-unit): cover the pod lookup, creation and deletion paths#7511
mengw15 merged 2 commits into
apache:mainfrom
aglinxinyuan:cov/kubernetes-client

Conversation

@aglinxinyuan

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

The spec covered the pure transforms and the namespace-wide wrappers and stopped. The single-pod
half of the class — getPodByName, podExists, getPodLimits, createPod, deletePod and the
pod URI — was untested, which is 42 of the file's 62 lines.

None of it needs a cluster: the fabric8 client is already a constructor parameter, so the existing
Mockito fixture extends to the rest of the fluent chain, with the pod that createPod builds
captured and inspected rather than sent anywhere.

Adds 8 tests. The three that matter:

  • the guard that refuses to overwrite a live pod — creating over a running unit would detach it
    from its owner;
  • the Option(...) wrapper around the by-name lookup — fabric8 returns null for an absent
    pod rather than throwing, so the wrapper is all that stands between a caller and an NPE;
  • the shared-memory volume appearing only when a size is requested/dev/shm defaults to
    64 Mi, too small for the Python workers, and the volume must not appear when unrequested.

Also covered: the pod URI's service and namespace segments, the first container's resource limits
and the empty-map fallback, env values reaching the container as strings, and deletePod targeting
the cuid's own pod.

Verified by mutation, all reverted (production diff empty):

Mutation Result
pod name loses the cuid suffix red
URI drops the namespace segment red
getPodByName no longer null-guards red
createPod overwrites an existing pod red
cpu limit written from the memory value red
pod hostname is not the pod name red
deletePod targets a fixed cuid red

No production file is touched.

Any related issues, documentation, discussions?

Closes #7510

How was this PR tested?

sbt "ComputingUnitManagingService/testOnly org.apache.texera.service.util.KubernetesClientSpec"
[info] Total number of tests run: 16
[info] Tests: succeeded 16, failed 0, canceled 0, ignored 0, pending 0

8 new on top of the existing 8. Test/scalafmtCheck and Test/scalafix --check both pass.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5)

KubernetesClientSpec covered the pure fabric8-to-map transforms and the
namespace-wide wrappers, and stopped there. The single-pod half of the
class - getPodByName, podExists, getPodLimits, createPod, deletePod and
the pod URI - was untested, which is 42 of the file's 62 lines.

None of it needs a cluster. The fabric8 client is already a constructor
parameter, and the existing spec's Mockito plumbing extends to the rest
of the fluent chain: withName(...).get() for the lookups and
resource(pod).inNamespace(...).create() for creation, with the built pod
captured and inspected.

Adds 8 tests. The ones worth having are the guard that refuses to
overwrite a live pod, the null-to-None wrapper that fabric8 requires, and
the shared-memory volume appearing only when a size is requested.

No production file is touched.
Copilot AI lite review requested due to automatic review settings August 10, 2026 05:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the platform Non-amber Scala service paths label Aug 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @kunwp1
    You can notify them by mentioning @kunwp1 in a comment.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (2)

computing-unit-managing-service/src/test/scala/org/apache/texera/service/util/KubernetesClientSpec.scala:298

  • In the shared-memory helper, the pod argument is captured via verify(client).resource(...), but the test doesn't assert that the fluent chain actually reaches .create(). Adding a verify(resource).create() makes the intent (“create the pod”) explicit and protects against regressions where creation is skipped.
      when(client.resource(any(classOf[Pod]))).thenReturn(namespaceable)
      when(namespaceable.inNamespace(namespace)).thenReturn(resource)
      // create()'s return value is not asserted; the pod is inspected through the captor below.
      when(resource.create()).thenReturn(null)
      new KubernetesClient(client).createPod(6, "1", "2Gi", "0", Map.empty, shm)
      verify(client).resource(captor.capture())
      captor.getValue

computing-unit-managing-service/src/test/scala/org/apache/texera/service/util/KubernetesClientSpec.scala:271

  • This test captures the pod passed to client.resource(...) but doesn't assert that create() was actually invoked. If createPod were to accidentally stop calling .create() (e.g., returning the built pod without creating it), this test would still pass.

Consider verifying the terminal call on the fluent chain as well (and optionally inNamespace(namespace)), to ensure the method truly performs creation.

This issue also appears on line 292 of the same file.

    when(client.resource(any(classOf[Pod]))).thenReturn(namespaceable)
    when(namespaceable.inNamespace(namespace)).thenReturn(resource)
    // create()'s return value is not asserted; the pod is inspected through the captor below.
    when(resource.create()).thenReturn(null)

    new KubernetesClient(client).createPod(5, "2", "4Gi", "1", Map("UID" -> 9, "MODE" -> "batch"))

    verify(client).resource(captor.capture())
    val built = captor.getValue

@codecov-commenter

codecov-commenter commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.47%. Comparing base (a61e1ee) to head (987bad4).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7511      +/-   ##
============================================
- Coverage     86.52%   86.47%   -0.06%     
- Complexity     4211     4221      +10     
============================================
  Files          1169     1169              
  Lines         46754    46750       -4     
  Branches       5203     5203              
============================================
- Hits          40454    40427      -27     
- Misses         4577     4599      +22     
- Partials       1723     1724       +1     
Flag Coverage Δ *Carryforward flag
access-control-service 70.00% <ø> (ø)
agent-service 86.87% <ø> (-2.14%) ⬇️ Carriedforward from 42d08a3
amber 81.87% <ø> (ø) Carriedforward from 42d08a3
computing-unit-managing-service 60.38% <ø> (+9.66%) ⬆️
config-service 65.97% <ø> (ø)
file-service 69.05% <ø> (ø)
frontend 89.23% <ø> (+<0.01%) ⬆️ Carriedforward from 42d08a3
notebook-migration-service 78.89% <ø> (ø)
pyamber 97.56% <ø> (ø) Carriedforward from 42d08a3
workflow-compiling-service 26.31% <ø> (ø)

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mengw15 mengw15 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mengw15
mengw15 added this pull request to the merge queue Aug 10, 2026
Merged via the queue into apache:main with commit 8aec229 Aug 10, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform Non-amber Scala service paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cover the Kubernetes client's pod lookup, creation and deletion paths

4 participants