Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@
import static io.fabric8.kubernetes.client.Config.disableAutoConfig;

public class ConfigBuilder extends ConfigFluent<ConfigBuilder> implements VisitableBuilder<Config, ConfigBuilder> {
/**
* Note: differs from the typical generated builder - the fluent state is
* preserved whole
*/
public ConfigBuilder() {
this.fluent = this;
}

/**
* Note: differs from the typical generated builder - the fluent state is
* preserved whole
*/
public ConfigBuilder(ConfigFluent<?> fluent) {
this.fluent = fluent;
}
Expand All @@ -42,23 +50,19 @@ public ConfigBuilder(Config instance) {

ConfigFluent<?> fluent;

@Override
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());
return buildable;
// build the config state from the generated builder, then use that
// to construct the full state
SundrioConfig config = toSundrioConfig(fluent);
return new Config(config, true);
}

public static SundrioConfig toSundrioConfig(SundrioConfigFluent<?> fluent) {
SundrioConfigBuilder builder = new SundrioConfigBuilder();
builder.fluent = fluent;
SundrioConfig config = builder.build();
config.setAutoConfigure(Optional.ofNullable(config.getAutoConfigure()).orElse(!disableAutoConfig()));
return config;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,60 +25,9 @@ public ConfigFluent(Config instance) {
this.copyInstance(instance);
}

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

// Fix #https://github.com/fabric8io/kubernetes-client/issues/6249
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,31 @@
*/
package io.fabric8.kubernetes.client;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.fabric8.kubernetes.api.model.AuthProviderConfig;
import io.fabric8.kubernetes.api.model.NamedContext;
import io.fabric8.kubernetes.client.http.TlsVersion;
import io.sundr.builder.annotations.Buildable;
import lombok.Data;

import java.util.HashMap;
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
*
* To add a new config option:
* <ol>
* <li>add a field in this class. Adding getters / setters is optional
* <li>add logic in the {@link Config} constructor to copy the field. Optionally add auto configuration logic.
* <li>no other changes are typically necessary
* </ol>
*
* This class is necessary to be able to cleanly deserialize the config.
* It is also used 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
Expand All @@ -34,30 +50,119 @@
* 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);
@Buildable(lazyCollectionInitEnabled = false, lazyMapInitEnabled = false, builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false
/* , ignore = "additionalProperties" */)
@SuppressWarnings({ "LombokGetterMayBeUsed", "LombokSetterMayBeUsed" })
@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
public class SundrioConfig {

protected Boolean trustCerts;
protected Boolean disableHostnameVerification;
protected String masterUrl;
protected String apiVersion;
protected String namespace;
protected Boolean defaultNamespace;
protected String caCertFile;
protected String caCertData;
protected String clientCertFile;
protected String clientCertData;
protected String clientKeyFile;
protected String clientKeyData;
protected String clientKeyAlgo;
protected String clientKeyPassphrase;
protected String trustStoreFile;
protected String trustStorePassphrase;
protected String keyStoreFile;
protected String keyStorePassphrase;
protected AuthProviderConfig authProvider;
protected String username;
protected String password;
protected volatile String oauthToken;
@JsonIgnore
protected volatile String autoOAuthToken;
@JsonIgnore
protected OAuthTokenProvider oauthTokenProvider;
protected Long websocketPingInterval;
protected Integer connectionTimeout;
protected Integer maxConcurrentRequests;
protected Integer maxConcurrentRequestsPerHost;

protected List<NamedContext> contexts;
protected NamedContext currentContext;

protected Integer watchReconnectInterval;
protected Integer watchReconnectLimit;
protected Integer uploadRequestTimeout;
protected Integer requestRetryBackoffLimit;
protected Integer requestRetryBackoffInterval;
protected Integer requestTimeout;
protected Long scaleTimeout;
protected Integer loggingInterval;
protected String impersonateUsername;
protected String[] impersonateGroups;
protected Map<String, List<String>> impersonateExtras;

protected Boolean http2Disable;
protected String httpProxy;
protected String httpsProxy;
protected String proxyUsername;
protected String proxyPassword;
protected String[] noProxy;
protected String userAgent;
protected TlsVersion[] tlsVersions;

protected Boolean onlyHttpWatches;

/**
* custom headers
*/
protected Map<String, String> customHeaders;

protected Boolean autoConfigure;

@JsonIgnore
protected Map<String, Object> additionalProperties = new HashMap<>();

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

/*
* Begin specific overrides for getters / setters
* Only needed if changing the default signature, adding javadocs, etc.
*/

public void setImpersonateGroups(String... impersonateGroup) {
this.impersonateGroups = impersonateGroup;
}

/**
* Returns all the {@link NamedContext}s that exist in the kube config
*
* @return all the contexts
*
* @see NamedContext
*/
public List<NamedContext> getContexts() {
return contexts;
}

/**
* Returns the current context that's defined in the kube config. Returns {@code null} if there's none
*
* @return the current context
*
* @see NamedContext
*/
public NamedContext getCurrentContext() {
return currentContext;
}

}
Loading
Loading