Skip to content

Commit

Permalink
fix(config): ConfigBuilder.autoConfig is considered when instantiatin…
Browse files Browse the repository at this point in the history
…g new Config

`Config`'s autoConfigure field should behave as per expectations. We
need to make changes to ConfigBuilder and ConfigFluent in order to
achieve this.
- Add a new Constructor with additional boolean arguments `autoConfigure` and
  `shouldSetDefaultValues`
- Add a new class `SundrioConfig` that would extend `Config` for
  generating the Sundrio Builder for Config
- Move generated classes `ConfigBuilder` and `ConfigFluent` to `src/main/java`
  - `ConfigBuilder` would extend generated SundrioConfigBuilder and
    override the `build()` method by calling `disableAutoConfig()` if
    `autoConfigure` is nto provided by the user. Earlier `ConfigBuidler` was calling `new Config()`
    (this was enabling auto configuration)
- Make all fields in Config class use boxed types instead of primitive
  types so that we can distinguish whether they have been configured by
  user.

Signed-off-by: Rohan Kumar <[email protected]>

(cherry picked from commit 08b0e9f)
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
rohanKanojia authored and manusa committed Aug 9, 2024
1 parent 487826e commit 710a8a2
Show file tree
Hide file tree
Showing 13 changed files with 1,792 additions and 160 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#### Bugs
* Fix #6066: Added support for missing `v1.APIVersions` in KubernetesClient
* Fix #6110: VolumeSource (and other file mode fields) in Octal are correctly interpreted
* Fix #6137: `ConfigBuilder.withAutoConfigure` is not working
* Fix #6197: JettyHttp client error handling improvements.
* Fix #6215: Suppressing rejected execution exception for port forwarder
* Fix #6212: Improved reliability of file upload to Pod
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.kubernetes.client;

import io.fabric8.kubernetes.api.builder.VisitableBuilder;

import java.util.Optional;

import static io.fabric8.kubernetes.client.Config.disableAutoConfig;

public class ConfigBuilder extends ConfigFluent<ConfigBuilder> implements VisitableBuilder<Config, ConfigBuilder> {
public ConfigBuilder() {
this.fluent = this;
}

public ConfigBuilder(ConfigFluent<?> fluent) {
this.fluent = fluent;
}

public ConfigBuilder(ConfigFluent<?> fluent, Config instance) {
this.fluent = fluent;
fluent.copyInstance(instance);
}

public ConfigBuilder(Config instance) {
this.fluent = this;
this.copyInstance(instance);
}

ConfigFluent<?> fluent;

public Config build() {
Config buildable = new Config(fluent.getMasterUrl(), fluent.getApiVersion(), fluent.getNamespace(), fluent.getTrustCerts(),
fluent.getDisableHostnameVerification(), fluent.getCaCertFile(), fluent.getCaCertData(), fluent.getClientCertFile(),
fluent.getClientCertData(), fluent.getClientKeyFile(), fluent.getClientKeyData(), fluent.getClientKeyAlgo(),
fluent.getClientKeyPassphrase(), fluent.getUsername(), fluent.getPassword(), fluent.getOauthToken(),
fluent.getAutoOAuthToken(), fluent.getWatchReconnectInterval(), fluent.getWatchReconnectLimit(),
fluent.getConnectionTimeout(), fluent.getRequestTimeout(), fluent.getScaleTimeout(), fluent.getLoggingInterval(),
fluent.getMaxConcurrentRequests(), fluent.getMaxConcurrentRequestsPerHost(), fluent.getHttp2Disable(),
fluent.getHttpProxy(), fluent.getHttpsProxy(), fluent.getNoProxy(), fluent.getUserAgent(), fluent.getTlsVersions(),
fluent.getWebsocketPingInterval(), fluent.getProxyUsername(), fluent.getProxyPassword(), fluent.getTrustStoreFile(),
fluent.getTrustStorePassphrase(), fluent.getKeyStoreFile(), fluent.getKeyStorePassphrase(),
fluent.getImpersonateUsername(), fluent.getImpersonateGroups(), fluent.getImpersonateExtras(),
fluent.getOauthTokenProvider(), fluent.getCustomHeaders(), fluent.getRequestRetryBackoffLimit(),
fluent.getRequestRetryBackoffInterval(), fluent.getUploadRequestTimeout(), fluent.getOnlyHttpWatches(),
fluent.getCurrentContext(), fluent.getContexts(),
Optional.ofNullable(fluent.getAutoConfigure()).orElse(!disableAutoConfig()), true);
buildable.setAuthProvider(fluent.getAuthProvider());
buildable.setFile(fluent.getFile());
return buildable;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.kubernetes.client;

public class ConfigFluent<A extends ConfigFluent<A>> extends SundrioConfigFluent<A> {
public ConfigFluent() {
super();
}

public ConfigFluent(Config instance) {
super();
this.copyInstance(instance);
}

public void copyInstance(Config instance) {
if (instance != null) {
this.withMasterUrl(instance.getMasterUrl());
this.withApiVersion(instance.getApiVersion());
this.withNamespace(instance.getNamespace());
this.withTrustCerts(instance.isTrustCerts());
this.withDisableHostnameVerification(instance.isDisableHostnameVerification());
this.withCaCertFile(instance.getCaCertFile());
this.withCaCertData(instance.getCaCertData());
this.withClientCertFile(instance.getClientCertFile());
this.withClientCertData(instance.getClientCertData());
this.withClientKeyFile(instance.getClientKeyFile());
this.withClientKeyData(instance.getClientKeyData());
this.withClientKeyAlgo(instance.getClientKeyAlgo());
this.withClientKeyPassphrase(instance.getClientKeyPassphrase());
this.withUsername(instance.getUsername());
this.withPassword(instance.getPassword());
this.withOauthToken(instance.getOauthToken());
this.withAutoOAuthToken(instance.getAutoOAuthToken());
this.withWatchReconnectInterval(instance.getWatchReconnectInterval());
this.withWatchReconnectLimit(instance.getWatchReconnectLimit());
this.withConnectionTimeout(instance.getConnectionTimeout());
this.withRequestTimeout(instance.getRequestTimeout());
this.withScaleTimeout(instance.getScaleTimeout());
this.withLoggingInterval(instance.getLoggingInterval());
this.withMaxConcurrentRequests(instance.getMaxConcurrentRequests());
this.withMaxConcurrentRequestsPerHost(instance.getMaxConcurrentRequestsPerHost());
this.withHttp2Disable(instance.isHttp2Disable());
this.withHttpProxy(instance.getHttpProxy());
this.withHttpsProxy(instance.getHttpsProxy());
this.withNoProxy(instance.getNoProxy());
this.withUserAgent(instance.getUserAgent());
this.withTlsVersions(instance.getTlsVersions());
this.withWebsocketPingInterval(instance.getWebsocketPingInterval());
this.withProxyUsername(instance.getProxyUsername());
this.withProxyPassword(instance.getProxyPassword());
this.withTrustStoreFile(instance.getTrustStoreFile());
this.withTrustStorePassphrase(instance.getTrustStorePassphrase());
this.withKeyStoreFile(instance.getKeyStoreFile());
this.withKeyStorePassphrase(instance.getKeyStorePassphrase());
this.withImpersonateUsername(instance.getImpersonateUsername());
this.withImpersonateGroups(instance.getImpersonateGroups());
this.withImpersonateExtras(instance.getImpersonateExtras());
this.withOauthTokenProvider(instance.getOauthTokenProvider());
this.withCustomHeaders(instance.getCustomHeaders());
this.withRequestRetryBackoffLimit(instance.getRequestRetryBackoffLimit());
this.withRequestRetryBackoffInterval(instance.getRequestRetryBackoffInterval());
this.withUploadRequestTimeout(instance.getUploadRequestTimeout());
this.withOnlyHttpWatches(instance.isOnlyHttpWatches());
this.withCurrentContext(instance.getCurrentContext());
this.withContexts(instance.getContexts());
this.withAutoConfigure(instance.getAutoConfigure());
this.withAuthProvider(instance.getAuthProvider());
this.withFile(instance.getFile());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ public class RequestConfig {
private String[] impersonateGroups = new String[0];

private Map<String, List<String>> impersonateExtras = new HashMap<>();
private int watchReconnectInterval = 1000;
private int watchReconnectLimit = -1;
private int uploadRequestTimeout = DEFAULT_UPLOAD_REQUEST_TIMEOUT;
private int requestRetryBackoffLimit = DEFAULT_REQUEST_RETRY_BACKOFFLIMIT;
private int requestRetryBackoffInterval = DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL;
private int requestTimeout = DEFAULT_REQUEST_TIMEOUT;
private long scaleTimeout = DEFAULT_SCALE_TIMEOUT;
private int loggingInterval = DEFAULT_LOGGING_INTERVAL;
private Integer watchReconnectInterval = 1000;
private Integer watchReconnectLimit = -1;
private Integer uploadRequestTimeout = DEFAULT_UPLOAD_REQUEST_TIMEOUT;
private Integer requestRetryBackoffLimit = DEFAULT_REQUEST_RETRY_BACKOFFLIMIT;
private Integer requestRetryBackoffInterval = DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL;
private Integer requestTimeout = DEFAULT_REQUEST_TIMEOUT;
private Long scaleTimeout = DEFAULT_SCALE_TIMEOUT;
private Integer loggingInterval = DEFAULT_LOGGING_INTERVAL;

RequestConfig() {
}

@Buildable(builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false)
public RequestConfig(int watchReconnectLimit, int watchReconnectInterval, int requestTimeout,
long scaleTimeout, int loggingInterval, int requestRetryBackoffLimit,
int requestRetryBackoffInterval, int uploadRequestTimeout) {
public RequestConfig(Integer watchReconnectLimit, Integer watchReconnectInterval, Integer requestTimeout,
Long scaleTimeout, Integer loggingInterval, Integer requestRetryBackoffLimit,
Integer requestRetryBackoffInterval, Integer uploadRequestTimeout) {
this.watchReconnectLimit = watchReconnectLimit;
this.watchReconnectInterval = watchReconnectInterval;
this.requestTimeout = requestTimeout;
Expand All @@ -63,67 +63,67 @@ public RequestConfig(int watchReconnectLimit, int watchReconnectInterval, int re
this.uploadRequestTimeout = uploadRequestTimeout;
}

public int getWatchReconnectInterval() {
public Integer getWatchReconnectInterval() {
return watchReconnectInterval;
}

public void setWatchReconnectInterval(int watchReconnectInterval) {
public void setWatchReconnectInterval(Integer watchReconnectInterval) {
this.watchReconnectInterval = watchReconnectInterval;
}

public int getWatchReconnectLimit() {
public Integer getWatchReconnectLimit() {
return watchReconnectLimit;
}

public void setWatchReconnectLimit(int watchReconnectLimit) {
public void setWatchReconnectLimit(Integer watchReconnectLimit) {
this.watchReconnectLimit = watchReconnectLimit;
}

public int getRequestTimeout() {
public Integer getRequestTimeout() {
return requestTimeout;
}

public void setRequestTimeout(int requestTimeout) {
public void setRequestTimeout(Integer requestTimeout) {
this.requestTimeout = requestTimeout;
}

public int getRequestRetryBackoffLimit() {
public Integer getRequestRetryBackoffLimit() {
return requestRetryBackoffLimit;
}

public void setRequestRetryBackoffLimit(int requestRetryBackoffLimit) {
public void setRequestRetryBackoffLimit(Integer requestRetryBackoffLimit) {
this.requestRetryBackoffLimit = requestRetryBackoffLimit;
}

public int getRequestRetryBackoffInterval() {
public Integer getRequestRetryBackoffInterval() {
return requestRetryBackoffInterval;
}

public void setRequestRetryBackoffInterval(int requestRetryBackoffInterval) {
public void setRequestRetryBackoffInterval(Integer requestRetryBackoffInterval) {
this.requestRetryBackoffInterval = requestRetryBackoffInterval;
}

public int getUploadRequestTimeout() {
public Integer getUploadRequestTimeout() {
return uploadRequestTimeout;
}

public void setUploadRequestTimeout(int uploadRequestTimeout) {
public void setUploadRequestTimeout(Integer uploadRequestTimeout) {
this.uploadRequestTimeout = uploadRequestTimeout;
}

public long getScaleTimeout() {
public Long getScaleTimeout() {
return scaleTimeout;
}

public void setScaleTimeout(long scaleTimeout) {
public void setScaleTimeout(Long scaleTimeout) {
this.scaleTimeout = scaleTimeout;
}

public int getLoggingInterval() {
public Integer getLoggingInterval() {
return loggingInterval;
}

public void setLoggingInterval(int loggingInterval) {
public void setLoggingInterval(Integer loggingInterval) {
this.loggingInterval = loggingInterval;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.kubernetes.client;

import io.fabric8.kubernetes.api.model.NamedContext;
import io.fabric8.kubernetes.client.http.TlsVersion;
import io.sundr.builder.annotations.Buildable;

import java.util.List;
import java.util.Map;

/**
* This class is necessary to be able to autogenerate a builder for the Config class using Sundrio while providing
* specific behavior for the build() method.
*
* This way we can extend the default SundrioConfigBuilder, overriding the build method and enabling autoconfiguration only in
* this case.
*
* The builder is also capable of having a state of the Config with null values (no defaults or autoconfigured).
*
* The end purpose is for users to actually use the builder to override the default values or autoconfigured ones
* by providing their values through the builder withXxx accessors
*/
class SundrioConfig extends Config {
@Buildable(builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false)
public SundrioConfig(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, String autoOAuthToken, Integer watchReconnectInterval, Integer watchReconnectLimit,
Integer connectionTimeout,
Integer requestTimeout,
Long scaleTimeout, Integer loggingInterval, Integer maxConcurrentRequests, Integer maxConcurrentRequestsPerHost,
Boolean http2Disable, String httpProxy, String httpsProxy, String[] noProxy,
String userAgent, TlsVersion[] tlsVersions, 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, Integer requestRetryBackoffLimit,
Integer requestRetryBackoffInterval, Integer uploadRequestTimeout, Boolean onlyHttpWatches, NamedContext currentContext,
List<NamedContext> contexts, Boolean autoConfigure) {
super(masterUrl, apiVersion, namespace, trustCerts, disableHostnameVerification, caCertFile, caCertData,
clientCertFile, clientCertData, clientKeyFile, clientKeyData, clientKeyAlgo, clientKeyPassphrase, username,
password, oauthToken, autoOAuthToken, watchReconnectInterval, watchReconnectLimit, connectionTimeout, requestTimeout,
scaleTimeout, loggingInterval, maxConcurrentRequests, maxConcurrentRequestsPerHost, http2Disable,
httpProxy, httpsProxy, noProxy, userAgent, tlsVersions, websocketPingInterval, proxyUsername, proxyPassword,
trustStoreFile, trustStorePassphrase, keyStoreFile, keyStorePassphrase, impersonateUsername, impersonateGroups,
impersonateExtras, oauthTokenProvider, customHeaders, requestRetryBackoffLimit, requestRetryBackoffInterval,
uploadRequestTimeout, onlyHttpWatches, currentContext, contexts, autoConfigure, true);
}
}
Loading

0 comments on commit 710a8a2

Please sign in to comment.