Class KubernetesMockServer

    • Method Detail

      • init

        public void init()
      • init

        public void init​(InetAddress address,
                         int port)
      • destroy

        public void destroy()
      • getRootPaths

        public String[] getRootPaths()
      • createClient

        public io.fabric8.kubernetes.client.NamespacedKubernetesClient createClient()
      • createClient

        public io.fabric8.kubernetes.client.NamespacedKubernetesClient createClient​(io.fabric8.kubernetes.client.http.HttpClient.Factory factory)
      • createClient

        public io.fabric8.kubernetes.client.NamespacedKubernetesClient createClient​(Consumer<io.fabric8.kubernetes.client.KubernetesClientBuilder> kubernetesClientBuilderCustomizer)
        Creates a client using the cusotmized KubernetesClientBuilder provided in the Consumer parameter.

        The function is invoked using an initial Config instance that is initialized with the mock server's URL and the TlsVersion to use.

        The following snippet shows how you can use this method in your tests:

           @BeforeEach
           void setUp() {
             server = new KubernetesMockServer();
             server.start();
             client = server.createClient(b -> {/* customize builder */}));
           }
         }
        Parameters:
        kubernetesClientBuilderCustomizer - Consumer function to enable further customization of the provided KubernetesClientBuilder.
        Returns:
        a NamespacedKubernetesClient instance from the provided configuration.
      • setVersionInfo

        public final void setVersionInfo​(io.fabric8.kubernetes.client.VersionInfo versionInfo)
        Replace the current VersionInfo instance.
        Parameters:
        versionInfo - the new VersionInfo.
      • setUnsupported

        public void setUnsupported​(String... unsupported)
        Used to exclude support for the given apiGroups.
        Each is a simple expression of the form: group[/version]
        where * is a wildcard.
        For example to exclude all openshift support, you would specify openshift.io
        To exclude a specific apiVersion, you would fully specify route.openshift.io/v1

        NOTE this affects calls to Client.hasApiGroup(String, boolean) and Client.supports(Class). Other calls to get the full root path or other api group metadata will not return valid results in mock scenarios.

        Parameters:
        unsupported - apiGroup patterns
      • clearExpectations

        public void clearExpectations()
        Removes all recorded expectations.
      • initConfig

        protected io.fabric8.kubernetes.client.Config initConfig()
      • reset

        public void reset()
        Description copied from interface: Resetable
        return the resource to its initial state
        Specified by:
        reset in interface Resetable
      • expectCustomResource

        public void expectCustomResource​(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext rdc)
        Ensure that the server will supply an APIResourceList containing an APIResource representing the CustomResourceDefinitionContext from the apis/group/version endpoint.

        This is useful when testing calls through the KubernetesClient.genericKubernetesResources(String, String) entry point.

        If this is a crud server, the custom resource will be added to the set of previously added resources and the resources inferred from custom resource definitions that have been added.

        If this server is not crud, this call will add a single expectation for the given resource. Direct handling of multiple resources for a given api group/version has not yet been added.

        Specified by:
        expectCustomResource in interface CustomResourceAware
        Parameters:
        rdc - the resource definition context