2 years ago

#131927

test-img

Karthick M

Break in fabric8 kubernetes client mock server

We were using fabric8 kubernetes client 5.3.x for watcher and it worked fine. Recently when we moved to 5.11.2 there were many changes observed and eventually the JUnit Tests started failing.

We use io.fabric8.kubernetes.client.server.mock.KubernetesServer

Earlier we were using ContainerStatus .withNewReady which now seem to be removed. And then we added the following annotation @Rule public KubernetesServer myMockServer = new KubernetesServer(false, true);

After this, we are getting the following logs stating unsupported label requirement while the application code is sending this label.

[2022-02-03T07:30:22.733Z] 07:30:17.812 [pool-1-thread-1] DEBUG io.fabric8.kubernetes.client.dsl.internal.AbstractWatchManager - Watching http://localhost:40033/api/v1/namespaces/test/pods?labelSelector=app.kubernetes.io%2Fname%20in%20%28apps%29&timeoutSeconds=0&allowWatchBookmarks=true&watch=true...

[2022-02-03T07:30:22.733Z] 07:30:17.814 [MockWebServer /127.0.0.1:49882] WARN io.fabric8.kubernetes.client.server.mock.KubernetesAttributesExtractor - Ignoring unsupported label requirement: app.kubernetes.io/name in (apps)

[2022-02-03T07:30:22.733Z] 07:30:17.815 [MockWebServer /127.0.0.1:49882] DEBUG io.fabric8.kubernetes.client.server.mock.KubernetesAttributesExtractor - fromPath /api/v1/namespaces/test/pods?labelSelector=app.kubernetes.io%2Fname%20in%20%28apps%29&timeoutSeconds=0&allowWatchBookmarks=true&watch=true : {attributes: {namespace={key:namespace, value:test}, version={key:version, value:v1}, plural={key:plural, value:pods}}}

[2022-02-03T07:30:22.733Z] 07:30:17.815 [OkHttp http://localhost:40033/...] DEBUG io.fabric8.kubernetes.client.dsl.internal.WatcherWebSocketListener - WebSocket successfully opened

[2022-02-03T07:30:22.733Z] 07:30:20.818 [OkHttp http://localhost:40033/...] DEBUG io.fabric8.kubernetes.client.dsl.internal.AbstractWatchManager - Scheduling reconnect task

Is there something more should be done? Tests are in ERROR state and not Failed.

Sample JUnit program

  public void testAddNewPodWatchEvent()
  {
      //given
      doReturn(myClientMock).when(myTestObj).getClient();
      doReturn(myWatcherSpy).when(myTestObj).createEventHandler();
      String PATH =
              "/api/v1/namespaces/test/pods?labelSelector=app.kubernetes.io%2Fname%20in%20%28apps%29&timeoutSeconds=0&watch=true";
      Map<String, String> mockLabelMap = new HashMap<>();
      mockLabelMap.put("foo", "testlabel");
      mockLabelMap.put("app.kubernetes.io/name", "apps");
      Pod accPod = createAppsPod(mockLabelMap, true);

      myMockServer.expect()
              .get()
              .withPath(PATH)
              .andUpgradeToWebSocket()
              .open()
              .waitFor(100)
              .andEmit(new WatchEvent(accPod, "ADDED"))
              .done()
              .once();

      //when
      myTestObj.activate(mockProps);
      sleepForWatchToBeInvoked();

      //then
      verify(myWatcherSpy, atLeastOnce()).eventReceived(Action.ADDED, accPod);
  }

fabric8

0 Answers

Your Answer

Accepted video resources