question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KubernetesTestServer does not return set mocked pods

See original GitHub issue

Describe the bug

We (me and @chris-asl) are using Quarkus and quarkus-kubernetes-client following the documentation Quarkus Kubernetes Client.

The test outlined in the documentation is not passing and fails with

[ERROR] Failures:
[ERROR]   KubernetesClientTest.testInteractionWithAPIServer:38 1 expectation failed.
JSON path size() doesn't match.
Expected: is <2>
  Actual: <0>

We have created a test repository demonstrating exactly the problem (using code.quarkus.io) so that we have a minimal, complete and verifiable example, which you can find here.

The project contains three branches:

  • master: code as described from the docs
  • use-quarkus-snapshot: uses latest Quarkus SNAPSHOT (as outlined in CONTRIBUTING doc), still failling
  • fix-with-deprecated-resource: uses a deprecated resource KubernetesMockServerTestResource with which the tests are passing

Is there something we’re missing or are the docs outdated?

Expected behavior

Expected Kubernetes Mock Server to return 2 pods.

Actual behavior

Returned 0 pods.

To Reproduce

Here is a project that reproduces the issue (as described above) https://github.com/el10686/quarkus-kubernetes-client

Steps to reproduce the behavior:

  1. git clone
  2. ./mvnw test

Configuration

Empty file

Environment (please complete the following information):

Output of uname -a or ver

Linux vanias-G5-5500 5.8.0-45-generic #51~20.04.1-Ubuntu SMP Tue Feb 23 13:46:31 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk 11.0.10 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

GraalVM version (if different from Java)

Not using GraalVM

Quarkus version or git rev

1.12.2.Final and tested against latest snapshot

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/vanias/.m2/wrapper/dists/apache-maven-3.6.3-bin/1iopthnavndlasol9gbrbg6bf2/apache-maven-3.6.3
Java version: 11.0.10, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.8.0-45-generic", arch: "amd64", family: "unix"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
chris-aslcommented, Mar 19, 2021

@FroMage @geoand I can confirm this works just fine! Thank you very much for the prompt reply! 😄

1reaction
FroMagecommented, Mar 19, 2021

#15853 should fix that. Basically CRUD mode is now the default, so if you want to fix your test in the simplest way, just add crud = false on the annotation. Or set up your test resources like this:

@WithKubernetesTestServer
@QuarkusTest
public class KubernetesClientTest {

    @KubernetesTestServer
    KubernetesServer mockServer;

    @BeforeEach
    public void before() {
        final Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").and().build();
        final Pod pod2 = new PodBuilder().withNewMetadata().withName("pod2").withNamespace("test").and().build();

        // Set up Kubernetes so that our "pretend" pods are created
        mockServer.getClient().pods().create(pod1);
        mockServer.getClient().pods().create(pod2);
    }

    @Test
    public void testInteractionWithAPIServer() {
        RestAssured.when().get("/pod/test").then()
                .body("size()", is(2));
    }

}

IMO this is cleaner as it doesn’t require mocking HTTP which can be error-prone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CRUD mode doesn't support watches on the pod resource ...
I'm trying to use the mock KubernetesServer in CRUD mode to test some code that sets up a watch on the pod resource,...
Read more >
How to Mock APIs in Kubernetes - Speedscale
In this guide, we document the process of building mock APIs in Kubernetes from traffic using Speedscale.
Read more >
Unit testing Kubernetes operators using mocks - ITNEXT
It simply informs the mock object that it has been called, and returns without any error. This method would do something useful for...
Read more >
Mocking the Kubernetes client in Go for Unit Testing - Medium
When we run this main.go file against a running cluster, we end up creating a pod called test-pod in the default namespace. Now,...
Read more >
Setting up Kubernetes Mock Server Using Golang
I am trying to setup a mock server using which I can test performance of my application on higher scales. Basically my Go...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found