diff --git a/CHANGELOG.md b/CHANGELOG.md index fa0c4cfea4f..e017a71ff9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### 6.7-SNAPSHOT #### Bugs +Fix #5121: RequestConfig is propagated to derived HttpClient instances #### Improvements diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/LogWatchCallback.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/LogWatchCallback.java index aa108fefd6b..2ca97a9289f 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/LogWatchCallback.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/LogWatchCallback.java @@ -16,6 +16,7 @@ package io.fabric8.kubernetes.client.dsl.internal; import io.fabric8.kubernetes.client.KubernetesClientException; +import io.fabric8.kubernetes.client.RequestConfigBuilder; import io.fabric8.kubernetes.client.dsl.LogWatch; import io.fabric8.kubernetes.client.http.AsyncBody; import io.fabric8.kubernetes.client.http.HttpClient; @@ -31,8 +32,8 @@ import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.WritableByteChannel; +import java.util.Optional; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -40,20 +41,22 @@ public class LogWatchCallback implements LogWatch, AutoCloseable { private static final Logger LOGGER = LoggerFactory.getLogger(LogWatchCallback.class); - private OutputStream out; + private final OutputStream out; private WritableByteChannel outChannel; + private final OperationContext context; private volatile InputStream output; private final AtomicBoolean closed = new AtomicBoolean(false); private final CompletableFuture asyncBody = new CompletableFuture<>(); private final SerialExecutor serialExecutor; - public LogWatchCallback(OutputStream out, Executor executor) { + public LogWatchCallback(OutputStream out, OperationContext context) { this.out = out; if (out != null) { outChannel = Channels.newChannel(out); } - this.serialExecutor = new SerialExecutor(executor); + this.context = context; + this.serialExecutor = new SerialExecutor(context.getExecutor()); } @Override @@ -71,7 +74,10 @@ private void cleanUp() { public LogWatchCallback callAndWait(HttpClient client, URL url) { HttpRequest request = client.newHttpRequestBuilder().url(url).build(); - HttpClient clone = client.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build(); + HttpClient clone = client.newBuilder() + .tag(Optional.ofNullable(context.getRequestConfig()).map(RequestConfigBuilder::new).orElse(new RequestConfigBuilder()) + .withRequestTimeout(0).build()) + .readTimeout(0, TimeUnit.MILLISECONDS).build(); if (out == null) { // we can pass the input stream directly to the consumer diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchConnectionManager.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchConnectionManager.java index af19ebae7a4..64f4b20a673 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchConnectionManager.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchConnectionManager.java @@ -20,6 +20,7 @@ import io.fabric8.kubernetes.api.model.ListOptions; import io.fabric8.kubernetes.api.model.Status; import io.fabric8.kubernetes.client.KubernetesClientException; +import io.fabric8.kubernetes.client.RequestConfigBuilder; import io.fabric8.kubernetes.client.Watcher; import io.fabric8.kubernetes.client.http.HttpClient; import io.fabric8.kubernetes.client.http.HttpResponse; @@ -72,6 +73,7 @@ public WatchConnectionManager(final HttpClient client, final BaseOperation watcher, final int reconnectInterval, final int reconnectLimit, long websocketTimeout) throws MalformedURLException { super(watcher, baseOperation, listOptions, reconnectLimit, reconnectInterval, () -> client.newBuilder() + .tag(new RequestConfigBuilder(baseOperation.getRequestConfig()).withRequestTimeout(0).build()) .readTimeout(websocketTimeout, TimeUnit.MILLISECONDS) .build()); } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchHTTPManager.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchHTTPManager.java index eca91132b19..d1d3b685ef5 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchHTTPManager.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchHTTPManager.java @@ -18,6 +18,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.KubernetesResourceList; import io.fabric8.kubernetes.api.model.ListOptions; +import io.fabric8.kubernetes.client.RequestConfigBuilder; import io.fabric8.kubernetes.client.Watcher; import io.fabric8.kubernetes.client.http.AsyncBody; import io.fabric8.kubernetes.client.http.HttpClient; @@ -48,6 +49,7 @@ public WatchHTTPManager(final HttpClient client, super( watcher, baseOperation, listOptions, reconnectLimit, reconnectInterval, () -> client.newBuilder() + .tag(new RequestConfigBuilder(baseOperation.getRequestConfig()).withRequestTimeout(0).build()) .readTimeout(0, TimeUnit.MILLISECONDS) .forStreaming() .build()); diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/core/v1/PodOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/core/v1/PodOperationsImpl.java index 3f7606ce14d..f090cff2c5b 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/core/v1/PodOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/core/v1/PodOperationsImpl.java @@ -28,6 +28,7 @@ import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.LocalPortForward; import io.fabric8.kubernetes.client.PortForward; +import io.fabric8.kubernetes.client.RequestConfigBuilder; import io.fabric8.kubernetes.client.dsl.BytesLimitTerminateTimeTailPrettyLoggable; import io.fabric8.kubernetes.client.dsl.CopyOrReadable; import io.fabric8.kubernetes.client.dsl.EphemeralContainersResource; @@ -97,7 +98,7 @@ public class PodOperationsImpl extends HasMetadataOperation containers, Strin } private ExecWebSocketListener setupConnectionToPod(URI uri) { - HttpClient clone = httpClient.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build(); + HttpClient clone = httpClient.newBuilder() + .tag(new RequestConfigBuilder(getRequestConfig()).withRequestTimeout(0).build()) + .readTimeout(0, TimeUnit.MILLISECONDS) + .build(); ExecWebSocketListener execWebSocketListener = new ExecWebSocketListener(getContext(), this.context.getExecutor()); CompletableFuture startedFuture = clone.newWebSocketBuilder() .subprotocol("v4.channel.k8s.io") diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/apps/DeploymentConfigOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/apps/DeploymentConfigOperationsImpl.java index 4078b7ecb0c..acf001796da 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/apps/DeploymentConfigOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/apps/DeploymentConfigOperationsImpl.java @@ -140,7 +140,7 @@ public LogWatch watchLog(OutputStream out) { // In case of DeploymentConfig we directly get logs at DeploymentConfig Url, but we need to wait for Pods waitUntilDeploymentConfigPodBecomesReady(get()); URL url = getResourceLogUrl(true); - final LogWatchCallback callback = new LogWatchCallback(out, this.context.getExecutor()); + final LogWatchCallback callback = new LogWatchCallback(out, context); return callback.callAndWait(this.httpClient, url); } catch (Throwable t) { throw KubernetesClientException.launderThrowable(forOperationType("watchLog"), t); diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/build/BuildConfigOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/build/BuildConfigOperationsImpl.java index 18cb47873fe..fb8eaa66b75 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/build/BuildConfigOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/build/BuildConfigOperationsImpl.java @@ -261,6 +261,7 @@ public Typeable> withSecret(String secret) { protected Build submitToApiServer(InputStream inputStream, long contentLength) { try { HttpClient newClient = this.httpClient.newBuilder() + .tag(getOperationContext().getRequestConfig()) .readTimeout(getOperationContext().getTimeout(), getOperationContext().getTimeoutUnit()) .writeTimeout(getOperationContext().getTimeout(), getOperationContext().getTimeoutUnit()) .build(); diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/build/BuildOperationsImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/build/BuildOperationsImpl.java index 8b9ebab38e1..40e5dfaaf96 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/build/BuildOperationsImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/dsl/internal/build/BuildOperationsImpl.java @@ -134,7 +134,7 @@ public LogWatch watchLog(OutputStream out) { // In case of Build we directly get logs at Build Url, but we need to wait for Pods waitUntilBuildPodBecomesReady(get()); URL url = new URL(URLUtils.join(getResourceUrl().toString(), getLogParameters() + "&follow=true")); - final LogWatchCallback callback = new LogWatchCallback(out, this.context.getExecutor()); + final LogWatchCallback callback = new LogWatchCallback(out, context); return callback.callAndWait(this.httpClient, url); } catch (IOException t) { throw KubernetesClientException.launderThrowable(forOperationType("watchLog"), t); diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/impl/OpenShiftClientImpl.java b/openshift-client/src/main/java/io/fabric8/openshift/client/impl/OpenShiftClientImpl.java index 347e3d99915..53d6811345b 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/impl/OpenShiftClientImpl.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/impl/OpenShiftClientImpl.java @@ -699,8 +699,10 @@ public boolean supportsOpenShiftAPIGroup(String apiGroup) { protected void setDerivedFields() { OpenShiftConfig wrapped = OpenShiftConfig.wrap(config); this.config = wrapped; - HttpClient.DerivedClientBuilder builder = httpClient.newBuilder().authenticatorNone(); + HttpClient.DerivedClientBuilder builder = httpClient.newBuilder(); this.httpClient = builder + .authenticatorNone() + .tag(config.getRequestConfig()) .addOrReplaceInterceptor(TokenRefreshInterceptor.NAME, new OpenShiftOAuthInterceptor(httpClient, wrapped)) .build(); diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/internal/OpenShiftOAuthInterceptor.java b/openshift-client/src/main/java/io/fabric8/openshift/client/internal/OpenShiftOAuthInterceptor.java index 81f073ef5bb..bcd331daf61 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/internal/OpenShiftOAuthInterceptor.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/internal/OpenShiftOAuthInterceptor.java @@ -138,6 +138,7 @@ private boolean setAuthHeader(BasicBuilder builder, String token) { private CompletableFuture authorize() { HttpClient.DerivedClientBuilder builder = client.newBuilder(); + builder.tag(config.getRequestConfig()); builder.addOrReplaceInterceptor(TokenRefreshInterceptor.NAME, null); HttpClient clone = builder.build(); diff --git a/openshift-client/src/test/java/io/fabric8/openshift/client/dsl/internal/build/BuildConfigOperationsImplTest.java b/openshift-client/src/test/java/io/fabric8/openshift/client/dsl/internal/build/BuildConfigOperationsImplTest.java index 6a38bafb298..498c0803398 100644 --- a/openshift-client/src/test/java/io/fabric8/openshift/client/dsl/internal/build/BuildConfigOperationsImplTest.java +++ b/openshift-client/src/test/java/io/fabric8/openshift/client/dsl/internal/build/BuildConfigOperationsImplTest.java @@ -55,6 +55,7 @@ public void setUp() { when(response.uri()).thenReturn(URI.create("https://localhost:8443/")); when(httpClient.newBuilder() + .tag(any()) .readTimeout(anyLong(), any()) .writeTimeout(anyLong(), any()) .build()).thenReturn(httpClient);