Skip to content

Commit

Permalink
Merge pull request #4837 from shawkins/iss4708
Browse files Browse the repository at this point in the history
fix #4708 refining what is possible via the requestconfig
  • Loading branch information
manusa committed Feb 22, 2023
2 parents 2f7d77a + f12e14b commit b83927f
Show file tree
Hide file tree
Showing 47 changed files with 348 additions and 545 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
* Fix #4758: added support for pod ephemeral container operations

#### _**Note**_: Breaking changes
* Fix #4708: The signature of the Interceptor methods changed to pass the full HttpRequest, rather than just the headers, and explicitly pass request tags - in particular the RequestConfig. To simplify authentication concerns the following fields have been removed from RequestConfig: username, password, oauthToken, and oauthTokenProvider. Not all HttpClient implementation support setting the connectionTimeout at a request level, thus it was removed from the RequestConfig as well.
* Fix #4659: The SupportTestingClient interface has been deprecated. Please use one of the supports methods or getApiGroup to determine what is available on the api server.
* Fix #4825: removed or deprecated/moved methods that are unrelated to the rolling timeout from ImageEditReplacePatchable. Deprecated rollout methods for timeout and edit - future versions will not support
* Fix #4826: removed RequestConfig upload connection and rolling timeouts. Both were no longer used with no plans to re-introduce their usage.

### 6.4.1 (2023-01-31)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import io.fabric8.kubernetes.client.http.BasicBuilder;
import io.fabric8.kubernetes.client.http.HttpClient;
import io.fabric8.kubernetes.client.http.HttpHeaders;
import io.fabric8.kubernetes.client.http.HttpRequest;
import io.fabric8.kubernetes.client.http.Interceptor;
import io.fabric8.kubernetes.client.http.StandardHttpClientBuilder;
import io.fabric8.kubernetes.client.http.TlsVersion;
Expand Down Expand Up @@ -71,7 +71,7 @@ public HttpClient build() {
this.interceptors.put("PROXY-AUTH", new Interceptor() {

@Override
public void before(BasicBuilder builder, HttpHeaders headers) {
public void before(BasicBuilder builder, HttpRequest httpRequest, RequestTags tags) {
builder.setHeader("Proxy-Authorization", proxyAuthorization);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.nio.ByteBuffer;
import java.util.Collections;
Expand Down Expand Up @@ -245,7 +247,15 @@ public OkHttpClientImpl(OkHttpClient client, OkHttpClientBuilderImpl builder) {

@Override
public void close() {
LOG.debug("Shutting down dispatcher " + this.httpClient.dispatcher(), new Exception());
if (LOG.isDebugEnabled()) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
new Exception().printStackTrace(printWriter);
printWriter.close();
String stack = writer.toString();
stack = stack.substring(stack.indexOf("\n"));
LOG.debug("Shutting down dispatcher {} at the following call stack: {}", this.httpClient.dispatcher(), stack);
}
ConnectionPool connectionPool = httpClient.connectionPool();
Dispatcher dispatcher = httpClient.dispatcher();
ExecutorService executorService = httpClient.dispatcher() != null ? httpClient.dispatcher().executorService() : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ default <T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperat

/**
* Creates a new client based upon the current except with a different
* {@link RequestConfig}. This client will use independent resources,
* and should be closed appropriately
* {@link RequestConfig}. It uses the same resources as the current client, thus
* closing it will close the original client.
*
* @param requestConfig
* @return a new client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ public class Config {
public static final String KUBERNETES_WATCH_RECONNECT_INTERVAL_SYSTEM_PROPERTY = "kubernetes.watch.reconnectInterval";
public static final String KUBERNETES_WATCH_RECONNECT_LIMIT_SYSTEM_PROPERTY = "kubernetes.watch.reconnectLimit";
public static final String KUBERNETES_CONNECTION_TIMEOUT_SYSTEM_PROPERTY = "kubernetes.connection.timeout";
public static final String KUBERNETES_UPLOAD_CONNECTION_TIMEOUT_SYSTEM_PROPERTY = "kubernetes.upload.connection.timeout";
public static final String KUBERNETES_UPLOAD_REQUEST_TIMEOUT_SYSTEM_PROPERTY = "kubernetes.upload.request.timeout";
public static final String KUBERNETES_REQUEST_TIMEOUT_SYSTEM_PROPERTY = "kubernetes.request.timeout";
public static final String KUBERNETES_REQUEST_RETRY_BACKOFFLIMIT_SYSTEM_PROPERTY = "kubernetes.request.retry.backoffLimit";
public static final String KUBERNETES_REQUEST_RETRY_BACKOFFINTERVAL_SYSTEM_PROPERTY = "kubernetes.request.retry.backoffInterval";
public static final String KUBERNETES_ROLLING_TIMEOUT_SYSTEM_PROPERTY = "kubernetes.rolling.timeout";
public static final String KUBERNETES_LOGGING_INTERVAL_SYSTEM_PROPERTY = "kubernetes.logging.interval";
public static final String KUBERNETES_SCALE_TIMEOUT_SYSTEM_PROPERTY = "kubernetes.scale.timeout";
public static final String KUBERNETES_WEBSOCKET_TIMEOUT_SYSTEM_PROPERTY = "kubernetes.websocket.timeout";
Expand Down Expand Up @@ -135,7 +133,6 @@ public class Config {
public static final String KUBERNETES_USER_AGENT = "kubernetes.user.agent";

public static final String DEFAULT_MASTER_URL = "https://kubernetes.default.svc";
public static final Long DEFAULT_ROLLING_TIMEOUT = 15 * 60 * 1000L;
public static final Long DEFAULT_SCALE_TIMEOUT = 10 * 60 * 1000L;
public static final int DEFAULT_LOGGING_INTERVAL = 20 * 1000;
public static final Long DEFAULT_WEBSOCKET_TIMEOUT = 5 * 1000L;
Expand All @@ -147,7 +144,6 @@ public class Config {
public static final Integer DEFAULT_REQUEST_RETRY_BACKOFFLIMIT = 10;
public static final Integer DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL = 100;

public static final int DEFAULT_UPLOAD_CONNECTION_TIMEOUT = 10 * 1000;
public static final int DEFAULT_UPLOAD_REQUEST_TIMEOUT = 120 * 1000;

public static final String HTTP_PROTOCOL_PREFIX = "http://";
Expand Down Expand Up @@ -175,6 +171,14 @@ public class Config {
private String keyStoreFile;
private String keyStorePassphrase;
private AuthProviderConfig authProvider;
private String username;
private String password;
private volatile String oauthToken;
private OAuthTokenProvider oauthTokenProvider;
private long websocketPingInterval = DEFAULT_WEBSOCKET_PING_INTERVAL;
private int connectionTimeout = 10 * 1000;
private int maxConcurrentRequests = DEFAULT_MAX_CONCURRENT_REQUESTS;
private int maxConcurrentRequestsPerHost = DEFAULT_MAX_CONCURRENT_REQUESTS_PER_HOST;

private RequestConfig requestConfig = new RequestConfig();

Expand All @@ -184,26 +188,16 @@ public class Config {
/**
* fields not used but needed for builder generation.
*/
private String username;
private String password;
private String oauthToken;
private int watchReconnectInterval = 1000;
private int watchReconnectLimit = -1;
private int connectionTimeout = 10 * 1000;
private int uploadConnectionTimeout = DEFAULT_UPLOAD_CONNECTION_TIMEOUT;
private int uploadRequestTimeout = DEFAULT_UPLOAD_REQUEST_TIMEOUT;
private int requestRetryBackoffLimit;
private int requestRetryBackoffInterval;
private int requestTimeout = 10 * 1000;
private long rollingTimeout = DEFAULT_ROLLING_TIMEOUT;
private long scaleTimeout = DEFAULT_SCALE_TIMEOUT;
private int loggingInterval = DEFAULT_LOGGING_INTERVAL;
private long websocketTimeout = DEFAULT_WEBSOCKET_TIMEOUT;
private long websocketPingInterval = DEFAULT_WEBSOCKET_PING_INTERVAL;
private int maxConcurrentRequests = DEFAULT_MAX_CONCURRENT_REQUESTS;
private int maxConcurrentRequestsPerHost = DEFAULT_MAX_CONCURRENT_REQUESTS_PER_HOST;
private String impersonateUsername;
private OAuthTokenProvider oauthTokenProvider;

/**
* @deprecated use impersonateGroups instead
Expand Down Expand Up @@ -331,26 +325,26 @@ public Config(String masterUrl, String apiVersion, String namespace, boolean tru
String impersonateUsername, String[] impersonateGroups, Map<String, List<String>> impersonateExtras) {
this(masterUrl, apiVersion, namespace, trustCerts, disableHostnameVerification, caCertFile, caCertData, clientCertFile,
clientCertData, clientKeyFile, clientKeyData, clientKeyAlgo, clientKeyPassphrase, username, password, oauthToken,
watchReconnectInterval, watchReconnectLimit, connectionTimeout, requestTimeout, rollingTimeout, scaleTimeout,
watchReconnectInterval, watchReconnectLimit, connectionTimeout, requestTimeout, scaleTimeout,
loggingInterval, maxConcurrentRequests, maxConcurrentRequestsPerHost, false, httpProxy, httpsProxy, noProxy,
errorMessages, userAgent, tlsVersions, websocketTimeout, websocketPingInterval, proxyUsername, proxyPassword,
trustStoreFile, trustStorePassphrase, keyStoreFile, keyStorePassphrase, impersonateUsername, impersonateGroups,
impersonateExtras, null, null, DEFAULT_REQUEST_RETRY_BACKOFFLIMIT, DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL,
DEFAULT_UPLOAD_CONNECTION_TIMEOUT, DEFAULT_UPLOAD_REQUEST_TIMEOUT);
DEFAULT_UPLOAD_REQUEST_TIMEOUT);
}

@Buildable(builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false)
public Config(String masterUrl, String apiVersion, String namespace, boolean trustCerts, boolean disableHostnameVerification,
String caCertFile, String caCertData, String clientCertFile, String clientCertData, String clientKeyFile,
String clientKeyData, String clientKeyAlgo, String clientKeyPassphrase, String username, String password,
String oauthToken, int watchReconnectInterval, int watchReconnectLimit, int connectionTimeout, int requestTimeout,
long rollingTimeout, long scaleTimeout, int loggingInterval, int maxConcurrentRequests, int maxConcurrentRequestsPerHost,
long scaleTimeout, int loggingInterval, int maxConcurrentRequests, int maxConcurrentRequestsPerHost,
boolean http2Disable, String httpProxy, String httpsProxy, String[] noProxy, Map<Integer, String> errorMessages,
String userAgent, TlsVersion[] tlsVersions, long websocketTimeout, long websocketPingInterval, String proxyUsername,
String proxyPassword, String trustStoreFile, String trustStorePassphrase, String keyStoreFile, String keyStorePassphrase,
String impersonateUsername, String[] impersonateGroups, Map<String, List<String>> impersonateExtras,
OAuthTokenProvider oauthTokenProvider, Map<String, String> customHeaders, int requestRetryBackoffLimit,
int requestRetryBackoffInterval, int uploadConnectionTimeout, int uploadRequestTimeout) {
int requestRetryBackoffInterval, int uploadRequestTimeout) {
this.apiVersion = apiVersion;
this.namespace = namespace;
this.trustCerts = trustCerts;
Expand All @@ -363,11 +357,15 @@ public Config(String masterUrl, String apiVersion, String namespace, boolean tru
this.clientKeyData = clientKeyData;
this.clientKeyAlgo = clientKeyAlgo;
this.clientKeyPassphrase = clientKeyPassphrase;

this.requestConfig = new RequestConfig(username, password, oauthToken, watchReconnectLimit, watchReconnectInterval,
connectionTimeout, rollingTimeout, requestTimeout, scaleTimeout, loggingInterval, websocketTimeout,
websocketPingInterval, oauthTokenProvider,
requestRetryBackoffLimit, requestRetryBackoffInterval, uploadConnectionTimeout, uploadRequestTimeout);
this.username = username;
this.password = password;
this.oauthToken = oauthToken;
this.websocketPingInterval = websocketPingInterval;
this.connectionTimeout = connectionTimeout;

this.requestConfig = new RequestConfig(watchReconnectLimit, watchReconnectInterval,
requestTimeout, scaleTimeout, loggingInterval, websocketTimeout,
requestRetryBackoffLimit, requestRetryBackoffInterval, uploadRequestTimeout);
this.requestConfig.setImpersonateUsername(impersonateUsername);
this.requestConfig.setImpersonateGroups(impersonateGroups);
this.requestConfig.setImpersonateExtras(impersonateExtras);
Expand Down Expand Up @@ -451,12 +449,6 @@ public static void configFromSysPropsOrEnvVars(Config config) {
config.setWatchReconnectLimit(Integer.parseInt(configuredWatchReconnectLimit));
}

String configuredRollingTimeout = Utils.getSystemPropertyOrEnvVar(KUBERNETES_ROLLING_TIMEOUT_SYSTEM_PROPERTY,
String.valueOf(DEFAULT_ROLLING_TIMEOUT));
if (configuredRollingTimeout != null) {
config.setRollingTimeout(Long.parseLong(configuredRollingTimeout));
}

String configuredScaleTimeout = Utils.getSystemPropertyOrEnvVar(KUBERNETES_SCALE_TIMEOUT_SYSTEM_PROPERTY,
String.valueOf(DEFAULT_SCALE_TIMEOUT));
if (configuredScaleTimeout != null) {
Expand All @@ -471,8 +463,6 @@ public static void configFromSysPropsOrEnvVars(Config config) {

config.setConnectionTimeout(
Utils.getSystemPropertyOrEnvVar(KUBERNETES_CONNECTION_TIMEOUT_SYSTEM_PROPERTY, config.getConnectionTimeout()));
config.setUploadConnectionTimeout(Utils.getSystemPropertyOrEnvVar(KUBERNETES_UPLOAD_CONNECTION_TIMEOUT_SYSTEM_PROPERTY,
config.getUploadConnectionTimeout()));
config.setUploadRequestTimeout(
Utils.getSystemPropertyOrEnvVar(KUBERNETES_UPLOAD_REQUEST_TIMEOUT_SYSTEM_PROPERTY, config.getUploadRequestTimeout()));
config.setRequestTimeout(
Expand Down Expand Up @@ -969,29 +959,32 @@ public static String getKeyAlgorithm(String clientKeyFile, String clientKeyData)

@JsonProperty("oauthToken")
public String getOauthToken() {
return getRequestConfig().getOauthToken();
if (this.oauthTokenProvider != null) {
return this.oauthTokenProvider.getToken();
}
return oauthToken;
}

public void setOauthToken(String oauthToken) {
this.requestConfig.setOauthToken(oauthToken);
this.oauthToken = oauthToken;
}

@JsonProperty("password")
public String getPassword() {
return getRequestConfig().getPassword();
return password;
}

public void setPassword(String password) {
this.requestConfig.setPassword(password);
this.password = password;
}

@JsonProperty("username")
public String getUsername() {
return getRequestConfig().getUsername();
return username;
}

public void setUsername(String username) {
this.requestConfig.setUsername(username);
this.username = username;
}

@JsonProperty("impersonateUsername")
Expand Down Expand Up @@ -1164,20 +1157,11 @@ public static ConfigBuilder builder() {

@JsonProperty("connectionTimeout")
public int getConnectionTimeout() {
return getRequestConfig().getConnectionTimeout();
return connectionTimeout;
}

public void setConnectionTimeout(int connectionTimeout) {
this.requestConfig.setConnectionTimeout(connectionTimeout);
}

@JsonProperty("uploadConnectionTimeout")
public int getUploadConnectionTimeout() {
return getRequestConfig().getUploadConnectionTimeout();
}

public void setUploadConnectionTimeout(int connectionTimeout) {
this.requestConfig.setUploadConnectionTimeout(connectionTimeout);
this.connectionTimeout = connectionTimeout;
}

@JsonProperty("uploadRequestTimeout")
Expand Down Expand Up @@ -1216,15 +1200,6 @@ public void setRequestRetryBackoffInterval(int requestRetryBackoffInterval) {
requestConfig.setRequestRetryBackoffInterval(requestRetryBackoffInterval);
}

@JsonProperty("rollingTimeout")
public long getRollingTimeout() {
return getRequestConfig().getRollingTimeout();
}

public void setRollingTimeout(long rollingTimeout) {
this.requestConfig.setRollingTimeout(rollingTimeout);
}

@JsonProperty("scaleTimeout")
public long getScaleTimeout() {
return getRequestConfig().getScaleTimeout();
Expand Down Expand Up @@ -1326,11 +1301,11 @@ public void setWebsocketTimeout(long websocketTimeout) {

@JsonProperty("websocketPingInterval")
public long getWebsocketPingInterval() {
return getRequestConfig().getWebsocketPingInterval();
return websocketPingInterval;
}

public void setWebsocketPingInterval(long websocketPingInterval) {
this.requestConfig.setWebsocketPingInterval(websocketPingInterval);
this.websocketPingInterval = websocketPingInterval;
}

public int getMaxConcurrentRequests() {
Expand Down Expand Up @@ -1371,10 +1346,6 @@ public RequestConfig getRequestConfig() {
return this.requestConfig;
}

public static void setRequestConfig(Config config, RequestConfig requestConfig) {
config.requestConfig = requestConfig;
}

public void setTrustStorePassphrase(String trustStorePassphrase) {
this.trustStorePassphrase = trustStorePassphrase;
}
Expand Down Expand Up @@ -1413,11 +1384,11 @@ public String getKeyStoreFile() {

@JsonIgnore
public OAuthTokenProvider getOauthTokenProvider() {
return this.getRequestConfig().getOauthTokenProvider();
return this.oauthTokenProvider;
}

public void setOauthTokenProvider(OAuthTokenProvider oauthTokenProvider) {
this.requestConfig.setOauthTokenProvider(oauthTokenProvider);
this.oauthTokenProvider = oauthTokenProvider;
}

@JsonProperty("customHeaders")
Expand Down
Loading

0 comments on commit b83927f

Please sign in to comment.