-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(config): ConfigBuilder.autoConfig is considered when instantiatin…
…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]>
- Loading branch information
1 parent
d91de12
commit 08b0e9f
Showing
13 changed files
with
1,214 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
429 changes: 318 additions & 111 deletions
429
kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java
Large diffs are not rendered by default.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/ConfigBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/ConfigFluent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/SundrioConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.