Skip to content

Commit 61153af

Browse files
committed
rationalizing Config constructors / building
Signed-off-by: Steve Hawkins <[email protected]>
1 parent b40a155 commit 61153af

File tree

10 files changed

+467
-927
lines changed

10 files changed

+467
-927
lines changed

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

Lines changed: 150 additions & 644 deletions
Large diffs are not rendered by default.

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@
2222
import static io.fabric8.kubernetes.client.Config.disableAutoConfig;
2323

2424
public class ConfigBuilder extends ConfigFluent<ConfigBuilder> implements VisitableBuilder<Config, ConfigBuilder> {
25+
/**
26+
* Note: differs from the typical generated builder - the fluent state is
27+
* preserved whole
28+
*/
2529
public ConfigBuilder() {
2630
this.fluent = this;
2731
}
2832

33+
/**
34+
* Note: differs from the typical generated builder - the fluent state is
35+
* preserved whole
36+
*/
2937
public ConfigBuilder(ConfigFluent<?> fluent) {
3038
this.fluent = fluent;
3139
}
@@ -42,23 +50,14 @@ public ConfigBuilder(Config instance) {
4250

4351
ConfigFluent<?> fluent;
4452

53+
@Override
4554
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-
return buildable;
55+
// build the config state from the generated builder, then use that
56+
// to construct the full state
57+
SundrioConfigBuilder builder = new SundrioConfigBuilder();
58+
builder.fluent = fluent;
59+
SundrioConfig config = builder.build();
60+
config.setAutoConfigure(Optional.ofNullable(config.getAutoConfigure()).orElse(!disableAutoConfig()));
61+
return new Config(config, true);
6362
}
6463
}

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

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,60 +25,9 @@ public ConfigFluent(Config instance) {
2525
this.copyInstance(instance);
2626
}
2727

28+
// no need to override the base logic
2829
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-
}
30+
super.copyInstance(instance);
8231
}
8332

8433
// Fix #https://github.com/fabric8io/kubernetes-client/issues/6249

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

Lines changed: 129 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,29 @@
1515
*/
1616
package io.fabric8.kubernetes.client;
1717

18+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
19+
import com.fasterxml.jackson.annotation.JsonAnySetter;
20+
import com.fasterxml.jackson.annotation.JsonIgnore;
21+
import com.fasterxml.jackson.annotation.JsonInclude;
22+
import io.fabric8.kubernetes.api.model.AuthProviderConfig;
1823
import io.fabric8.kubernetes.api.model.NamedContext;
1924
import io.fabric8.kubernetes.client.http.TlsVersion;
2025
import io.sundr.builder.annotations.Buildable;
26+
import lombok.Data;
2127

28+
import java.util.HashMap;
2229
import java.util.List;
2330
import java.util.Map;
2431

2532
/**
26-
* This class is necessary to be able to autogenerate a builder for the Config class using Sundrio while providing
33+
*
34+
* To add a new config option:
35+
* <li>add a field in this class. Adding getters / setters is optional
36+
* <li>add logic in the {@link Config} constructor to copy the field. Optionally add auto configuration logic.
37+
* <li>no other changes are typically necessary
38+
*
39+
* This class is necessary to be able to cleanly deserialize the config.
40+
* It is also used to autogenerate a builder for the Config class using Sundrio while providing
2741
* specific behavior for the build() method.
2842
*
2943
* This way we can extend the default SundrioConfigBuilder, overriding the build method and enabling autoconfiguration only in
@@ -34,30 +48,119 @@
3448
* The end purpose is for users to actually use the builder to override the default values or autoconfigured ones
3549
* by providing their values through the builder withXxx accessors
3650
*/
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);
51+
@Buildable(lazyCollectionInitEnabled = false, lazyMapInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false
52+
/* , ignore = "additionalProperties" */)
53+
@SuppressWarnings({ "LombokGetterMayBeUsed", "LombokSetterMayBeUsed" })
54+
@JsonInclude(JsonInclude.Include.NON_NULL)
55+
@Data
56+
public class SundrioConfig {
57+
58+
protected Boolean trustCerts;
59+
protected Boolean disableHostnameVerification;
60+
protected String masterUrl;
61+
protected String apiVersion;
62+
protected String namespace;
63+
protected Boolean defaultNamespace;
64+
protected String caCertFile;
65+
protected String caCertData;
66+
protected String clientCertFile;
67+
protected String clientCertData;
68+
protected String clientKeyFile;
69+
protected String clientKeyData;
70+
protected String clientKeyAlgo;
71+
protected String clientKeyPassphrase;
72+
protected String trustStoreFile;
73+
protected String trustStorePassphrase;
74+
protected String keyStoreFile;
75+
protected String keyStorePassphrase;
76+
protected AuthProviderConfig authProvider;
77+
protected String username;
78+
protected String password;
79+
protected volatile String oauthToken;
80+
@JsonIgnore
81+
protected volatile String autoOAuthToken;
82+
@JsonIgnore
83+
protected OAuthTokenProvider oauthTokenProvider;
84+
protected Long websocketPingInterval;
85+
protected Integer connectionTimeout;
86+
protected Integer maxConcurrentRequests;
87+
protected Integer maxConcurrentRequestsPerHost;
88+
89+
protected List<NamedContext> contexts;
90+
protected NamedContext currentContext;
91+
92+
protected Integer watchReconnectInterval;
93+
protected Integer watchReconnectLimit;
94+
protected Integer uploadRequestTimeout;
95+
protected Integer requestRetryBackoffLimit;
96+
protected Integer requestRetryBackoffInterval;
97+
protected Integer requestTimeout;
98+
protected Long scaleTimeout;
99+
protected Integer loggingInterval;
100+
protected String impersonateUsername;
101+
protected String[] impersonateGroups;
102+
protected Map<String, List<String>> impersonateExtras;
103+
104+
protected Boolean http2Disable;
105+
protected String httpProxy;
106+
protected String httpsProxy;
107+
protected String proxyUsername;
108+
protected String proxyPassword;
109+
protected String[] noProxy;
110+
protected String userAgent;
111+
protected TlsVersion[] tlsVersions;
112+
113+
protected Boolean onlyHttpWatches;
114+
115+
/**
116+
* custom headers
117+
*/
118+
protected Map<String, String> customHeaders;
119+
120+
protected Boolean autoConfigure;
121+
122+
@JsonIgnore
123+
protected Map<String, Object> additionalProperties = new HashMap<>();
124+
125+
@JsonAnyGetter
126+
public Map<String, Object> getAdditionalProperties() {
127+
return this.additionalProperties;
62128
}
129+
130+
@JsonAnySetter
131+
public void setAdditionalProperty(String name, Object value) {
132+
this.additionalProperties.put(name, value);
133+
}
134+
135+
/*
136+
* Begin specific overrides for getters / setters
137+
* Only needed if changing the default signature, adding javadocs, etc.
138+
*/
139+
140+
public void setImpersonateGroups(String... impersonateGroup) {
141+
this.impersonateGroups = impersonateGroup;
142+
}
143+
144+
/**
145+
* Returns all the {@link NamedContext}s that exist in the kube config
146+
*
147+
* @return all the contexts
148+
*
149+
* @see NamedContext
150+
*/
151+
public List<NamedContext> getContexts() {
152+
return contexts;
153+
}
154+
155+
/**
156+
* Returns the current context that's defined in the kube config. Returns {@code null} if there's none
157+
*
158+
* @return the current context
159+
*
160+
* @see NamedContext
161+
*/
162+
public NamedContext getCurrentContext() {
163+
return currentContext;
164+
}
165+
63166
}

0 commit comments

Comments
 (0)