StyxScheduler implements AppInit { @VisibleForTesting public static NamespacedKubernetesClient getKubernetesClient(Config config, String id) { return getKubernetesClient(config, id, createGkeClient(), DefaultKubernetesClient::new); } private  StyxScheduler(Builder builder); static Builder newBuilder(); static StyxScheduler createDefault(); @Override void create(Environment environment); @VisibleForTesting static NamespacedKubernetesClient getKubernetesClient(Config config, String id); static final String SERVICE_NAME; static final String STYX_STALE_STATE_TTL_CONFIG; }
@Test @Parameters({ "4711", "" }) public void testGetKubernetesClient(String k8sRequestTimeoutConfig) throws Exception { var clusterCaCertificate = Resources.toString(Resources.getResource("ca.crt"), UTF_8); var clientCertificate = Resources.toString(Resources.getResource("client.crt"), UTF_8); var clientKey = Resources.toString(Resources.getResource("client.key"), UTF_8); final int expectedK8sRequestTimeout; if (!k8sRequestTimeoutConfig.isEmpty()) { expectedK8sRequestTimeout = Integer.parseInt(k8sRequestTimeoutConfig); } else { expectedK8sRequestTimeout = DEFAULT_KUBERNETES_REQUEST_TIMEOUT_MILLIS; } var client = getKubernetesClient( k8sRequestTimeoutConfig, clusterCaCertificate, clientCertificate, clientKey); assertThat(client, is(theInstance(kubernetesClient))); verify(kubernetesClientFactory).apply(httpClientCaptor.capture(), k8sClientConfigCaptor.capture()); var k8sConfig = k8sClientConfigCaptor.getValue(); var httpClient = httpClientCaptor.getValue(); assertThat(k8sConfig.getMasterUrl(), is("https: assertThat(k8sConfig.getCaCertData(), is(clusterCaCertificate)); assertThat(k8sConfig.getClientCertData(), is(clientCertificate)); assertThat(k8sConfig.getClientKeyData(), is(clientKey)); assertThat(k8sConfig.getNamespace(), is(TEST_NAMESPACE)); assertThat(k8sConfig.getRequestTimeout(), is(expectedK8sRequestTimeout)); assertThat(httpClient.protocols(), contains(Protocol.HTTP_1_1)); }
@Test public void testGetKubernetesClientNullClusterCaCertificate() throws Exception { var clientCertificate = Resources.toString(Resources.getResource("client.crt"), UTF_8); var clientKey = Resources.toString(Resources.getResource("client.key"), UTF_8); exception.expect(NullPointerException.class); getKubernetesClient("", null, clientCertificate, clientKey); }
@Test public void testGetKubernetesClientNullClientCertificate() throws Exception { var clusterCaCertificate = Resources.toString(Resources.getResource("ca.crt"), UTF_8); var clientKey = Resources.toString(Resources.getResource("client.key"), UTF_8); exception.expect(NullPointerException.class); getKubernetesClient("", clusterCaCertificate, null, clientKey); }
@Test public void testGetKubernetesClientNullClientKey() throws Exception { var clusterCaCertificate = Resources.toString(Resources.getResource("ca.crt"), UTF_8); var clientCertificate = Resources.toString(Resources.getResource("client.crt"), UTF_8); exception.expect(NullPointerException.class); getKubernetesClient("", clusterCaCertificate, clientCertificate, null); }