Search in sources :

Example 1 with RequestConfig

use of io.fabric8.kubernetes.client.RequestConfig in project kubernetes-client by fabric8io.

the class UserImpersonationIT method should_be_able_to_create_a_project_impersonating_service_account.

@Test
public void should_be_able_to_create_a_project_impersonating_service_account() {
    RequestConfig requestConfig = new RequestConfigBuilder().withImpersonateUsername(SERVICE_ACCOUNT).withImpersonateGroups("system:authenticated", "system:authenticated:oauth").withImpersonateExtras(Collections.singletonMap("scopes", Collections.singletonList("development"))).build();
    // Create a project
    ProjectRequest projectRequest = client.withRequestConfig(requestConfig).call(c -> c.projectrequests().create(new ProjectRequestBuilder().withNewMetadata().withName(NEW_PROJECT).endMetadata().build()));
    // Grab the requester annotation
    String requester = projectRequest.getMetadata().getAnnotations().get("openshift.io/requester");
    assertThat(requester).isEqualTo(SERVICE_ACCOUNT);
}
Also used : RequestConfig(io.fabric8.kubernetes.client.RequestConfig) ProjectRequestBuilder(io.fabric8.openshift.api.model.ProjectRequestBuilder) ProjectRequest(io.fabric8.openshift.api.model.ProjectRequest) RequestConfigBuilder(io.fabric8.kubernetes.client.RequestConfigBuilder) Test(org.junit.Test)

Example 2 with RequestConfig

use of io.fabric8.kubernetes.client.RequestConfig in project kubernetes-client by fabric8io.

the class RequestConfigTest method testOauthTokenSuppliedByProvider.

@Test
public void testOauthTokenSuppliedByProvider() throws InterruptedException {
    server.expect().withPath("/api/v1/namespaces/test/pods/podName").andReturn(200, new PodBuilder().withNewMetadata().withName("testPodX").endMetadata().build()).always();
    RequestConfig requestConfig = new RequestConfigBuilder().withOauthTokenProvider(tokenProvider).build();
    tokenProvider.updateToken("token1");
    sendRequest(requestConfig);
    assertAuthorizationHeader("Bearer token1");
    tokenProvider.updateToken("token2");
    sendRequest(requestConfig);
    assertAuthorizationHeader("Bearer token2");
}
Also used : RequestConfig(io.fabric8.kubernetes.client.RequestConfig) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) RequestConfigBuilder(io.fabric8.kubernetes.client.RequestConfigBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with RequestConfig

use of io.fabric8.kubernetes.client.RequestConfig in project dropwizard-kubernetes by dropwizard.

the class KubernetesClientFactory method build.

public KubernetesClient build(final MetricRegistry metrics, final LifecycleEnvironment lifecycle, final HealthCheckRegistry healthChecks, final String appName, @Nullable final Tracing tracing) throws Exception {
    final RequestConfig requestConf = requestConfig != null ? requestConfig.build() : null;
    final Config k8sConfig = config.build(appName, requestConf);
    if (httpClient == null) {
        return new DefaultKubernetesClient(k8sConfig);
    }
    final OkHttpClient okHttpClient = httpClient.build(k8sConfig, metrics, name, requestConf, tracing);
    final KubernetesClient client = new DefaultKubernetesClient(okHttpClient, k8sConfig);
    // manage
    lifecycle.manage(new KubernetesClientManager(client, name));
    // health checks
    final String healthCheckUrl = getHealthCheckUrl(k8sConfig);
    final KubernetesClientHealthCheck healthCheck = new KubernetesClientHealthCheck(okHttpClient, name, healthCheckUrl);
    healthChecks.register(name, healthCheck);
    return client;
}
Also used : RequestConfig(io.fabric8.kubernetes.client.RequestConfig) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) OkHttpClient(okhttp3.OkHttpClient) RequestConfig(io.fabric8.kubernetes.client.RequestConfig) Config(io.fabric8.kubernetes.client.Config) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClientHealthCheck(io.dropwizard.kubernetes.health.KubernetesClientHealthCheck) KubernetesClientManager(io.dropwizard.kubernetes.managed.KubernetesClientManager)

Example 4 with RequestConfig

use of io.fabric8.kubernetes.client.RequestConfig in project dropwizard-kubernetes by dropwizard.

the class OkHttpClientFactoryTest method shouldBuildAConfigWithNoRequestConfig.

@Test
public void shouldBuildAConfigWithNoRequestConfig() throws Exception {
    // given
    final File yaml = new File(Resources.getResource("yaml/http/http-client.yaml").toURI());
    final OkHttpClientFactory httpClientFactory = factory.build(yaml);
    final Config config = new ConfigBuilder().build();
    final RequestConfig requestConfig = new RequestConfigBuilder().build();
    // when
    final OkHttpClient httpClient = httpClientFactory.build(config, metrics, "app123", requestConfig, tracing);
    // then
    assertThat(httpClient).isInstanceOf(OkHttpClient.class);
    assertThat(httpClient.interceptors().size()).isEqualTo(2);
    assertThat(httpClient.proxy()).isNotNull();
    assertThat(httpClient.followRedirects()).isFalse();
    assertThat(httpClient.followRedirects()).isFalse();
}
Also used : RequestConfig(io.fabric8.kubernetes.client.RequestConfig) OkHttpClient(okhttp3.OkHttpClient) RequestConfig(io.fabric8.kubernetes.client.RequestConfig) Config(io.fabric8.kubernetes.client.Config) RequestConfigBuilder(io.fabric8.kubernetes.client.RequestConfigBuilder) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) RequestConfigBuilder(io.fabric8.kubernetes.client.RequestConfigBuilder) File(java.io.File) Test(org.junit.Test)

Example 5 with RequestConfig

use of io.fabric8.kubernetes.client.RequestConfig in project dropwizard-kubernetes by dropwizard.

the class ConfigFactory method build.

public Config build(final String appName, @Nullable final RequestConfig requestConfig) {
    final Config config = Config.autoConfigure(currentContext);
    if (masterUrl != null) {
        config.setMasterUrl(masterUrl);
    }
    if (apiVersion != null) {
        config.setApiVersion(apiVersion);
    }
    if (namespace != null) {
        config.setNamespace(namespace);
    }
    if (userAgent != null) {
        config.setUserAgent(userAgent);
    } else {
        config.setUserAgent(appName);
    }
    if (requestConfig != null) {
        config.setLoggingInterval(requestConfig.getLoggingInterval());
        config.setRollingTimeout(requestConfig.getRollingTimeout());
        config.setScaleTimeout(requestConfig.getScaleTimeout());
        config.setWatchReconnectInterval(requestConfig.getWatchReconnectInterval());
        config.setWatchReconnectLimit(requestConfig.getWatchReconnectLimit());
        config.setConnectionTimeout(requestConfig.getConnectionTimeout());
        config.setRequestTimeout(requestConfig.getRequestTimeout());
        config.setRollingTimeout(requestConfig.getRollingTimeout());
        config.setScaleTimeout(requestConfig.getScaleTimeout());
        config.setWebsocketTimeout(requestConfig.getWebsocketTimeout());
        config.setWebsocketPingInterval(requestConfig.getWebsocketPingInterval());
        config.setMaxConcurrentRequests(requestConfig.getMaxConcurrentRequests());
        config.setMaxConcurrentRequestsPerHost(requestConfig.getMaxConcurrentRequestsPerHost());
    }
    return config;
}
Also used : Config(io.fabric8.kubernetes.client.Config) RequestConfig(io.fabric8.kubernetes.client.RequestConfig)

Aggregations

RequestConfig (io.fabric8.kubernetes.client.RequestConfig)11 Config (io.fabric8.kubernetes.client.Config)5 RequestConfigBuilder (io.fabric8.kubernetes.client.RequestConfigBuilder)5 Test (org.junit.Test)5 File (java.io.File)3 OkHttpClient (okhttp3.OkHttpClient)3 List (java.util.List)2 Tracing (brave.Tracing)1 HttpTracing (brave.http.HttpTracing)1 TracingInterceptor (brave.okhttp3.TracingInterceptor)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 Lists (com.google.common.collect.Lists)1 InstrumentedOkHttpClients (com.raskasa.metrics.okhttp.InstrumentedOkHttpClients)1 KubernetesClientHealthCheck (io.dropwizard.kubernetes.health.KubernetesClientHealthCheck)1 DispatcherFactory (io.dropwizard.kubernetes.http.dispatcher.DispatcherFactory)1 BackwardsCompatibilityInterceptorFactory (io.dropwizard.kubernetes.http.interceptor.BackwardsCompatibilityInterceptorFactory)1 InterceptorFactory (io.dropwizard.kubernetes.http.interceptor.InterceptorFactory)1 LoggingNetworkInterceptorFactory (io.dropwizard.kubernetes.http.networkinterceptor.LoggingNetworkInterceptorFactory)1 NetworkInterceptorFactory (io.dropwizard.kubernetes.http.networkinterceptor.NetworkInterceptorFactory)1