Skip to content

Commit 08b0e9f

Browse files
authored
fix(config): ConfigBuilder.autoConfig is considered when instantiating 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]>
1 parent d91de12 commit 08b0e9f

File tree

13 files changed

+1214
-160
lines changed

13 files changed

+1214
-160
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#### Bugs
66
* Fix #6038: Support for Gradle configuration cache
77
* Fix #6110: VolumeSource (and other file mode fields) in Octal are correctly interpreted
8+
* Fix #6137: `ConfigBuilder.withAutoConfigure` is not working
89
* Fix #6215: Suppressing rejected execution exception for port forwarder
910
* Fix #6197: JettyHttp client error handling improvements.
1011

kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java

Lines changed: 318 additions & 111 deletions
Large diffs are not rendered by default.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.kubernetes.client;
17+
18+
import io.fabric8.kubernetes.api.builder.VisitableBuilder;
19+
20+
import java.util.Optional;
21+
22+
import static io.fabric8.kubernetes.client.Config.disableAutoConfig;
23+
24+
public class ConfigBuilder extends ConfigFluent<ConfigBuilder> implements VisitableBuilder<Config, ConfigBuilder> {
25+
public ConfigBuilder() {
26+
this.fluent = this;
27+
}
28+
29+
public ConfigBuilder(ConfigFluent<?> fluent) {
30+
this.fluent = fluent;
31+
}
32+
33+
public ConfigBuilder(ConfigFluent<?> fluent, Config instance) {
34+
this.fluent = fluent;
35+
fluent.copyInstance(instance);
36+
}
37+
38+
public ConfigBuilder(Config instance) {
39+
this.fluent = this;
40+
this.copyInstance(instance);
41+
}
42+
43+
ConfigFluent<?> fluent;
44+
45+
public Config build() {
46+
Config buildable = new Config(fluent.getMasterUrl(), fluent.getApiVersion(), fluent.getNamespace(), fluent.getTrustCerts(),
47+
fluent.getDisableHostnameVerification(), fluent.getCaCertFile(), fluent.getCaCertData(), fluent.getClientCertFile(),
48+
fluent.getClientCertData(), fluent.getClientKeyFile(), fluent.getClientKeyData(), fluent.getClientKeyAlgo(),
49+
fluent.getClientKeyPassphrase(), fluent.getUsername(), fluent.getPassword(), fluent.getOauthToken(),
50+
fluent.getAutoOAuthToken(), fluent.getWatchReconnectInterval(), fluent.getWatchReconnectLimit(),
51+
fluent.getConnectionTimeout(), fluent.getRequestTimeout(), fluent.getScaleTimeout(), fluent.getLoggingInterval(),
52+
fluent.getMaxConcurrentRequests(), fluent.getMaxConcurrentRequestsPerHost(), fluent.getHttp2Disable(),
53+
fluent.getHttpProxy(), fluent.getHttpsProxy(), fluent.getNoProxy(), fluent.getUserAgent(), fluent.getTlsVersions(),
54+
fluent.getWebsocketPingInterval(), fluent.getProxyUsername(), fluent.getProxyPassword(), fluent.getTrustStoreFile(),
55+
fluent.getTrustStorePassphrase(), fluent.getKeyStoreFile(), fluent.getKeyStorePassphrase(),
56+
fluent.getImpersonateUsername(), fluent.getImpersonateGroups(), fluent.getImpersonateExtras(),
57+
fluent.getOauthTokenProvider(), fluent.getCustomHeaders(), fluent.getRequestRetryBackoffLimit(),
58+
fluent.getRequestRetryBackoffInterval(), fluent.getUploadRequestTimeout(), fluent.getOnlyHttpWatches(),
59+
fluent.getCurrentContext(), fluent.getContexts(),
60+
Optional.ofNullable(fluent.getAutoConfigure()).orElse(!disableAutoConfig()), true);
61+
buildable.setAuthProvider(fluent.getAuthProvider());
62+
buildable.setFile(fluent.getFile());
63+
return buildable;
64+
}
65+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.kubernetes.client;
17+
18+
public class ConfigFluent<A extends ConfigFluent<A>> extends SundrioConfigFluent<A> {
19+
public ConfigFluent() {
20+
super();
21+
}
22+
23+
public ConfigFluent(Config instance) {
24+
super();
25+
this.copyInstance(instance);
26+
}
27+
28+
public void copyInstance(Config instance) {
29+
if (instance != null) {
30+
this.withMasterUrl(instance.getMasterUrl());
31+
this.withApiVersion(instance.getApiVersion());
32+
this.withNamespace(instance.getNamespace());
33+
this.withTrustCerts(instance.isTrustCerts());
34+
this.withDisableHostnameVerification(instance.isDisableHostnameVerification());
35+
this.withCaCertFile(instance.getCaCertFile());
36+
this.withCaCertData(instance.getCaCertData());
37+
this.withClientCertFile(instance.getClientCertFile());
38+
this.withClientCertData(instance.getClientCertData());
39+
this.withClientKeyFile(instance.getClientKeyFile());
40+
this.withClientKeyData(instance.getClientKeyData());
41+
this.withClientKeyAlgo(instance.getClientKeyAlgo());
42+
this.withClientKeyPassphrase(instance.getClientKeyPassphrase());
43+
this.withUsername(instance.getUsername());
44+
this.withPassword(instance.getPassword());
45+
this.withOauthToken(instance.getOauthToken());
46+
this.withAutoOAuthToken(instance.getAutoOAuthToken());
47+
this.withWatchReconnectInterval(instance.getWatchReconnectInterval());
48+
this.withWatchReconnectLimit(instance.getWatchReconnectLimit());
49+
this.withConnectionTimeout(instance.getConnectionTimeout());
50+
this.withRequestTimeout(instance.getRequestTimeout());
51+
this.withScaleTimeout(instance.getScaleTimeout());
52+
this.withLoggingInterval(instance.getLoggingInterval());
53+
this.withMaxConcurrentRequests(instance.getMaxConcurrentRequests());
54+
this.withMaxConcurrentRequestsPerHost(instance.getMaxConcurrentRequestsPerHost());
55+
this.withHttp2Disable(instance.isHttp2Disable());
56+
this.withHttpProxy(instance.getHttpProxy());
57+
this.withHttpsProxy(instance.getHttpsProxy());
58+
this.withNoProxy(instance.getNoProxy());
59+
this.withUserAgent(instance.getUserAgent());
60+
this.withTlsVersions(instance.getTlsVersions());
61+
this.withWebsocketPingInterval(instance.getWebsocketPingInterval());
62+
this.withProxyUsername(instance.getProxyUsername());
63+
this.withProxyPassword(instance.getProxyPassword());
64+
this.withTrustStoreFile(instance.getTrustStoreFile());
65+
this.withTrustStorePassphrase(instance.getTrustStorePassphrase());
66+
this.withKeyStoreFile(instance.getKeyStoreFile());
67+
this.withKeyStorePassphrase(instance.getKeyStorePassphrase());
68+
this.withImpersonateUsername(instance.getImpersonateUsername());
69+
this.withImpersonateGroups(instance.getImpersonateGroups());
70+
this.withImpersonateExtras(instance.getImpersonateExtras());
71+
this.withOauthTokenProvider(instance.getOauthTokenProvider());
72+
this.withCustomHeaders(instance.getCustomHeaders());
73+
this.withRequestRetryBackoffLimit(instance.getRequestRetryBackoffLimit());
74+
this.withRequestRetryBackoffInterval(instance.getRequestRetryBackoffInterval());
75+
this.withUploadRequestTimeout(instance.getUploadRequestTimeout());
76+
this.withOnlyHttpWatches(instance.isOnlyHttpWatches());
77+
this.withCurrentContext(instance.getCurrentContext());
78+
this.withContexts(instance.getContexts());
79+
this.withAutoConfigure(instance.getAutoConfigure());
80+
this.withAuthProvider(instance.getAuthProvider());
81+
this.withFile(instance.getFile());
82+
}
83+
}
84+
}

kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/RequestConfig.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@ public class RequestConfig {
3737
private String[] impersonateGroups = new String[0];
3838

3939
private Map<String, List<String>> impersonateExtras = new HashMap<>();
40-
private int watchReconnectInterval = 1000;
41-
private int watchReconnectLimit = -1;
42-
private int uploadRequestTimeout = DEFAULT_UPLOAD_REQUEST_TIMEOUT;
43-
private int requestRetryBackoffLimit = DEFAULT_REQUEST_RETRY_BACKOFFLIMIT;
44-
private int requestRetryBackoffInterval = DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL;
45-
private int requestTimeout = DEFAULT_REQUEST_TIMEOUT;
46-
private long scaleTimeout = DEFAULT_SCALE_TIMEOUT;
47-
private int loggingInterval = DEFAULT_LOGGING_INTERVAL;
40+
private Integer watchReconnectInterval = 1000;
41+
private Integer watchReconnectLimit = -1;
42+
private Integer uploadRequestTimeout = DEFAULT_UPLOAD_REQUEST_TIMEOUT;
43+
private Integer requestRetryBackoffLimit = DEFAULT_REQUEST_RETRY_BACKOFFLIMIT;
44+
private Integer requestRetryBackoffInterval = DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL;
45+
private Integer requestTimeout = DEFAULT_REQUEST_TIMEOUT;
46+
private Long scaleTimeout = DEFAULT_SCALE_TIMEOUT;
47+
private Integer loggingInterval = DEFAULT_LOGGING_INTERVAL;
4848

4949
RequestConfig() {
5050
}
5151

5252
@Buildable(builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false)
53-
public RequestConfig(int watchReconnectLimit, int watchReconnectInterval, int requestTimeout,
54-
long scaleTimeout, int loggingInterval, int requestRetryBackoffLimit,
55-
int requestRetryBackoffInterval, int uploadRequestTimeout) {
53+
public RequestConfig(Integer watchReconnectLimit, Integer watchReconnectInterval, Integer requestTimeout,
54+
Long scaleTimeout, Integer loggingInterval, Integer requestRetryBackoffLimit,
55+
Integer requestRetryBackoffInterval, Integer uploadRequestTimeout) {
5656
this.watchReconnectLimit = watchReconnectLimit;
5757
this.watchReconnectInterval = watchReconnectInterval;
5858
this.requestTimeout = requestTimeout;
@@ -63,67 +63,67 @@ public RequestConfig(int watchReconnectLimit, int watchReconnectInterval, int re
6363
this.uploadRequestTimeout = uploadRequestTimeout;
6464
}
6565

66-
public int getWatchReconnectInterval() {
66+
public Integer getWatchReconnectInterval() {
6767
return watchReconnectInterval;
6868
}
6969

70-
public void setWatchReconnectInterval(int watchReconnectInterval) {
70+
public void setWatchReconnectInterval(Integer watchReconnectInterval) {
7171
this.watchReconnectInterval = watchReconnectInterval;
7272
}
7373

74-
public int getWatchReconnectLimit() {
74+
public Integer getWatchReconnectLimit() {
7575
return watchReconnectLimit;
7676
}
7777

78-
public void setWatchReconnectLimit(int watchReconnectLimit) {
78+
public void setWatchReconnectLimit(Integer watchReconnectLimit) {
7979
this.watchReconnectLimit = watchReconnectLimit;
8080
}
8181

82-
public int getRequestTimeout() {
82+
public Integer getRequestTimeout() {
8383
return requestTimeout;
8484
}
8585

86-
public void setRequestTimeout(int requestTimeout) {
86+
public void setRequestTimeout(Integer requestTimeout) {
8787
this.requestTimeout = requestTimeout;
8888
}
8989

90-
public int getRequestRetryBackoffLimit() {
90+
public Integer getRequestRetryBackoffLimit() {
9191
return requestRetryBackoffLimit;
9292
}
9393

94-
public void setRequestRetryBackoffLimit(int requestRetryBackoffLimit) {
94+
public void setRequestRetryBackoffLimit(Integer requestRetryBackoffLimit) {
9595
this.requestRetryBackoffLimit = requestRetryBackoffLimit;
9696
}
9797

98-
public int getRequestRetryBackoffInterval() {
98+
public Integer getRequestRetryBackoffInterval() {
9999
return requestRetryBackoffInterval;
100100
}
101101

102-
public void setRequestRetryBackoffInterval(int requestRetryBackoffInterval) {
102+
public void setRequestRetryBackoffInterval(Integer requestRetryBackoffInterval) {
103103
this.requestRetryBackoffInterval = requestRetryBackoffInterval;
104104
}
105105

106-
public int getUploadRequestTimeout() {
106+
public Integer getUploadRequestTimeout() {
107107
return uploadRequestTimeout;
108108
}
109109

110-
public void setUploadRequestTimeout(int uploadRequestTimeout) {
110+
public void setUploadRequestTimeout(Integer uploadRequestTimeout) {
111111
this.uploadRequestTimeout = uploadRequestTimeout;
112112
}
113113

114-
public long getScaleTimeout() {
114+
public Long getScaleTimeout() {
115115
return scaleTimeout;
116116
}
117117

118-
public void setScaleTimeout(long scaleTimeout) {
118+
public void setScaleTimeout(Long scaleTimeout) {
119119
this.scaleTimeout = scaleTimeout;
120120
}
121121

122-
public int getLoggingInterval() {
122+
public Integer getLoggingInterval() {
123123
return loggingInterval;
124124
}
125125

126-
public void setLoggingInterval(int loggingInterval) {
126+
public void setLoggingInterval(Integer loggingInterval) {
127127
this.loggingInterval = loggingInterval;
128128
}
129129

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.fabric8.kubernetes.client;
17+
18+
import io.fabric8.kubernetes.api.model.NamedContext;
19+
import io.fabric8.kubernetes.client.http.TlsVersion;
20+
import io.sundr.builder.annotations.Buildable;
21+
22+
import java.util.List;
23+
import java.util.Map;
24+
25+
/**
26+
* This class is necessary to be able to autogenerate a builder for the Config class using Sundrio while providing
27+
* specific behavior for the build() method.
28+
*
29+
* This way we can extend the default SundrioConfigBuilder, overriding the build method and enabling autoconfiguration only in
30+
* this case.
31+
*
32+
* The builder is also capable of having a state of the Config with null values (no defaults or autoconfigured).
33+
*
34+
* The end purpose is for users to actually use the builder to override the default values or autoconfigured ones
35+
* by providing their values through the builder withXxx accessors
36+
*/
37+
class SundrioConfig extends Config {
38+
@Buildable(builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false)
39+
public SundrioConfig(String masterUrl, String apiVersion, String namespace, Boolean trustCerts,
40+
Boolean disableHostnameVerification,
41+
String caCertFile, String caCertData, String clientCertFile, String clientCertData, String clientKeyFile,
42+
String clientKeyData, String clientKeyAlgo, String clientKeyPassphrase, String username, String password,
43+
String oauthToken, String autoOAuthToken, Integer watchReconnectInterval, Integer watchReconnectLimit,
44+
Integer connectionTimeout,
45+
Integer requestTimeout,
46+
Long scaleTimeout, Integer loggingInterval, Integer maxConcurrentRequests, Integer maxConcurrentRequestsPerHost,
47+
Boolean http2Disable, String httpProxy, String httpsProxy, String[] noProxy,
48+
String userAgent, TlsVersion[] tlsVersions, Long websocketPingInterval, String proxyUsername,
49+
String proxyPassword, String trustStoreFile, String trustStorePassphrase, String keyStoreFile, String keyStorePassphrase,
50+
String impersonateUsername, String[] impersonateGroups, Map<String, List<String>> impersonateExtras,
51+
OAuthTokenProvider oauthTokenProvider, Map<String, String> customHeaders, Integer requestRetryBackoffLimit,
52+
Integer requestRetryBackoffInterval, Integer uploadRequestTimeout, Boolean onlyHttpWatches, NamedContext currentContext,
53+
List<NamedContext> contexts, Boolean autoConfigure) {
54+
super(masterUrl, apiVersion, namespace, trustCerts, disableHostnameVerification, caCertFile, caCertData,
55+
clientCertFile, clientCertData, clientKeyFile, clientKeyData, clientKeyAlgo, clientKeyPassphrase, username,
56+
password, oauthToken, autoOAuthToken, watchReconnectInterval, watchReconnectLimit, connectionTimeout, requestTimeout,
57+
scaleTimeout, loggingInterval, maxConcurrentRequests, maxConcurrentRequestsPerHost, http2Disable,
58+
httpProxy, httpsProxy, noProxy, userAgent, tlsVersions, websocketPingInterval, proxyUsername, proxyPassword,
59+
trustStoreFile, trustStorePassphrase, keyStoreFile, keyStorePassphrase, impersonateUsername, impersonateGroups,
60+
impersonateExtras, oauthTokenProvider, customHeaders, requestRetryBackoffLimit, requestRetryBackoffInterval,
61+
uploadRequestTimeout, onlyHttpWatches, currentContext, contexts, autoConfigure, true);
62+
}
63+
}

0 commit comments

Comments
 (0)