Skip to content

Commit 6debf29

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

File tree

11 files changed

+508
-937
lines changed

11 files changed

+508
-937
lines changed

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

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

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

Lines changed: 21 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,19 @@ 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+
SundrioConfig config = toSundrioConfig(fluent);
58+
return new Config(config, true);
59+
}
60+
61+
public static SundrioConfig toSundrioConfig(SundrioConfigFluent<?> fluent) {
62+
SundrioConfigBuilder builder = new SundrioConfigBuilder();
63+
builder.fluent = fluent;
64+
SundrioConfig config = builder.build();
65+
config.setAutoConfigure(Optional.ofNullable(config.getAutoConfigure()).orElse(!disableAutoConfig()));
66+
return config;
6367
}
6468
}

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

0 commit comments

Comments
 (0)