Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KubernetesMockServer should provide Kubernetes Aggregated Discovery endpoints in CRUD Mode #6062

Open
rohanKanojia opened this issue Jun 18, 2024 · 1 comment
Labels
component/kubernetes-server-mock Deals with the kubernetes-server-mock directory mainly

Comments

@rohanKanojia
Copy link
Member

Is your enhancement related to a problem? Please describe

At the moment KubernetesMockServer doesn't support providing opinionated responses for Kubernetes Aggregated Discovery APIs . This causes problems when we try to use KubernetesMockServer with clients other than Fabric8 KubernetesClient like kubectl /helm etc. It logs this warning with used with helm CLI

OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
Jun 18, 2024 6:09:27 PM okhttp3.mockwebserver.MockWebServer$Http2SocketHandler onStream
INFO: MockWebServer[42981] received request: GET /version HTTP/1.1 and responded: HTTP/1.1 200 OK protocol is h2
Jun 18, 2024 6:09:27 PM okhttp3.mockwebserver.MockWebServer$Http2SocketHandler onStream
INFO: MockWebServer[42981] received request: GET /api/v1/namespaces/test/secrets?labelSelector=name%3Dtest-project%2Cowner%3Dhelm HTTP/1.1 and responded: HTTP/1.1 200 OK protocol is h2
Jun 18, 2024 6:09:27 PM okhttp3.mockwebserver.MockWebServer$Http2SocketHandler onStream
INFO: MockWebServer[42981] received request: GET /version?timeout=32s HTTP/1.1 and responded: HTTP/1.1 200 OK protocol is h2
Jun 18, 2024 6:09:27 PM okhttp3.mockwebserver.MockWebServer$Http2SocketHandler onStream
INFO: MockWebServer[42981] received request: GET /api?timeout=32s HTTP/1.1 and responded: HTTP/1.1 200 OK protocol is h2
Jun 18, 2024 6:09:27 PM okhttp3.mockwebserver.MockWebServer$Http2SocketHandler onStream
INFO: MockWebServer[42981] received request: GET /apis?timeout=32s HTTP/1.1 and responded: HTTP/1.1 200 OK protocol is h2
Jun 18, 2024 6:09:28 PM okhttp3.mockwebserver.MockWebServer$Http2SocketHandler onStream
INFO: MockWebServer[42981] received request: GET /api?timeout=32s HTTP/1.1 and responded: HTTP/1.1 200 OK protocol is h2
Jun 18, 2024 6:09:28 PM okhttp3.mockwebserver.MockWebServer$Http2SocketHandler onStream
INFO: MockWebServer[42981] received request: GET /apis?timeout=32s HTTP/1.1 and responded: HTTP/1.1 200 OK protocol is h2
Jun 18, 2024 6:09:28 PM okhttp3.mockwebserver.MockWebServer$2 acceptConnections
INFO: MockWebServer[42981] done accepting connections: Socket closed

Describe the solution you'd like

Fabric8 KubernetesMockServer should provide some opinionated defaults for these endpoints:

  • /api
  • /apis/
  • /apis/{apiGroup}/{apiVersion}

Describe alternatives you've considered

For now I'm using KubernetesMockServer in expectations mode by providing these expectations:

  private void prepareMockWebServerExpectations() {
    server.expect().get()
      .withPath("/version?timeout=32s")
      .andReturn(200, new VersionInfo.Builder()
        .withMajor("1")
        .withMinor("30")
        .build())
      .always();
    server.expect().get().withPath("/api?timeout=32s")
      .andReturn(200, String.format("{\"kind\":\"APIVersions\",\"versions\":[\"v1\"],\"serverAddressByClientCIDRs\":[{\"clientCIDR\":\"0.0.0.0/0\",\"serverAddress\":\"%s:%d\"}]}", server.getHostName(), server.getPort()))
      .always();
    server.expect().get().withPath("/apis?timeout=32s")
      .andReturn(200, createNewAPIGroupList())
      .always();
    server.expect().get().withPath("/api/v1?timeout=32s")
      .andReturn(200, createNewAPIResourceList())
      .always();
    server.expect().get().withPath("/apis/apps/v1?timeout=32s")
      .andReturn(200, createNewAPIResourceList())
      .always();
  }

  private APIResourceList createNewAPIResourceList() {
    APIResourceListBuilder apiResourceListBuilder = new APIResourceListBuilder();
    apiResourceListBuilder.addToResources(new APIResourceBuilder()
        .withNamespaced()
        .withKind("Service")
        .withName("services")
        .withSingularName("service")
      .build());
    apiResourceListBuilder.addToResources(new APIResourceBuilder()
        .withName("deployments")
        .withKind("Deployment")
        .withSingularName("deployment")
        .withNamespaced()
      .build());
    apiResourceListBuilder.addToResources(new APIResourceBuilder()
      .withName("serviceaccounts")
      .withKind("ServiceAccount")
      .withSingularName("serviceaccount")
      .withNamespaced()
      .build());
    return apiResourceListBuilder.build();
  }

  private APIGroupList createNewAPIGroupList() {
    return new APIGroupListBuilder()
      .addToGroups(new APIGroupBuilder()
        .withName("apps")
        .addNewVersion()
        .withGroupVersion("apps/v1")
        .withVersion("v1")
        .endVersion()
        .withNewPreferredVersion()
        .withGroupVersion("apps/v1")
        .withVersion("v1")
        .endPreferredVersion()
        .build())
      .build();
  }

Additional context

No response

Copy link

stale bot commented Sep 17, 2024

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/kubernetes-server-mock Deals with the kubernetes-server-mock directory mainly
Projects
None yet
Development

No branches or pull requests

2 participants