@Bean @ConditionalOnMissingBean public KubernetesClient kubernetesClient(Config config) { return new DefaultKubernetesClient(config); }
public KubernetesApplicationContextInitializer() { this(LazilyInstantiate.using(() -> // If we are inside Kubernetes this should be perfectly valid. // If not then we won't add the Kubernetes profile anyway. new KubernetesProfileApplicationListener( new StandardPodUtils(new DefaultKubernetesClient())))); }
private static KubernetesContainerClient createKubernetesContainerClient() { // We only want one kubernetes client because it creates lots of thread pools and such things // so lets cache a copy of it in this factory. if (kubernetesContainerClient == null) { synchronized (ContainerFactory.class) { if (kubernetesContainerClient == null) { kubernetesContainerClient = new KubernetesContainerClient(new Environment(), KubernetesContainerClient::createDoneablePodDefaultImpl, new DefaultKubernetesClient()); kubernetesContainerClient.initialiseContainerEnvironment(); } } } return kubernetesContainerClient; }
public KubernetesApplicationContextInitializer() { //If we are inside Kubernetes this should be perfectly valid. //If not then we won't add the Kubernetes profile anyway. this(new StandardPodUtils(new DefaultKubernetesClient())); }
@Bean @ConditionalOnMissingBean public KubernetesClient kubernetesClient(Config config) { return new DefaultKubernetesClient(config); }
public static void main(String[] args) { KubernetesClient client = new DefaultKubernetesClient(); OpenShiftClient oclient = client.adapt(OpenShiftClient.class); System.out.println("Adapted to an openshift client: " + oclient); } }
public static DefaultKubernetesClient fromConfig(String config) { return new DefaultKubernetesClient(Serialization.unmarshal(config, Config.class)); }
public AutoAdaptableKubernetesClient(OkHttpClient httpClient, Config config) throws KubernetesClientException { delegate = adapt(new DefaultKubernetesClient(httpClient, config)); }
public DefaultOpenShiftClient(final OpenShiftConfig config) throws KubernetesClientException { super(config); try { this.httpClient = clientWithOpenShiftOAuthInterceptor(this.httpClient); this.delegate = new DefaultKubernetesClient(this.httpClient, config); this.openShiftUrl = new URL(config.getOpenShiftUrl()); } catch (MalformedURLException e) { throw new KubernetesClientException("Could not create client", e); } }
public DefaultOpenShiftClient(OkHttpClient httpClient, OpenShiftConfig config) throws KubernetesClientException { super(httpClient, config); try { this.httpClient = clientWithOpenShiftOAuthInterceptor(httpClient); this.delegate = new DefaultKubernetesClient(this.httpClient, config); this.openShiftUrl = new URL(config.getOpenShiftUrl()); } catch (MalformedURLException e) { throw new KubernetesClientException("Could not create client", e); } }
@Override public NamespacedKubernetesClient inNamespace(String namespace) { Config updated = new ConfigBuilder(getConfiguration()).withNamespace(namespace).build(); return new DefaultKubernetesClient(httpClient, updated); }
public static void main(String[] args) { String master = "http://localhost:8080/"; if (args.length == 1) { master = args[0]; } io.fabric8.kubernetes.client.Config config = new io.fabric8.kubernetes.client.ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { StorageClassList storageClassList = client.storage().storageClasses().list(); logger.info(storageClassList.toString()); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); } } }
public NamespacedKubernetesClient createClient() { Config config = new ConfigBuilder() .withMasterUrl(url("/")) .withTrustCerts(true) .withTlsVersions(TLS_1_0) .withNamespace("test") .build(); return new DefaultKubernetesClient(config); }
public static void main(String[] args) { try (DefaultKubernetesClient kubernetesClient = new DefaultKubernetesClient(new ConfigBuilder() .withMasterUrl("cluster_url") .withUsername("my_username") .withPassword("my_password") .build())) { final OpenShiftClient openShiftClient = kubernetesClient.adapt(OpenShiftClient.class); logger.info(openShiftClient.projects().list().toString()); } } }
@Test public void testAdaptToHttpClient() { KubernetesClient client = new DefaultKubernetesClient(); Assert.assertTrue(client.isAdaptable(OkHttpClient.class)); Assert.assertNotNull(client.adapt(OkHttpClient.class)); } }
@Ignore @Test public void testLoadingDodgyKubeConfig() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, InvalidKeySpecException { System.setProperty("kubeconfig", "/tmp/ceposta.kubeconfig"); KubernetesClient client = new DefaultKubernetesClient(); Config config = client.getConfiguration(); KeyStore ts = CertUtils.createTrustStore(config.getCaCertData(), null, null, "changeit"); KeyStore ks = CertUtils.createKeyStore(config.getClientCertData(), null, config.getClientKeyData(), null, "RSA", "changeit", null, "changeit"); }
@Test public void shouldRespectMaxRequestsPerHost() { Config config = new ConfigBuilder() .withMaxConcurrentRequestsPerHost(20) .build(); KubernetesClient client = new DefaultKubernetesClient(); assertEquals(5, client.adapt(OkHttpClient.class).dispatcher().getMaxRequestsPerHost()); client = new DefaultKubernetesClient(config); assertEquals(20, client.adapt(OkHttpClient.class).dispatcher().getMaxRequestsPerHost()); }
@Test public void shouldRespectMaxRequests() { Config config = new ConfigBuilder() .withMaxConcurrentRequests(120) .build(); KubernetesClient client = new DefaultKubernetesClient(); assertEquals(64, client.adapt(OkHttpClient.class).dispatcher().getMaxRequests()); client = new DefaultKubernetesClient(config); assertEquals(120, client.adapt(OkHttpClient.class).dispatcher().getMaxRequests()); }
public NamespacedKubernetesClient createClient() { Config config = new ConfigBuilder() .withMasterUrl(url("/")) .withTrustCerts(true) .withTlsVersions(TLS_1_0) .withNamespace("test") .build(); return new DefaultKubernetesClient(config); }
@Test public void shouldInstantiateClientUsingSerializeDeserialize() throws MalformedURLException { DefaultKubernetesClient original = new DefaultKubernetesClient(); String json = Serialization.asJson(original.getConfiguration()); DefaultKubernetesClient copy = DefaultKubernetesClient.fromConfig(json); Assert.assertEquals(original.getConfiguration().getMasterUrl(), copy.getConfiguration().getMasterUrl()); Assert.assertEquals(original.getConfiguration().getOauthToken(), copy.getConfiguration().getOauthToken()); Assert.assertEquals(original.getConfiguration().getNamespace(), copy.getConfiguration().getNamespace()); Assert.assertEquals(original.getConfiguration().getUsername(), copy.getConfiguration().getUsername()); Assert.assertEquals(original.getConfiguration().getPassword(), copy.getConfiguration().getPassword()); }