@Override public Config getConfiguration() { return delegate.getConfiguration(); } }
@Override public Config getConfiguration() { return delegate.getConfiguration(); } }
@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"); }
public KubernetesSupport(KubernetesClient client) { this.client = client; this.okHttpClient = this.client == null ? null : HttpClientUtils.createHttpClient(this.client.getConfiguration()); }
private JsonObject config() { String token = client.getConfiguration().getOauthToken(); if (token == null || token.trim().isEmpty()) { token = "some-token"; } return new JsonObject() .put("token", token) .put("host", "localhost") .put("ssl", false) .put("port", port); }
@Override public void authenticate(HttpClientBuilder httpClientBuilder, String s, String s1) { httpClientBuilder.addInterceptorFirst(new BearerTokenInterceptor(kubernetes.getConfiguration().getRequestConfig().getOauthToken())); }
@Override public void authenticate(HttpClientBuilder httpClientBuilder, String s, String s1) { httpClientBuilder.addInterceptorFirst(new BearerTokenInterceptor(kubernetes.getConfiguration().getRequestConfig().getOauthToken())); }
if (masterUrl != null && masterUrl.toString().startsWith("https")) { try { SSLContext sslCtx = SSLUtils.sslContext(kubernetes.getConfiguration()); ConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslCtx); builder = builder.sslConnectionSocketFactory(factory); builder = builder.authenticator(new BearerTokenAuthenticator()); String token = kubernetes.getConfiguration().getOauthToken(); builder = builder.user(token); break;
/** * Obtains a {@link KubernetesClient} either from the configured {@link Cloud} or a default instance. * @return * @throws AbortException */ protected KubernetesClient getKubernetesClient() throws AbortException { Cloud cloud = Jenkins.getInstance().getCloud(getStep().getCloud()); if (cloud == null) { LOGGER.warning("Cloud does not exist: [" + getStep().getCloud() + "]. Falling back to default KubernetesClient."); } else if (!(cloud instanceof KubernetesCloud)) { LOGGER.warning("Cloud is not a Kubernetes cloud: [" + getStep().getCloud() + "]. Falling back to default KubernetesClient."); } else { KubernetesCloud kubernetesCloud = (KubernetesCloud) cloud; try { String json = Serialization.asJson(kubernetesCloud.connect().getConfiguration()); return DefaultKubernetesClient.fromConfig(json); } catch (Throwable t) { LOGGER.warning("Could not connect to cloud: [" + getStep().getCloud() + "]. Falling back to default KubernetesClient."); } } return new DefaultKubernetesClient(); }
/** * Creates a {@link J4pClient} for the specified pod. * * @param kubernetes The {@link KubernetesClient} instance. * @param pod The name of the pod. * @return An instance of the {@link J4pClient}. */ private static J4pClient forPod(KubernetesClient kubernetes, String pod) { String jolokiaUrl = String.format(JOLOKIA_URL_FORMAT, kubernetes.getMasterUrl(), kubernetes.getNamespace(), pod); try { return new J4pClientBuilder() .url(jolokiaUrl) .user("user") .authenticator(new JolokiaKubernetesAuthenticator(kubernetes)) .sslConnectionSocketFactory(new SSLConnectionSocketFactory(SSLUtils.sslContext(kubernetes.getConfiguration()))) .build(); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) { throw SyndesisServerException.launderThrowable(e); } }
/** * Creates a {@link J4pClient} for the specified pod. * * @param kubernetes The {@link KubernetesClient} instance. * @param pod The name of the pod. * @return An instance of the {@link J4pClient}. */ private static J4pClient forPod(KubernetesClient kubernetes, String pod) { String jolokiaUrl = String.format(JOLOKIA_URL_FORMAT, kubernetes.getMasterUrl(), kubernetes.getNamespace(), pod); try { return new J4pClientBuilder() .url(jolokiaUrl) .user("user") .authenticator(new JolokiaKubernetesAuthenticator(kubernetes)) .sslConnectionSocketFactory(new SSLConnectionSocketFactory(SSLUtils.sslContext(kubernetes.getConfiguration()))) .build(); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) { throw SyndesisServerException.launderThrowable(e); } }
/** * Obtains a {@link KubernetesClient} either from the configured {@link Cloud} or a default instance. * @return * @throws AbortException */ protected KubernetesClient getKubernetesClient() throws AbortException { Cloud cloud = Jenkins.getInstance().getCloud(getStep().getCloud()); if (cloud == null) { LOGGER.warning("Cloud does not exist: [" + getStep().getCloud() + "]. Falling back to default KubernetesClient."); } else if (!(cloud instanceof KubernetesCloud)) { LOGGER.warning("Cloud is not a Kubernetes cloud: [" + getStep().getCloud() + "]. Falling back to default KubernetesClient."); } else { KubernetesCloud kubernetesCloud = (KubernetesCloud) cloud; try { String json = Serialization.asJson(kubernetesCloud.connect().getConfiguration()); return DefaultKubernetesClient.fromConfig(json); } catch (Throwable t) { LOGGER.warning("Could not connect to cloud: [" + getStep().getCloud() + "]. Falling back to default KubernetesClient."); } } return new DefaultKubernetesClient(); }
@Before public void before() { JdbcDataSource ds = new JdbcDataSource(); ds.setURL("jdbc:h2:mem:t;DB_CLOSE_DELAY=-1;MODE=PostgreSQL"); this.dbi = new DBI(ds); this.jsondb = new SqlJsonDB(dbi, null); this.jsondb.createTables(); client = mock(KubernetesClient.class); when(client.getConfiguration()).thenReturn(new ConfigBuilder().withMasterUrl("http://master").build()); }
port = new URL(client.getConfiguration().getMasterUrl()).getPort();
port = new URL(client.getConfiguration().getMasterUrl()).getPort();