From f7bba419325fc8a61b75671d50a85527a57986b0 Mon Sep 17 00:00:00 2001 From: Steve Hawkins Date: Fri, 4 Mar 2022 09:06:26 -0500 Subject: [PATCH 1/3] fix #3865: using just a single builder --- doc/MIGRATION-v6.md | 13 +- .../client/BaseKubernetesClientBuilder.java | 75 ----- .../io/fabric8/kubernetes/client/Config.java | 261 ++++++++++++------ .../client/KubernetesClientBuilder.java | 61 +++- .../client/utils/HttpClientUtils.java | 89 +++--- .../client/DefaultKubernetesClient.java | 82 ++++-- .../client/OpenShiftClientBuilder.java | 37 --- .../openshift/client/OpenShiftConfig.java | 169 ++++++------ .../client/DefaultOpenShiftClient.java | 41 ++- 9 files changed, 456 insertions(+), 372 deletions(-) delete mode 100644 kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/BaseKubernetesClientBuilder.java delete mode 100644 openshift-client-api/src/main/java/io/fabric8/openshift/client/OpenShiftClientBuilder.java diff --git a/doc/MIGRATION-v6.md b/doc/MIGRATION-v6.md index 961de8b604c..117b6cbbca8 100644 --- a/doc/MIGRATION-v6.md +++ b/doc/MIGRATION-v6.md @@ -59,7 +59,16 @@ This release introduces kubernetes-client-api and openshift-client-api modules. If you are directly relying on classes in the -client jars other than DefaultKubernetesClient and DefaultOpenShiftClient, please let us know your usage scenario. Moving forward we'd like consider all classes in the -client jars internal. -When you rely solely on a compile dependency to the respective -api dependencies you will not be able to use DefaultKubernetesClient nor DefaultOpenShiftClient directly to create your client instances. You should instead - TBD +When you rely solely on a compile dependency to the respective -api dependencies you will not be able to use DefaultKubernetesClient nor DefaultOpenShiftClient directly to create your client instances. You should instead use KubernetesClientBuilder. Passing a configuration of HttpClient is instead done through builder methods - withConfig and withHttpClientFactory. For example: + + ```java + KubernetesClient client = new KubernetesClientBuilder().build(); + ... + ``` + ```java + OpenShiftClient openShiftClient = new new KubernetesClientBuilder().withConfig(new OpenShiftConfigBuilder()...build()).build().adapt(OpenShiftClient.class); + ... + ``` ### OkHttp HttpClient @@ -87,6 +96,7 @@ The group on the object being deserialized is not required to match the prospect - Removed HttpClientUtils.createHttpClient(final Config config, final Consumer additionalConfig), please use the OkHttpClientFactory instead - Removed methods on SharedInformerFactory dealing with the OperationContext - Removed DefaultKubernetesClient and DefaultOpenShiftClient constructors directly referencing OkHttp - use OkHttpClientImpl to wrap the OkHttpClient, or the OkHttpClientFactory instead. +- Removed OpenShiftConfig OpenshiftApiGroupsEnabled methods ### Extension Development @@ -163,6 +173,7 @@ Client.isAdaptable and Client.adapt will check first if the existing instance is ## Deprecations - ApiVersionUtil classes in each extension have been deprecated, you should use io.fabric8.kubernetes.client.utils.ApiVersionUtil instead. +- HttpClientUtils.createHttpClient has been deprecated, you should create your own client factory instead. - Extension specific EnableXXXMockClient and XXXMockServer classes have been deprecated. You can simply use EnableKubernetesMockClient and KubernetesMockServer instead. Dependencies on the xxx-mock jar are then no longer needed, just a dependency to kubernetes-server-mock. diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/BaseKubernetesClientBuilder.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/BaseKubernetesClientBuilder.java deleted file mode 100644 index 5e280c3792f..00000000000 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/BaseKubernetesClientBuilder.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * 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.client.http.HttpClient; -import io.fabric8.kubernetes.client.utils.Serialization; - -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; - -public class BaseKubernetesClientBuilder> { - - private Config config; - private HttpClient.Factory factory; - private Class clazz; - - protected BaseKubernetesClientBuilder(String className) { - try { - this.clazz = (Class) Class.forName(className); - } catch (ClassNotFoundException e) { - throw KubernetesClientException.launderThrowable(e); - } - } - - public KubernetesClient build() { - if (config == null) { - config = new ConfigBuilder().build(); - } - try { - if (factory == null) { - return clazz.getConstructor(Config.class).newInstance(config); - } - HttpClient client = factory.createHttpClient(config); - return clazz.getConstructor(HttpClient.class, Config.class).newInstance(client, config); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException - | NoSuchMethodException | SecurityException e) { - throw KubernetesClientException.launderThrowable(e); - } - } - - public BaseKubernetesClientBuilder withConfig(Config config) { - this.config = config; - return this; - } - - public BaseKubernetesClientBuilder withConfig(String config) { - this.config = Serialization.unmarshal(config); - return this; - } - - public BaseKubernetesClientBuilder withConfig(InputStream config) { - this.config = Serialization.unmarshal(config); - return this; - } - - public BaseKubernetesClientBuilder withHttpClientFactory(HttpClient.Factory factory) { - this.factory = factory; - return this; - } - -} diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java index 0a7bbbadb88..d4be97aef2d 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java @@ -16,6 +16,8 @@ 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.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; @@ -55,7 +57,7 @@ import java.util.Map; @JsonInclude(JsonInclude.Include.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true, allowGetters = true, allowSetters = true) +@JsonIgnoreProperties(allowGetters = true, allowSetters = true) public class Config { private static final Logger LOGGER = LoggerFactory.getLogger(Config.class); @@ -95,13 +97,12 @@ public class Config { public static final String KUBERNETES_SCALE_TIMEOUT_SYSTEM_PROPERTY = "kubernetes.scale.timeout"; public static final String KUBERNETES_WEBSOCKET_TIMEOUT_SYSTEM_PROPERTY = "kubernetes.websocket.timeout"; public static final String KUBERNETES_WEBSOCKET_PING_INTERVAL_SYSTEM_PROPERTY = "kubernetes.websocket.ping.interval"; - public static final String KUBERNETES_MAX_CONCURRENT_REQUESTS ="kubernetes.max.concurrent.requests"; - public static final String KUBERNETES_MAX_CONCURRENT_REQUESTS_PER_HOST ="kubernetes.max.concurrent.requests.per.host"; + public static final String KUBERNETES_MAX_CONCURRENT_REQUESTS = "kubernetes.max.concurrent.requests"; + public static final String KUBERNETES_MAX_CONCURRENT_REQUESTS_PER_HOST = "kubernetes.max.concurrent.requests.per.host"; public static final String KUBERNETES_IMPERSONATE_USERNAME = "kubernetes.impersonate.username"; public static final String KUBERNETES_IMPERSONATE_GROUP = "kubernetes.impersonate.group"; - public static final String KUBERNETES_TRUSTSTORE_PASSPHRASE_PROPERTY = "kubernetes.truststore.passphrase"; public static final String KUBERNETES_TRUSTSTORE_FILE_PROPERTY = "kubernetes.truststore.file"; public static final String KUBERNETES_KEYSTORE_PASSPHRASE_PROPERTY = "kubernetes.keystore.passphrase"; @@ -126,7 +127,7 @@ public class Config { public static final String KUBERNETES_PROXY_USERNAME = "proxy.username"; public static final String KUBERNETES_PROXY_PASSWORD = "proxy.password"; - public static final String KUBERNETES_USER_AGENT = "fabric8-kubernetes-client/" + Version.clientVersion() ; + public static final String KUBERNETES_USER_AGENT = "fabric8-kubernetes-client/" + Version.clientVersion(); public static final String DEFAULT_MASTER_URL = "https://kubernetes.default.svc"; public static final Long DEFAULT_ROLLING_TIMEOUT = 15 * 60 * 1000L; @@ -200,8 +201,8 @@ public class Config { private OAuthTokenProvider oauthTokenProvider; /** - * @deprecated use impersonateGroups instead - */ + * @deprecated use impersonateGroups instead + */ @Deprecated private String impersonateGroup; private String[] impersonateGroups; @@ -217,19 +218,22 @@ public class Config { private String proxyPassword; private String[] noProxy; private String userAgent; - private TlsVersion[] tlsVersions = new TlsVersion[]{TlsVersion.TLS_1_2}; + private TlsVersion[] tlsVersions = new TlsVersion[] { TlsVersion.TLS_1_2 }; private Map errorMessages = new HashMap<>(); /** * custom headers */ - private Map customHeaders = null; + private Map customHeaders = null; private Boolean autoConfigure = Boolean.FALSE; private File file; + @JsonIgnore + protected Map additionalProperties = new HashMap(); + /** * @deprecated use {@link #autoConfigure(String)} or {@link ConfigBuilder} instead */ @@ -251,11 +255,14 @@ private Config(Boolean autoConfigure) { * You can also reuse this object to build your own {@link Config} object * without any auto configuration like this: * - *
{@code
-   * Config configFromBuilder = new ConfigBuilder(Config.empty())
-   *                                // ...
-   *                               .build();
-   * }
+ *
+   * {
+   *   @code
+   *   Config configFromBuilder = new ConfigBuilder(Config.empty())
+   *       // ...
+   *       .build();
+   * }
+   * 
* * @return a Config object without any automatic configuration */ @@ -296,19 +303,44 @@ private static String ensureEndsWithSlash(String masterUrl) { private static String ensureHttps(String masterUrl, Config config) { if (!masterUrl.toLowerCase(Locale.ROOT).startsWith(HTTP_PROTOCOL_PREFIX) - && !masterUrl.toLowerCase(Locale.ROOT).startsWith(HTTPS_PROTOCOL_PREFIX)) { - masterUrl = (SSLUtils.isHttpsAvailable(config) ? HTTPS_PROTOCOL_PREFIX : HTTP_PROTOCOL_PREFIX) + masterUrl; + && !masterUrl.toLowerCase(Locale.ROOT).startsWith(HTTPS_PROTOCOL_PREFIX)) { + masterUrl = (SSLUtils.isHttpsAvailable(config) ? HTTPS_PROTOCOL_PREFIX : HTTP_PROTOCOL_PREFIX) + masterUrl; } return masterUrl; } @Deprecated - public Config(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, int watchReconnectInterval, int watchReconnectLimit, int connectionTimeout, int requestTimeout, long rollingTimeout, long scaleTimeout, int loggingInterval, int maxConcurrentRequests, int maxConcurrentRequestsPerHost, String httpProxy, String httpsProxy, String[] noProxy, Map errorMessages, String userAgent, TlsVersion[] tlsVersions, long websocketTimeout, long websocketPingInterval, String proxyUsername, String proxyPassword, String trustStoreFile, String trustStorePassphrase, String keyStoreFile, String keyStorePassphrase, String impersonateUsername, String[] impersonateGroups, Map> impersonateExtras) { - this(masterUrl, apiVersion, namespace, trustCerts, disableHostnameVerification, caCertFile, caCertData, clientCertFile, clientCertData, clientKeyFile, clientKeyData, clientKeyAlgo, clientKeyPassphrase, username, password, oauthToken, watchReconnectInterval, watchReconnectLimit, connectionTimeout, requestTimeout, rollingTimeout, scaleTimeout, loggingInterval, maxConcurrentRequests, maxConcurrentRequestsPerHost, false, httpProxy, httpsProxy, noProxy, errorMessages, userAgent, tlsVersions, websocketTimeout, websocketPingInterval, proxyUsername, proxyPassword, trustStoreFile, trustStorePassphrase, keyStoreFile, keyStorePassphrase, impersonateUsername, impersonateGroups, impersonateExtras, null,null, DEFAULT_REQUEST_RETRY_BACKOFFLIMIT, DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL, DEFAULT_UPLOAD_CONNECTION_TIMEOUT, DEFAULT_UPLOAD_REQUEST_TIMEOUT); + public Config(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, int watchReconnectInterval, int watchReconnectLimit, int connectionTimeout, int requestTimeout, + long rollingTimeout, long scaleTimeout, int loggingInterval, int maxConcurrentRequests, int maxConcurrentRequestsPerHost, + String httpProxy, String httpsProxy, String[] noProxy, Map errorMessages, String userAgent, + TlsVersion[] tlsVersions, long websocketTimeout, long websocketPingInterval, String proxyUsername, String proxyPassword, + String trustStoreFile, String trustStorePassphrase, String keyStoreFile, String keyStorePassphrase, + String impersonateUsername, String[] impersonateGroups, Map> impersonateExtras) { + this(masterUrl, apiVersion, namespace, trustCerts, disableHostnameVerification, caCertFile, caCertData, clientCertFile, + clientCertData, clientKeyFile, clientKeyData, clientKeyAlgo, clientKeyPassphrase, username, password, oauthToken, + watchReconnectInterval, watchReconnectLimit, connectionTimeout, requestTimeout, rollingTimeout, scaleTimeout, + loggingInterval, maxConcurrentRequests, maxConcurrentRequestsPerHost, false, httpProxy, httpsProxy, noProxy, + errorMessages, userAgent, tlsVersions, websocketTimeout, websocketPingInterval, proxyUsername, proxyPassword, + trustStoreFile, trustStorePassphrase, keyStoreFile, keyStorePassphrase, impersonateUsername, impersonateGroups, + impersonateExtras, null, null, DEFAULT_REQUEST_RETRY_BACKOFFLIMIT, DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL, + DEFAULT_UPLOAD_CONNECTION_TIMEOUT, DEFAULT_UPLOAD_REQUEST_TIMEOUT); } @Buildable(builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false) - public Config(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, int watchReconnectInterval, int watchReconnectLimit, int connectionTimeout, int requestTimeout, long rollingTimeout, long scaleTimeout, int loggingInterval, int maxConcurrentRequests, int maxConcurrentRequestsPerHost, boolean http2Disable, String httpProxy, String httpsProxy, String[] noProxy, Map errorMessages, String userAgent, TlsVersion[] tlsVersions, long websocketTimeout, long websocketPingInterval, String proxyUsername, String proxyPassword, String trustStoreFile, String trustStorePassphrase, String keyStoreFile, String keyStorePassphrase, String impersonateUsername, String[] impersonateGroups, Map> impersonateExtras, OAuthTokenProvider oauthTokenProvider,Map customHeaders, int requestRetryBackoffLimit, int requestRetryBackoffInterval, int uploadConnectionTimeout, int uploadRequestTimeout) { + public Config(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, int watchReconnectInterval, int watchReconnectLimit, int connectionTimeout, int requestTimeout, + long rollingTimeout, long scaleTimeout, int loggingInterval, int maxConcurrentRequests, int maxConcurrentRequestsPerHost, + boolean http2Disable, String httpProxy, String httpsProxy, String[] noProxy, Map errorMessages, + String userAgent, TlsVersion[] tlsVersions, long websocketTimeout, long websocketPingInterval, String proxyUsername, + String proxyPassword, String trustStoreFile, String trustStorePassphrase, String keyStoreFile, String keyStorePassphrase, + String impersonateUsername, String[] impersonateGroups, Map> impersonateExtras, + OAuthTokenProvider oauthTokenProvider, Map customHeaders, int requestRetryBackoffLimit, + int requestRetryBackoffInterval, int uploadConnectionTimeout, int uploadRequestTimeout) { this.masterUrl = masterUrl; this.apiVersion = apiVersion; this.namespace = namespace; @@ -323,22 +355,26 @@ public Config(String masterUrl, String apiVersion, String namespace, boolean tru this.clientKeyAlgo = clientKeyAlgo; this.clientKeyPassphrase = clientKeyPassphrase; - this.requestConfig = new RequestConfig(username, password, oauthToken, watchReconnectLimit, watchReconnectInterval, connectionTimeout, rollingTimeout, requestTimeout, scaleTimeout, loggingInterval, websocketTimeout, websocketPingInterval, maxConcurrentRequests, maxConcurrentRequestsPerHost, oauthTokenProvider, requestRetryBackoffLimit, requestRetryBackoffInterval, uploadConnectionTimeout, uploadRequestTimeout); + this.requestConfig = new RequestConfig(username, password, oauthToken, watchReconnectLimit, watchReconnectInterval, + connectionTimeout, rollingTimeout, requestTimeout, scaleTimeout, loggingInterval, websocketTimeout, + websocketPingInterval, maxConcurrentRequests, maxConcurrentRequestsPerHost, oauthTokenProvider, + requestRetryBackoffLimit, requestRetryBackoffInterval, uploadConnectionTimeout, uploadRequestTimeout); this.requestConfig.setImpersonateUsername(impersonateUsername); this.requestConfig.setImpersonateGroups(impersonateGroups); this.requestConfig.setImpersonateExtras(impersonateExtras); this.http2Disable = http2Disable; - this.httpProxy= httpProxy; - this.httpsProxy= httpsProxy; - this.noProxy= noProxy; + this.httpProxy = httpProxy; + this.httpsProxy = httpsProxy; + this.noProxy = noProxy; this.proxyUsername = proxyUsername; this.proxyPassword = proxyPassword; this.errorMessages = errorMessages; this.userAgent = userAgent; this.tlsVersions = tlsVersions; - if (!this.masterUrl.toLowerCase(Locale.ROOT).startsWith(HTTP_PROTOCOL_PREFIX) && !this.masterUrl.startsWith(HTTPS_PROTOCOL_PREFIX)) { + if (!this.masterUrl.toLowerCase(Locale.ROOT).startsWith(HTTP_PROTOCOL_PREFIX) + && !this.masterUrl.startsWith(HTTPS_PROTOCOL_PREFIX)) { this.masterUrl = (SSLUtils.isHttpsAvailable(this) ? HTTPS_PROTOCOL_PREFIX : HTTP_PROTOCOL_PREFIX) + this.masterUrl; } @@ -356,37 +392,50 @@ public Config(String masterUrl, String apiVersion, String namespace, boolean tru public static void configFromSysPropsOrEnvVars(Config config) { config.setTrustCerts(Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, config.isTrustCerts())); - config.setDisableHostnameVerification(Utils.getSystemPropertyOrEnvVar(KUBERNETES_DISABLE_HOSTNAME_VERIFICATION_SYSTEM_PROPERTY, config.isDisableHostnameVerification())); + config.setDisableHostnameVerification(Utils.getSystemPropertyOrEnvVar( + KUBERNETES_DISABLE_HOSTNAME_VERIFICATION_SYSTEM_PROPERTY, config.isDisableHostnameVerification())); config.setMasterUrl(Utils.getSystemPropertyOrEnvVar(KUBERNETES_MASTER_SYSTEM_PROPERTY, config.getMasterUrl())); config.setApiVersion(Utils.getSystemPropertyOrEnvVar(KUBERNETES_API_VERSION_SYSTEM_PROPERTY, config.getApiVersion())); config.setNamespace(Utils.getSystemPropertyOrEnvVar(KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, config.getNamespace())); - config.setCaCertFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_FILE_SYSTEM_PROPERTY, config.getCaCertFile())); - config.setCaCertData(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_DATA_SYSTEM_PROPERTY, config.getCaCertData())); - config.setClientCertFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_CERTIFICATE_FILE_SYSTEM_PROPERTY, config.getClientCertFile())); - config.setClientCertData(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_CERTIFICATE_DATA_SYSTEM_PROPERTY, config.getClientCertData())); - config.setClientKeyFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_FILE_SYSTEM_PROPERTY, config.getClientKeyFile())); - config.setClientKeyData(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_DATA_SYSTEM_PROPERTY, config.getClientKeyData())); + config + .setCaCertFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_FILE_SYSTEM_PROPERTY, config.getCaCertFile())); + config + .setCaCertData(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_DATA_SYSTEM_PROPERTY, config.getCaCertData())); + config.setClientCertFile( + Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_CERTIFICATE_FILE_SYSTEM_PROPERTY, config.getClientCertFile())); + config.setClientCertData( + Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_CERTIFICATE_DATA_SYSTEM_PROPERTY, config.getClientCertData())); + config.setClientKeyFile( + Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_FILE_SYSTEM_PROPERTY, config.getClientKeyFile())); + config.setClientKeyData( + Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_DATA_SYSTEM_PROPERTY, config.getClientKeyData())); config.setClientKeyAlgo(getKeyAlgorithm(config.getClientKeyFile(), config.getClientKeyData())); - config.setClientKeyPassphrase(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_PASSPHRASE_SYSTEM_PROPERTY, new String(config.getClientKeyPassphrase()))); + config.setClientKeyPassphrase(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_PASSPHRASE_SYSTEM_PROPERTY, + new String(config.getClientKeyPassphrase()))); config.setUserAgent(Utils.getSystemPropertyOrEnvVar(KUBERNETES_USER_AGENT, config.getUserAgent())); - config.setTrustStorePassphrase(Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRUSTSTORE_PASSPHRASE_PROPERTY, config.getTrustStorePassphrase())); + config.setTrustStorePassphrase( + Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRUSTSTORE_PASSPHRASE_PROPERTY, config.getTrustStorePassphrase())); config.setTrustStoreFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRUSTSTORE_FILE_PROPERTY, config.getTrustStoreFile())); - config.setKeyStorePassphrase(Utils.getSystemPropertyOrEnvVar(KUBERNETES_KEYSTORE_PASSPHRASE_PROPERTY, config.getKeyStorePassphrase())); + config.setKeyStorePassphrase( + Utils.getSystemPropertyOrEnvVar(KUBERNETES_KEYSTORE_PASSPHRASE_PROPERTY, config.getKeyStorePassphrase())); config.setKeyStoreFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_KEYSTORE_FILE_PROPERTY, config.getKeyStoreFile())); config.setOauthToken(Utils.getSystemPropertyOrEnvVar(KUBERNETES_OAUTH_TOKEN_SYSTEM_PROPERTY, config.getOauthToken())); config.setUsername(Utils.getSystemPropertyOrEnvVar(KUBERNETES_AUTH_BASIC_USERNAME_SYSTEM_PROPERTY, config.getUsername())); config.setPassword(Utils.getSystemPropertyOrEnvVar(KUBERNETES_AUTH_BASIC_PASSWORD_SYSTEM_PROPERTY, config.getPassword())); - config.setImpersonateUsername(Utils.getSystemPropertyOrEnvVar(KUBERNETES_IMPERSONATE_USERNAME, config.getImpersonateUsername())); + config.setImpersonateUsername( + Utils.getSystemPropertyOrEnvVar(KUBERNETES_IMPERSONATE_USERNAME, config.getImpersonateUsername())); - String configuredImpersonateGroups = Utils.getSystemPropertyOrEnvVar(KUBERNETES_IMPERSONATE_GROUP, config.getImpersonateGroup()); + String configuredImpersonateGroups = Utils.getSystemPropertyOrEnvVar(KUBERNETES_IMPERSONATE_GROUP, + config.getImpersonateGroup()); if (configuredImpersonateGroups != null) { config.setImpersonateGroups(configuredImpersonateGroups.split(",")); } - String configuredWatchReconnectInterval = Utils.getSystemPropertyOrEnvVar(KUBERNETES_WATCH_RECONNECT_INTERVAL_SYSTEM_PROPERTY); + String configuredWatchReconnectInterval = Utils + .getSystemPropertyOrEnvVar(KUBERNETES_WATCH_RECONNECT_INTERVAL_SYSTEM_PROPERTY); if (configuredWatchReconnectInterval != null) { config.setWatchReconnectInterval(Integer.parseInt(configuredWatchReconnectInterval)); } @@ -396,45 +445,57 @@ public static void configFromSysPropsOrEnvVars(Config config) { config.setWatchReconnectLimit(Integer.parseInt(configuredWatchReconnectLimit)); } - String configuredRollingTimeout = Utils.getSystemPropertyOrEnvVar(KUBERNETES_ROLLING_TIMEOUT_SYSTEM_PROPERTY, String.valueOf(DEFAULT_ROLLING_TIMEOUT)); + String configuredRollingTimeout = Utils.getSystemPropertyOrEnvVar(KUBERNETES_ROLLING_TIMEOUT_SYSTEM_PROPERTY, + String.valueOf(DEFAULT_ROLLING_TIMEOUT)); if (configuredRollingTimeout != null) { config.setRollingTimeout(Long.parseLong(configuredRollingTimeout)); } - String configuredScaleTimeout = Utils.getSystemPropertyOrEnvVar(KUBERNETES_SCALE_TIMEOUT_SYSTEM_PROPERTY, String.valueOf(DEFAULT_SCALE_TIMEOUT)); + String configuredScaleTimeout = Utils.getSystemPropertyOrEnvVar(KUBERNETES_SCALE_TIMEOUT_SYSTEM_PROPERTY, + String.valueOf(DEFAULT_SCALE_TIMEOUT)); if (configuredScaleTimeout != null) { config.setScaleTimeout(Long.parseLong(configuredScaleTimeout)); } - - String configuredLoggingInterval = Utils.getSystemPropertyOrEnvVar(KUBERNETES_LOGGING_INTERVAL_SYSTEM_PROPERTY, String.valueOf(DEFAULT_LOGGING_INTERVAL)); + String configuredLoggingInterval = Utils.getSystemPropertyOrEnvVar(KUBERNETES_LOGGING_INTERVAL_SYSTEM_PROPERTY, + String.valueOf(DEFAULT_LOGGING_INTERVAL)); if (configuredLoggingInterval != null) { config.setLoggingInterval(Integer.parseInt(configuredLoggingInterval)); } - config.setConnectionTimeout(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CONNECTION_TIMEOUT_SYSTEM_PROPERTY, config.getConnectionTimeout())); - config.setUploadConnectionTimeout(Utils.getSystemPropertyOrEnvVar(KUBERNETES_UPLOAD_CONNECTION_TIMEOUT_SYSTEM_PROPERTY, config.getUploadConnectionTimeout())); - config.setUploadRequestTimeout(Utils.getSystemPropertyOrEnvVar(KUBERNETES_UPLOAD_REQUEST_TIMEOUT_SYSTEM_PROPERTY, config.getUploadRequestTimeout())); - config.setRequestTimeout(Utils.getSystemPropertyOrEnvVar(KUBERNETES_REQUEST_TIMEOUT_SYSTEM_PROPERTY, config.getRequestTimeout())); - config.setRequestRetryBackoffLimit(Utils.getSystemPropertyOrEnvVar(KUBERNETES_REQUEST_RETRY_BACKOFFLIMIT_SYSTEM_PROPERTY, config.getRequestRetryBackoffLimit())); - config.setRequestRetryBackoffInterval(Utils.getSystemPropertyOrEnvVar(KUBERNETES_REQUEST_RETRY_BACKOFFINTERVAL_SYSTEM_PROPERTY, config.getRequestRetryBackoffInterval())); - - String configuredWebsocketTimeout = Utils.getSystemPropertyOrEnvVar(KUBERNETES_WEBSOCKET_TIMEOUT_SYSTEM_PROPERTY, String.valueOf(config.getWebsocketTimeout())); + config.setConnectionTimeout( + Utils.getSystemPropertyOrEnvVar(KUBERNETES_CONNECTION_TIMEOUT_SYSTEM_PROPERTY, config.getConnectionTimeout())); + config.setUploadConnectionTimeout(Utils.getSystemPropertyOrEnvVar(KUBERNETES_UPLOAD_CONNECTION_TIMEOUT_SYSTEM_PROPERTY, + config.getUploadConnectionTimeout())); + config.setUploadRequestTimeout( + Utils.getSystemPropertyOrEnvVar(KUBERNETES_UPLOAD_REQUEST_TIMEOUT_SYSTEM_PROPERTY, config.getUploadRequestTimeout())); + config.setRequestTimeout( + Utils.getSystemPropertyOrEnvVar(KUBERNETES_REQUEST_TIMEOUT_SYSTEM_PROPERTY, config.getRequestTimeout())); + config.setRequestRetryBackoffLimit(Utils.getSystemPropertyOrEnvVar(KUBERNETES_REQUEST_RETRY_BACKOFFLIMIT_SYSTEM_PROPERTY, + config.getRequestRetryBackoffLimit())); + config.setRequestRetryBackoffInterval(Utils.getSystemPropertyOrEnvVar( + KUBERNETES_REQUEST_RETRY_BACKOFFINTERVAL_SYSTEM_PROPERTY, config.getRequestRetryBackoffInterval())); + + String configuredWebsocketTimeout = Utils.getSystemPropertyOrEnvVar(KUBERNETES_WEBSOCKET_TIMEOUT_SYSTEM_PROPERTY, + String.valueOf(config.getWebsocketTimeout())); if (configuredWebsocketTimeout != null) { config.setWebsocketTimeout(Long.parseLong(configuredWebsocketTimeout)); } - String configuredWebsocketPingInterval = Utils.getSystemPropertyOrEnvVar(KUBERNETES_WEBSOCKET_PING_INTERVAL_SYSTEM_PROPERTY, String.valueOf(config.getWebsocketPingInterval())); + String configuredWebsocketPingInterval = Utils.getSystemPropertyOrEnvVar(KUBERNETES_WEBSOCKET_PING_INTERVAL_SYSTEM_PROPERTY, + String.valueOf(config.getWebsocketPingInterval())); if (configuredWebsocketPingInterval != null) { config.setWebsocketPingInterval(Long.parseLong(configuredWebsocketPingInterval)); } - String configuredMaxConcurrentRequests = Utils.getSystemPropertyOrEnvVar(KUBERNETES_MAX_CONCURRENT_REQUESTS, String.valueOf(config.getMaxConcurrentRequests())); + String configuredMaxConcurrentRequests = Utils.getSystemPropertyOrEnvVar(KUBERNETES_MAX_CONCURRENT_REQUESTS, + String.valueOf(config.getMaxConcurrentRequests())); if (configuredMaxConcurrentRequests != null) { config.setMaxConcurrentRequests(Integer.parseInt(configuredMaxConcurrentRequests)); } - String configuredMaxConcurrentReqeustsPerHost = Utils.getSystemPropertyOrEnvVar(KUBERNETES_MAX_CONCURRENT_REQUESTS_PER_HOST, String.valueOf(config.getMaxConcurrentRequestsPerHost())); + String configuredMaxConcurrentReqeustsPerHost = Utils.getSystemPropertyOrEnvVar(KUBERNETES_MAX_CONCURRENT_REQUESTS_PER_HOST, + String.valueOf(config.getMaxConcurrentRequestsPerHost())); if (configuredMaxConcurrentReqeustsPerHost != null) { config.setMaxConcurrentRequestsPerHost(Integer.parseInt(configuredMaxConcurrentReqeustsPerHost)); } @@ -470,8 +531,10 @@ private static boolean tryServiceAccount(Config config) { LOGGER.debug("Trying to configure client from service account..."); String masterHost = Utils.getSystemPropertyOrEnvVar(KUBERNETES_SERVICE_HOST_PROPERTY, (String) null); String masterPort = Utils.getSystemPropertyOrEnvVar(KUBERNETES_SERVICE_PORT_PROPERTY, (String) null); - String saTokenPath = Utils.getSystemPropertyOrEnvVar(KUBERNETES_AUTH_SERVICEACCOUNT_TOKEN_FILE_SYSTEM_PROPERTY, KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH); - String caCertPath = Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_FILE_SYSTEM_PROPERTY, KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH); + String saTokenPath = Utils.getSystemPropertyOrEnvVar(KUBERNETES_AUTH_SERVICEACCOUNT_TOKEN_FILE_SYSTEM_PROPERTY, + KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH); + String caCertPath = Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_FILE_SYSTEM_PROPERTY, + KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH); if (masterHost != null && masterPort != null) { String hostPort = joinHostPort(masterHost, masterPort); @@ -504,7 +567,7 @@ private static boolean tryServiceAccount(Config config) { private static String joinHostPort(String host, String port) { if (host.indexOf(':') >= 0) { - // Host is an IPv6 + // Host is an IPv6 return "[" + host + "]:" + port; } return host + ":" + port; @@ -531,7 +594,7 @@ public static Config fromKubeconfig(String kubeconfigContents) { public static Config fromKubeconfig(String context, String kubeconfigContents, String kubeconfigPath) { // we allow passing context along here, since downstream accepts it Config config = new Config(); - if(kubeconfigPath != null) + if (kubeconfigPath != null) config.file = new File(kubeconfigPath); loadFromKubeconfig(config, context, kubeconfigContents); return config; @@ -558,14 +621,17 @@ private static boolean tryKubeConfig(Config config, String context) { } public static String getKubeconfigFilename() { - String fileName = Utils.getSystemPropertyOrEnvVar(KUBERNETES_KUBECONFIG_FILE, new File(getHomeDir(), ".kube" + File.separator + "config").toString()); + String fileName = Utils.getSystemPropertyOrEnvVar(KUBERNETES_KUBECONFIG_FILE, + new File(getHomeDir(), ".kube" + File.separator + "config").toString()); // if system property/env var contains multiple files take the first one based on the environment // we are running in (eg. : for Linux, ; for Windows) String[] fileNames = fileName.split(File.pathSeparator); if (fileNames.length > 1) { - LOGGER.warn("Found multiple Kubernetes config files [{}], using the first one: [{}]. If not desired file, please change it by doing `export KUBECONFIG=/path/to/kubeconfig` on Unix systems or `$Env:KUBECONFIG=/path/to/kubeconfig` on Windows.", fileNames, fileNames[0]); + LOGGER.warn( + "Found multiple Kubernetes config files [{}], using the first one: [{}]. If not desired file, please change it by doing `export KUBECONFIG=/path/to/kubeconfig` on Unix systems or `$Env:KUBECONFIG=/path/to/kubeconfig` on Windows.", + fileNames, fileNames[0]); fileName = fileNames[0]; } return fileName; @@ -573,9 +639,9 @@ public static String getKubeconfigFilename() { private static String getKubeconfigContents(File kubeConfigFile) { String kubeconfigContents = null; - try (FileReader reader = new FileReader(kubeConfigFile)){ + try (FileReader reader = new FileReader(kubeConfigFile)) { kubeconfigContents = IOHelpers.readFully(reader); - } catch(IOException e) { + } catch (IOException e) { LOGGER.error("Could not load Kubernetes config file from {}", kubeConfigFile.getPath(), e); return null; } @@ -592,12 +658,13 @@ private static boolean loadFromKubeconfig(Config config, String context, String Context currentContext = setCurrentContext(context, config, kubeConfig); Cluster currentCluster = KubeConfigUtils.getCluster(kubeConfig, currentContext); if (currentContext != null) { - config.setNamespace(currentContext.getNamespace()); + config.setNamespace(currentContext.getNamespace()); } if (currentCluster != null) { config.setMasterUrl(currentCluster.getServer()); config.setTrustCerts(currentCluster.getInsecureSkipTlsVerify() != null && currentCluster.getInsecureSkipTlsVerify()); - config.setDisableHostnameVerification(currentCluster.getInsecureSkipTlsVerify() != null && currentCluster.getInsecureSkipTlsVerify()); + config.setDisableHostnameVerification( + currentCluster.getInsecureSkipTlsVerify() != null && currentCluster.getInsecureSkipTlsVerify()); config.setCaCertData(currentCluster.getCertificateAuthorityData()); AuthInfo currentAuthInfo = KubeConfigUtils.getUserAuthInfo(kubeConfig, currentContext); if (currentAuthInfo != null) { @@ -632,7 +699,7 @@ private static boolean loadFromKubeconfig(Config config, String context, String config.setOauthToken(currentAuthInfo.getAuthProvider().getConfig().get(ID_TOKEN)); } } - } else if (config.getOauthTokenProvider() == null) { // https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins + } else if (config.getOauthTokenProvider() == null) { // https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins ExecConfig exec = currentAuthInfo.getExec(); if (exec != null) { ExecCredential ec = getExecCredentialFromExecConfig(exec, configFile); @@ -645,7 +712,8 @@ private static boolean loadFromKubeconfig(Config config, String context, String } config.getErrorMessages().put(401, "Unauthorized! Token may have expired! Please log-in again."); - config.getErrorMessages().put(403, "Forbidden! User " + (currentContext != null? currentContext.getUser() : "") + " doesn't have permission."); + config.getErrorMessages().put(403, + "Forbidden! User " + (currentContext != null ? currentContext.getUser() : "") + " doesn't have permission."); } return true; } @@ -656,12 +724,15 @@ private static boolean loadFromKubeconfig(Config config, String context, String return false; } - protected static ExecCredential getExecCredentialFromExecConfig(ExecConfig exec, File configFile) throws IOException, InterruptedException { + protected static ExecCredential getExecCredentialFromExecConfig(ExecConfig exec, File configFile) + throws IOException, InterruptedException { String apiVersion = exec.getApiVersion(); - if ("client.authentication.k8s.io/v1alpha1".equals(apiVersion) || "client.authentication.k8s.io/v1beta1".equals(apiVersion)) { + if ("client.authentication.k8s.io/v1alpha1".equals(apiVersion) + || "client.authentication.k8s.io/v1beta1".equals(apiVersion)) { List env = exec.getEnv(); // TODO check behavior of tty & stdin - ProcessBuilder pb = new ProcessBuilder(getAuthenticatorCommandFromExecConfig(exec, configFile, Utils.getSystemPathVariable())); + ProcessBuilder pb = new ProcessBuilder( + getAuthenticatorCommandFromExecConfig(exec, configFile, Utils.getSystemPathVariable())); pb.redirectErrorStream(true); if (env != null) { Map environment = pb.environment(); @@ -687,7 +758,8 @@ protected static ExecCredential getExecCredentialFromExecConfig(ExecConfig exec, return null; } - protected static List getAuthenticatorCommandFromExecConfig(ExecConfig exec, File configFile, String systemPathValue) { + protected static List getAuthenticatorCommandFromExecConfig(ExecConfig exec, File configFile, + String systemPathValue) { String command = exec.getCommand(); if (command.contains(File.separator) && !command.startsWith(File.separator) && configFile != null) { // Appears to be a relative path; normalize. Spec is vague about how to detect this situation. @@ -697,7 +769,7 @@ protected static List getAuthenticatorCommandFromExecConfig(ExecConfig e command = getCommandWithFullyQualifiedPath(command, systemPathValue); List args = exec.getArgs(); if (args != null) { - argv.add(command + " " + String.join( " ", args)); + argv.add(command + " " + String.join(" ", args)); } return argv; } @@ -736,8 +808,11 @@ private static final class ExecCredential { public ExecCredentialSpec spec; public ExecCredentialStatus status; } + @JsonIgnoreProperties(ignoreUnknown = true) - private static final class ExecCredentialSpec {} + private static final class ExecCredentialSpec { + } + @JsonIgnoreProperties(ignoreUnknown = true) private static final class ExecCredentialStatus { public String token; @@ -750,7 +825,7 @@ private static boolean tryNamespaceFromPath(Config config) { String serviceAccountNamespace = Utils.getSystemPropertyOrEnvVar(KUBERNETES_NAMESPACE_FILE, KUBERNETES_NAMESPACE_PATH); boolean serviceAccountNamespaceExists = Files.isRegularFile(new File(serviceAccountNamespace).toPath()); if (serviceAccountNamespaceExists) { - LOGGER.debug("Found service account namespace at: [{}].",serviceAccountNamespace); + LOGGER.debug("Found service account namespace at: [{}].", serviceAccountNamespace); try { String namespace = new String(Files.readAllBytes(new File(serviceAccountNamespace).toPath())); config.setNamespace(namespace.replace(System.lineSeparator(), "")); @@ -759,7 +834,7 @@ private static boolean tryNamespaceFromPath(Config config) { LOGGER.error("Error reading service account namespace from: [" + serviceAccountNamespace + "].", e); } } else { - LOGGER.debug("Did not find service account namespace at: [{}]. Ignoring.",serviceAccountNamespace); + LOGGER.debug("Did not find service account namespace at: [{}]. Ignoring.", serviceAccountNamespace); } } return false; @@ -798,33 +873,33 @@ private static String getHomeDir() { } public static String getKeyAlgorithm(InputStream inputStream) throws IOException { - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) { - String line, algorithm = null; - - while ((line = bufferedReader.readLine()) != null) { - if (line.contains("BEGIN EC PRIVATE KEY")) - algorithm = "EC"; - else if (line.contains("BEGIN RSA PRIVATE KEY")) { - algorithm = "RSA"; - } + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) { + String line, algorithm = null; + + while ((line = bufferedReader.readLine()) != null) { + if (line.contains("BEGIN EC PRIVATE KEY")) + algorithm = "EC"; + else if (line.contains("BEGIN RSA PRIVATE KEY")) { + algorithm = "RSA"; } - return algorithm; } + return algorithm; + } } public static String getKeyAlgorithm(String clientKeyFile, String clientKeyData) { // Check if any system property is set - if(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_ALGO_SYSTEM_PROPERTY) != null) { + if (Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_ALGO_SYSTEM_PROPERTY) != null) { return Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_ALGO_SYSTEM_PROPERTY); } // Detect algorithm try { InputStream keyInputStream = CertUtils.getInputStreamFromDataOrFile(clientKeyData, clientKeyFile); - if(keyInputStream != null) { + if (keyInputStream != null) { return getKeyAlgorithm(keyInputStream); } - } catch(IOException exception) { + } catch (IOException exception) { LOGGER.debug("Failure in determining private key algorithm type, defaulting to RSA {}", exception.getMessage()); } return null; @@ -845,7 +920,7 @@ public String getPassword() { } public void setPassword(String password) { - this.requestConfig.setPassword(password); + this.requestConfig.setPassword(password); } @JsonProperty("username") @@ -1133,7 +1208,7 @@ public void setHttp2Disable(boolean http2Disable) { } public void setHttpProxy(String httpProxy) { - this.httpProxy= httpProxy; + this.httpProxy = httpProxy; } @JsonProperty("httpProxy") @@ -1142,7 +1217,7 @@ public String getHttpProxy() { } public void setHttpsProxy(String httpsProxy) { - this.httpsProxy= httpsProxy; + this.httpsProxy = httpsProxy; } @JsonProperty("httpsProxy") @@ -1363,4 +1438,14 @@ public AuthProviderConfig getAuthProvider() { return authProvider; } + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + } diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/KubernetesClientBuilder.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/KubernetesClientBuilder.java index dafd3aa1f9d..4e2605fefdd 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/KubernetesClientBuilder.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/KubernetesClientBuilder.java @@ -16,10 +16,67 @@ package io.fabric8.kubernetes.client; -public class KubernetesClientBuilder extends BaseKubernetesClientBuilder { +import io.fabric8.kubernetes.client.http.HttpClient; +import io.fabric8.kubernetes.client.utils.Serialization; + +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; + +public class KubernetesClientBuilder { + + private Config config; + private HttpClient.Factory factory; + private Class clazz; public KubernetesClientBuilder() { - super("io.fabric8.kubernetes.client.DefaultKubernetesClient"); + // basically the same logic as in KubernetesResourceUtil for finding list types + // we're not guarding against a null context class loader + String className = "io.fabric8.kubernetes.client.DefaultKubernetesClient"; + try { + clazz = (Class) Thread.currentThread().getContextClassLoader().loadClass(className); + } catch (ClassNotFoundException | ClassCastException e) { + try { + clazz = (Class) KubernetesClient.class.getClassLoader().loadClass(className); + } catch (Exception ex) { + throw KubernetesClientException.launderThrowable(ex); + } + } + } + + public KubernetesClient build() { + if (config == null) { + config = new ConfigBuilder().build(); + } + try { + if (factory == null) { + return clazz.getConstructor(Config.class).newInstance(config); + } + HttpClient client = factory.createHttpClient(config); + return clazz.getConstructor(HttpClient.class, Config.class).newInstance(client, config); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | NoSuchMethodException | SecurityException e) { + throw KubernetesClientException.launderThrowable(e); + } + } + + public KubernetesClientBuilder withConfig(Config config) { + this.config = config; + return this; + } + + public KubernetesClientBuilder withConfig(String config) { + this.config = Serialization.unmarshal(config); + return this; + } + + public KubernetesClientBuilder withConfig(InputStream config) { + this.config = Serialization.unmarshal(config); + return this; + } + + public KubernetesClientBuilder withHttpClientFactory(HttpClient.Factory factory) { + this.factory = factory; + return this; } } diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java index 7962b7a7c5f..bb6a2a22112 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java @@ -25,10 +25,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.net.ssl.KeyManager; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; - import java.net.InetSocketAddress; import java.net.MalformedURLException; import java.net.URL; @@ -45,13 +41,18 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import javax.net.ssl.KeyManager; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; + public class HttpClientUtils { private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientUtils.class); public static final String HEADER_INTERCEPTOR = "HEADER"; - private HttpClientUtils() { } + private HttpClientUtils() { + } private static Pattern VALID_IPV4_PATTERN = null; public static final String ipv4Pattern = "(http:\\/\\/|https:\\/\\/)?(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])(\\/[0-9]\\d|1[0-9]\\d|2[0-9]\\d|3[0-2]\\d)?"; @@ -65,42 +66,43 @@ private HttpClientUtils() { } } } - public static URL getProxyUrl(Config config) throws MalformedURLException { - URL master = new URL(config.getMasterUrl()); - String host = master.getHost(); - if (config.getNoProxy() != null) { - for (String noProxy : config.getNoProxy()) { - if (isIpAddress(noProxy)) { - if (new IpAddressMatcher(noProxy).matches(host)) { - return null; - } - } else { - if (host.contains(noProxy)) { - return null; - } - } - } - } - String proxy = config.getHttpsProxy(); - if (master.getProtocol().equals("http")) { - proxy = config.getHttpProxy(); - } - if (proxy != null) { - URL proxyUrl = new URL(proxy); - if (proxyUrl.getPort() < 0) { - throw new IllegalArgumentException("Failure in creating proxy URL. Proxy port is required!"); - } - return proxyUrl; + public static URL getProxyUrl(Config config) throws MalformedURLException { + URL master = new URL(config.getMasterUrl()); + String host = master.getHost(); + if (config.getNoProxy() != null) { + for (String noProxy : config.getNoProxy()) { + if (isIpAddress(noProxy)) { + if (new IpAddressMatcher(noProxy).matches(host)) { + return null; + } + } else { + if (host.contains(noProxy)) { + return null; + } } - return null; + } } - - private static boolean isIpAddress(String ipAddress) { - Matcher ipMatcher = VALID_IPV4_PATTERN.matcher(ipAddress); - return ipMatcher.matches(); + String proxy = config.getHttpsProxy(); + if (master.getProtocol().equals("http")) { + proxy = config.getHttpProxy(); } + if (proxy != null) { + URL proxyUrl = new URL(proxy); + if (proxyUrl.getPort() < 0) { + throw new IllegalArgumentException("Failure in creating proxy URL. Proxy port is required!"); + } + return proxyUrl; + } + return null; + } + + private static boolean isIpAddress(String ipAddress) { + Matcher ipMatcher = VALID_IPV4_PATTERN.matcher(ipAddress); + return ipMatcher.matches(); + } - public static Map createApplicableInterceptors(Config config, HttpClient.Factory factory) { + public static Map createApplicableInterceptors(Config config, + HttpClient.Factory factory) { Map interceptors = new LinkedHashMap<>(); // Header Interceptor @@ -115,7 +117,7 @@ public void before(BasicBuilder builder, HttpHeaders headers) { } if (config.getCustomHeaders() != null && !config.getCustomHeaders().isEmpty()) { for (Map.Entry entry : config.getCustomHeaders().entrySet()) { - builder.header(entry.getKey(),entry.getValue()); + builder.header(entry.getKey(), entry.getValue()); } } if (config.getUserAgent() != null && !config.getUserAgent().isEmpty()) { @@ -128,7 +130,8 @@ public void before(BasicBuilder builder, HttpHeaders headers) { // Token Refresh Interceptor interceptors.put(TokenRefreshInterceptor.NAME, new TokenRefreshInterceptor(config, factory)); // Backwards Compatibility Interceptor - String shouldDisableBackwardsCompatibilityInterceptor = Utils.getSystemPropertyOrEnvVar(KUBERNETES_BACKWARDS_COMPATIBILITY_INTERCEPTOR_DISABLE, "false"); + String shouldDisableBackwardsCompatibilityInterceptor = Utils + .getSystemPropertyOrEnvVar(KUBERNETES_BACKWARDS_COMPATIBILITY_INTERCEPTOR_DISABLE, "false"); if (!Boolean.parseBoolean(shouldDisableBackwardsCompatibilityInterceptor)) { interceptors.put(BackwardsCompatibilityInterceptor.NAME, new BackwardsCompatibilityInterceptor()); } @@ -144,6 +147,11 @@ public static String basicCredentials(String username, String password) { private static final AtomicBoolean WARNED = new AtomicBoolean(); + /** + * @deprecated you should not need to call this method directly. Please create your own HttpClient.Factory + * should you need to customize your clients. + */ + @Deprecated public static HttpClient createHttpClient(Config config) { ServiceLoader loader = ServiceLoader.load(HttpClient.Factory.class); HttpClient.Factory factory = null; @@ -159,7 +167,8 @@ public static HttpClient createHttpClient(Config config) { } } if (factory == null) { - throw new KubernetesClientException("No httpclient implementations found on the context classloader, please ensure your classpath includes an implementation jar"); + throw new KubernetesClientException( + "No httpclient implementations found on the context classloader, please ensure your classpath includes an implementation jar"); } return factory.createHttpClient(config); } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/DefaultKubernetesClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/DefaultKubernetesClient.java index 0bfab39e6a6..4f9aeb94804 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/DefaultKubernetesClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/DefaultKubernetesClient.java @@ -121,26 +121,32 @@ /** * Class for Default Kubernetes Client implementing KubernetesClient interface. * It is thread safe. + * + * @deprecated direct usage should no longer be needed. Please use the {@link KubernetesClientBuilder} instead. */ +@Deprecated public class DefaultKubernetesClient extends BaseClient implements NamespacedKubernetesClient { public static final String KUBERNETES_VERSION_ENDPOINT = "version"; - + static { Handlers.register(Pod.class, PodOperationsImpl::new); Handlers.register(Job.class, JobOperationsImpl::new); Handlers.register(Service.class, ServiceOperationsImpl::new); Handlers.register(Deployment.class, DeploymentOperationsImpl::new); - Handlers.register(io.fabric8.kubernetes.api.model.extensions.Deployment.class, io.fabric8.kubernetes.client.dsl.internal.extensions.v1beta1.DeploymentOperationsImpl::new); + Handlers.register(io.fabric8.kubernetes.api.model.extensions.Deployment.class, + io.fabric8.kubernetes.client.dsl.internal.extensions.v1beta1.DeploymentOperationsImpl::new); Handlers.register(ReplicaSet.class, ReplicaSetOperationsImpl::new); - Handlers.register(io.fabric8.kubernetes.api.model.extensions.ReplicaSet.class, io.fabric8.kubernetes.client.dsl.internal.extensions.v1beta1.ReplicaSetOperationsImpl::new); + Handlers.register(io.fabric8.kubernetes.api.model.extensions.ReplicaSet.class, + io.fabric8.kubernetes.client.dsl.internal.extensions.v1beta1.ReplicaSetOperationsImpl::new); Handlers.register(ReplicationController.class, ReplicationControllerOperationsImpl::new); Handlers.register(StatefulSet.class, StatefulSetOperationsImpl::new); - Handlers.register(io.fabric8.kubernetes.api.model.certificates.v1.CertificateSigningRequest.class, CertificateSigningRequestOperationsImpl::new); + Handlers.register(io.fabric8.kubernetes.api.model.certificates.v1.CertificateSigningRequest.class, + CertificateSigningRequestOperationsImpl::new); // trigger a load of the other client handlers and make KubernetesClient and DefaultKubernetesClient Adapters.initializeHandlers(ResourcedHasMetadataOperation::register); } - + public DefaultKubernetesClient() { super(); } @@ -152,11 +158,11 @@ public DefaultKubernetesClient(String masterUrl) { public DefaultKubernetesClient(Config config) { super(config); } - + public DefaultKubernetesClient(HttpClient httpClient, Config config) { super(httpClient, config); } - + public DefaultKubernetesClient(ClientContext clientContext) { super(clientContext); } @@ -183,7 +189,7 @@ protected ClientContext createInNamespaceContext(String name, boolean any) { copy.setDefaultNamespace(false); return newState(copy); } - + protected Config configCopy() { return new ConfigBuilder(getConfiguration()).build(); } @@ -197,7 +203,7 @@ public LeaderElectorBuilder leaderElector( public FunctionCallable withRequestConfig(RequestConfig requestConfig) { return new WithRequestCallable<>(this, requestConfig); } - + /** * {@inheritDoc} */ @@ -238,7 +244,8 @@ public NamespaceListVisitFromServerGetDeleteRecreateWaitApplicable * {@inheritDoc} */ @Override - public NamespaceListVisitFromServerGetDeleteRecreateWaitApplicable resourceList(Collection items) { + public NamespaceListVisitFromServerGetDeleteRecreateWaitApplicable resourceList( + Collection items) { return resourceList(new KubernetesListBuilder().withItems(new ArrayList<>(items)).build()); } @@ -249,7 +256,7 @@ public NamespaceListVisitFromServerGetDeleteRecreateWaitApplicable public ParameterNamespaceListVisitFromServerGetDeleteRecreateWaitApplicable resourceList(String s) { return resourceListFor(s); } - + @Override public NamespaceableResource resource(T item) { // lookup the operation given the item @@ -263,7 +270,7 @@ public NamespaceableResource resource(T item) { */ @Override public NamespaceableResource resource(String s) { - return resource((HasMetadata)Serialization.unmarshal(s)); + return resource((HasMetadata) Serialization.unmarshal(s)); } /** @@ -271,7 +278,9 @@ public NamespaceableResource resource(String s) { */ @Override public MixedOperation, Resource> bindings() { - return resources(Binding.class, (Class>) TypeFactory.rawClass(new TypeReference>(){}.getType())); + return resources(Binding.class, + (Class>) TypeFactory.rawClass(new TypeReference>() { + }.getType())); } /** @@ -372,7 +381,7 @@ public MixedOperation> apiServices() { - return Handlers.getOperation(APIService.class, APIServiceList.class, this); + return Handlers.getOperation(APIService.class, APIServiceList.class, this); } /** @@ -432,37 +441,40 @@ public InOutCreateable tokenReviews() { * {@inheritDoc} */ @Override - public MixedOperation, Resource> customResources(Class resourceType) { + public MixedOperation, Resource> customResources( + Class resourceType) { return customResources(resourceType, null); } - /** * {@inheritDoc} */ @Override - public > MixedOperation> customResources(Class resourceType, Class listClass) { + public > MixedOperation> customResources( + Class resourceType, Class listClass) { return customResources(CustomResourceDefinitionContext.fromCustomResourceType(resourceType), resourceType, listClass); } - + @Override public MixedOperation> genericKubernetesResources( String apiVersion, String kind) { ResourceDefinitionContext context = Handlers.getResourceDefinitionContext(apiVersion, kind, this); if (context == null) { - throw new KubernetesClientException("Could not find the metadata for the given apiVersion and kind, please pass a ResourceDefinitionContext instead"); + throw new KubernetesClientException( + "Could not find the metadata for the given apiVersion and kind, please pass a ResourceDefinitionContext instead"); } return genericKubernetesResources(context); } - + /** * {@inheritDoc} */ @Override - public > HasMetadataOperationsImpl customResources(ResourceDefinitionContext rdContext, Class resourceType, Class listClass) { + public > HasMetadataOperationsImpl customResources( + ResourceDefinitionContext rdContext, Class resourceType, Class listClass) { return newHasMetadataOperation(rdContext, resourceType, listClass); } - + @Override public DiscoveryAPIGroupDSL discovery() { return adapt(DiscoveryAPIGroupClient.class); @@ -498,7 +510,7 @@ public FlowControlAPIGroupDSL flowControl() { public VersionInfo getVersion() { return getVersionInfo(KUBERNETES_VERSION_ENDPOINT); } - + @Override public VersionInfo getKubernetesVersion() { return getVersionInfo(KUBERNETES_VERSION_ENDPOINT); @@ -540,37 +552,49 @@ public AutoscalingAPIGroupDSL autoscaling() { * {@inheritDoc} */ @Override - public NetworkAPIGroupDSL network() { return adapt(NetworkAPIGroupClient.class); } + public NetworkAPIGroupDSL network() { + return adapt(NetworkAPIGroupClient.class); + } /** * {@inheritDoc} */ @Override - public StorageAPIGroupDSL storage() { return adapt(StorageAPIGroupClient.class); } + public StorageAPIGroupDSL storage() { + return adapt(StorageAPIGroupClient.class); + } /** * {@inheritDoc} */ @Override - public BatchAPIGroupDSL batch() { return adapt(BatchAPIGroupClient.class); } + public BatchAPIGroupDSL batch() { + return adapt(BatchAPIGroupClient.class); + } /** * {@inheritDoc} */ @Override - public MetricAPIGroupDSL top() { return adapt(MetricAPIGroupClient.class); } + public MetricAPIGroupDSL top() { + return adapt(MetricAPIGroupClient.class); + } /** * {@inheritDoc} */ @Override - public PolicyAPIGroupDSL policy() { return adapt(PolicyAPIGroupClient.class); } + public PolicyAPIGroupDSL policy() { + return adapt(PolicyAPIGroupClient.class); + } /** * {@inheritDoc} */ @Override - public RbacAPIGroupDSL rbac() { return adapt(RbacAPIGroupClient.class); } + public RbacAPIGroupDSL rbac() { + return adapt(RbacAPIGroupClient.class); + } /** * {@inheritDoc} diff --git a/openshift-client-api/src/main/java/io/fabric8/openshift/client/OpenShiftClientBuilder.java b/openshift-client-api/src/main/java/io/fabric8/openshift/client/OpenShiftClientBuilder.java deleted file mode 100644 index 7991dc76b14..00000000000 --- a/openshift-client-api/src/main/java/io/fabric8/openshift/client/OpenShiftClientBuilder.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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.openshift.client; - -import io.fabric8.kubernetes.client.BaseKubernetesClientBuilder; - -public class OpenShiftClientBuilder extends BaseKubernetesClientBuilder { - - public OpenShiftClientBuilder() { - super("io.fabric8.openshift.client.DefaultOpenShiftClient"); - } - - public OpenShiftClientBuilder withOpenShiftConfig(OpenShiftConfig config) { - super.withConfig(config); - return this; - } - - @Override - public OpenShiftClient build() { - return (OpenShiftClient)super.build(); - } - -} diff --git a/openshift-client-api/src/main/java/io/fabric8/openshift/client/OpenShiftConfig.java b/openshift-client-api/src/main/java/io/fabric8/openshift/client/OpenShiftConfig.java index b6f1e7a8251..794c0f42033 100644 --- a/openshift-client-api/src/main/java/io/fabric8/openshift/client/OpenShiftConfig.java +++ b/openshift-client-api/src/main/java/io/fabric8/openshift/client/OpenShiftConfig.java @@ -15,9 +15,9 @@ */ package io.fabric8.openshift.client; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.OAuthTokenProvider; import io.fabric8.kubernetes.client.http.TlsVersion; @@ -41,12 +41,17 @@ public class OpenShiftConfig extends Config { public static final String OPENSHIFT_URL_SYSTEM_PROPERTY = "openshift.url"; public static final String OPENSHIFT_BUILD_TIMEOUT_SYSTEM_PROPERTY = "openshift.build.timeout"; + public static final String DISABLE_API_GROUP_CHECK = "disableApiGroupCheck"; + public static final String OPENSHIFT_URL = "openShiftUrl"; + public static final String BUILD_TIMEOUT = "buildTimeout"; + public static final String OAPI_VERSION = "oapiVersion"; + public static final Long DEFAULT_BUILD_TIMEOUT = 5 * 60 * 1000L; - private String oapiVersion = "v1"; + // dummy fields so that Builder is created correctly + private String oapiVersion; private String openShiftUrl; - private long buildTimeout = DEFAULT_BUILD_TIMEOUT; - private boolean openshiftApiGroupsEnabled; + private long buildTimeout; private boolean disableApiGroupCheck; //If group hasn't been explicitly set. //This is not meant to be used. This constructor is used only by the generated builder. @@ -55,70 +60,84 @@ public class OpenShiftConfig extends Config { public OpenShiftConfig(Config kubernetesConfig) { this(kubernetesConfig, - getDefaultOpenShiftUrl(kubernetesConfig), getDefaultOapiVersion(kubernetesConfig), DEFAULT_BUILD_TIMEOUT - ); + getDefaultOpenShiftUrl(kubernetesConfig), getDefaultOapiVersion(kubernetesConfig), DEFAULT_BUILD_TIMEOUT); } public OpenShiftConfig(Config kubernetesConfig, String openShiftUrl) { this(kubernetesConfig, - getDefaultOpenShiftUrl(kubernetesConfig), getDefaultOapiVersion(kubernetesConfig), DEFAULT_BUILD_TIMEOUT - ); - this.openShiftUrl = openShiftUrl; - } - - @Buildable(builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false, refs = {@BuildableReference(Config.class)}) - public OpenShiftConfig(String openShiftUrl, String oapiVersion, 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, int watchReconnectInterval, int watchReconnectLimit, int connectionTimeout, int requestTimeout, long rollingTimeout, long scaleTimeout, int loggingInterval, int maxConcurrentRequests, int maxConcurrentRequestsPerHost, boolean http2Disable, String httpProxy, String httpsProxy, String[] noProxy, Map errorMessages, String userAgent, TlsVersion[] tlsVersions, long websocketTimeout, long websocketPingInterval, String proxyUsername, String proxyPassword, String trustStoreFile, String trustStorePassphrase, String keyStoreFile, String keyStorePassphrase, String impersonateUsername, String[] impersonateGroups, Map> impersonateExtras, OAuthTokenProvider oauthTokenProvider, Map customHeaders, int requestRetryBackoffLimit, int requestRetryBackoffInterval, int uploadConnectionTimeout, int uploadRequestTimeout, long buildTimeout, boolean openshiftApiGroupsEnabled, boolean disableApiGroupCheck) { - super(masterUrl, apiVersion, namespace, trustCerts, disableHostnameVerification, caCertFile, caCertData, clientCertFile, clientCertData, clientKeyFile, clientKeyData, clientKeyAlgo, clientKeyPassphrase, username, password, oauthToken, watchReconnectInterval, watchReconnectLimit, connectionTimeout, requestTimeout, rollingTimeout, scaleTimeout, loggingInterval, maxConcurrentRequests, maxConcurrentRequestsPerHost, http2Disable, httpProxy, httpsProxy, noProxy, errorMessages, userAgent, tlsVersions, websocketTimeout, websocketPingInterval, proxyUsername, proxyPassword, trustStoreFile, trustStorePassphrase, keyStoreFile, keyStorePassphrase, impersonateUsername, impersonateGroups, impersonateExtras, oauthTokenProvider, customHeaders, requestRetryBackoffLimit, requestRetryBackoffInterval, uploadConnectionTimeout, uploadRequestTimeout); - this.oapiVersion = oapiVersion; - this.openShiftUrl = openShiftUrl; - this.buildTimeout = buildTimeout; - this.openshiftApiGroupsEnabled = openshiftApiGroupsEnabled; - this.disableApiGroupCheck = disableApiGroupCheck; - - if (this.openShiftUrl == null || this.openShiftUrl.isEmpty()) { - this.openShiftUrl = URLUtils.join(getMasterUrl(), "oapi", this.oapiVersion); + getDefaultOpenShiftUrl(kubernetesConfig), getDefaultOapiVersion(kubernetesConfig), DEFAULT_BUILD_TIMEOUT); + this.setOpenShiftUrl(openShiftUrl); + } + + @Buildable(builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false, refs = { + @BuildableReference(Config.class) }) + public OpenShiftConfig(String openShiftUrl, String oapiVersion, 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, int watchReconnectInterval, int watchReconnectLimit, + int connectionTimeout, int requestTimeout, long rollingTimeout, long scaleTimeout, int loggingInterval, + int maxConcurrentRequests, int maxConcurrentRequestsPerHost, boolean http2Disable, String httpProxy, String httpsProxy, + String[] noProxy, Map errorMessages, String userAgent, TlsVersion[] tlsVersions, long websocketTimeout, + long websocketPingInterval, String proxyUsername, String proxyPassword, String trustStoreFile, + String trustStorePassphrase, String keyStoreFile, String keyStorePassphrase, String impersonateUsername, + String[] impersonateGroups, Map> impersonateExtras, OAuthTokenProvider oauthTokenProvider, + Map customHeaders, int requestRetryBackoffLimit, int requestRetryBackoffInterval, + int uploadConnectionTimeout, int uploadRequestTimeout, long buildTimeout, + boolean disableApiGroupCheck) { + super(masterUrl, apiVersion, namespace, trustCerts, disableHostnameVerification, caCertFile, caCertData, clientCertFile, + clientCertData, clientKeyFile, clientKeyData, clientKeyAlgo, clientKeyPassphrase, username, password, oauthToken, + watchReconnectInterval, watchReconnectLimit, connectionTimeout, requestTimeout, rollingTimeout, scaleTimeout, + loggingInterval, maxConcurrentRequests, maxConcurrentRequestsPerHost, http2Disable, httpProxy, httpsProxy, noProxy, + errorMessages, userAgent, tlsVersions, websocketTimeout, websocketPingInterval, proxyUsername, proxyPassword, + trustStoreFile, trustStorePassphrase, keyStoreFile, keyStorePassphrase, impersonateUsername, impersonateGroups, + impersonateExtras, oauthTokenProvider, customHeaders, requestRetryBackoffLimit, requestRetryBackoffInterval, + uploadConnectionTimeout, uploadRequestTimeout); + this.setOapiVersion(oapiVersion); + this.setBuildTimeout(buildTimeout); + this.setDisableApiGroupCheck(disableApiGroupCheck); + + if (openShiftUrl == null || openShiftUrl.isEmpty()) { + openShiftUrl = URLUtils.join(getMasterUrl(), "oapi", oapiVersion); } - if (!this.openShiftUrl.endsWith("/")) { - this.openShiftUrl = this.openShiftUrl + "/"; + if (!openShiftUrl.endsWith("/")) { + openShiftUrl += "/"; } + this.setOpenShiftUrl(openShiftUrl); } public OpenShiftConfig(Config kubernetesConfig, String openShiftUrl, String oapiVersion, long buildTimeout) { this(openShiftUrl, oapiVersion, - kubernetesConfig.getMasterUrl(), kubernetesConfig.getApiVersion(), - kubernetesConfig.getNamespace(), kubernetesConfig.isTrustCerts(), - kubernetesConfig.isDisableHostnameVerification(), kubernetesConfig.getCaCertFile(), - kubernetesConfig.getCaCertData(), kubernetesConfig.getClientCertFile(), - kubernetesConfig.getClientCertData(), kubernetesConfig.getClientKeyFile(), - kubernetesConfig.getClientKeyData(), kubernetesConfig.getClientKeyAlgo(), kubernetesConfig.getClientKeyPassphrase(), - kubernetesConfig.getUsername(), kubernetesConfig.getPassword(), kubernetesConfig.getOauthToken(), - kubernetesConfig.getWatchReconnectInterval(), kubernetesConfig.getWatchReconnectLimit(), - kubernetesConfig.getConnectionTimeout(), kubernetesConfig.getRequestTimeout(), - kubernetesConfig.getRollingTimeout(), kubernetesConfig.getScaleTimeout(), - kubernetesConfig.getLoggingInterval(), kubernetesConfig.getMaxConcurrentRequests(), - kubernetesConfig.getMaxConcurrentRequestsPerHost(), kubernetesConfig.isHttp2Disable(), - kubernetesConfig.getHttpProxy(), kubernetesConfig.getHttpsProxy(), kubernetesConfig.getNoProxy(), - kubernetesConfig.getErrorMessages(), kubernetesConfig.getUserAgent(), - kubernetesConfig.getTlsVersions(), kubernetesConfig.getWebsocketTimeout(), - kubernetesConfig.getWebsocketPingInterval(), kubernetesConfig.getProxyUsername(), - kubernetesConfig.getProxyPassword(), kubernetesConfig.getTrustStoreFile(), - kubernetesConfig.getTrustStorePassphrase(), kubernetesConfig.getKeyStoreFile(), - kubernetesConfig.getKeyStorePassphrase(), kubernetesConfig.getImpersonateUsername(), - kubernetesConfig.getImpersonateGroups(), kubernetesConfig.getImpersonateExtras(), - kubernetesConfig.getOauthTokenProvider(), kubernetesConfig.getCustomHeaders(), - kubernetesConfig.getRequestRetryBackoffLimit(), kubernetesConfig.getRequestRetryBackoffInterval(), - kubernetesConfig.getUploadConnectionTimeout(), kubernetesConfig.getUploadRequestTimeout(), - buildTimeout, - false, - false - ); + kubernetesConfig.getMasterUrl(), kubernetesConfig.getApiVersion(), + kubernetesConfig.getNamespace(), kubernetesConfig.isTrustCerts(), + kubernetesConfig.isDisableHostnameVerification(), kubernetesConfig.getCaCertFile(), + kubernetesConfig.getCaCertData(), kubernetesConfig.getClientCertFile(), + kubernetesConfig.getClientCertData(), kubernetesConfig.getClientKeyFile(), + kubernetesConfig.getClientKeyData(), kubernetesConfig.getClientKeyAlgo(), kubernetesConfig.getClientKeyPassphrase(), + kubernetesConfig.getUsername(), kubernetesConfig.getPassword(), kubernetesConfig.getOauthToken(), + kubernetesConfig.getWatchReconnectInterval(), kubernetesConfig.getWatchReconnectLimit(), + kubernetesConfig.getConnectionTimeout(), kubernetesConfig.getRequestTimeout(), + kubernetesConfig.getRollingTimeout(), kubernetesConfig.getScaleTimeout(), + kubernetesConfig.getLoggingInterval(), kubernetesConfig.getMaxConcurrentRequests(), + kubernetesConfig.getMaxConcurrentRequestsPerHost(), kubernetesConfig.isHttp2Disable(), + kubernetesConfig.getHttpProxy(), kubernetesConfig.getHttpsProxy(), kubernetesConfig.getNoProxy(), + kubernetesConfig.getErrorMessages(), kubernetesConfig.getUserAgent(), + kubernetesConfig.getTlsVersions(), kubernetesConfig.getWebsocketTimeout(), + kubernetesConfig.getWebsocketPingInterval(), kubernetesConfig.getProxyUsername(), + kubernetesConfig.getProxyPassword(), kubernetesConfig.getTrustStoreFile(), + kubernetesConfig.getTrustStorePassphrase(), kubernetesConfig.getKeyStoreFile(), + kubernetesConfig.getKeyStorePassphrase(), kubernetesConfig.getImpersonateUsername(), + kubernetesConfig.getImpersonateGroups(), kubernetesConfig.getImpersonateExtras(), + kubernetesConfig.getOauthTokenProvider(), kubernetesConfig.getCustomHeaders(), + kubernetesConfig.getRequestRetryBackoffLimit(), kubernetesConfig.getRequestRetryBackoffInterval(), + kubernetesConfig.getUploadConnectionTimeout(), kubernetesConfig.getUploadRequestTimeout(), + buildTimeout, + false); } public static OpenShiftConfig wrap(Config config) { return config instanceof OpenShiftConfig ? (OpenShiftConfig) config : new OpenShiftConfig(config); } - private static String getDefaultOapiVersion(Config config) { return Utils.getSystemPropertyOrEnvVar(KUBERNETES_OAPI_VERSION_SYSTEM_PROPERTY, config.getApiVersion()); } @@ -136,14 +155,6 @@ private static String getDefaultOpenShiftUrl(Config config) { } } - /** - * @deprecated openshiftApiGroupsEnabled is no longer honored - */ - @Deprecated - public OpenShiftConfig withOpenshiftApiGroupsEnabled(boolean openshiftApiGroupsEnabled) { - return new OpenShiftConfigBuilder(this).withOpenshiftApiGroupsEnabled(openshiftApiGroupsEnabled).build(); - } - private static boolean isRootURL(String url) { try { String path = new URL(url).getPath(); @@ -153,55 +164,39 @@ private static boolean isRootURL(String url) { } } - @JsonProperty("oapiVersion") + @JsonIgnore public String getOapiVersion() { - return oapiVersion; + return (String) this.additionalProperties.getOrDefault(OAPI_VERSION, "v1"); } public void setOapiVersion(String oapiVersion) { - this.oapiVersion = oapiVersion; + this.additionalProperties.put(OAPI_VERSION, oapiVersion); } - @JsonProperty("openShiftUrl") + @JsonIgnore public String getOpenShiftUrl() { - return openShiftUrl; + return (String) this.additionalProperties.get(OPENSHIFT_URL); } public void setOpenShiftUrl(String openShiftUrl) { - this.openShiftUrl = openShiftUrl; + this.additionalProperties.put(OPENSHIFT_URL, openShiftUrl); } - @JsonProperty("buildTimeout") public long getBuildTimeout() { - return buildTimeout; + return (long) this.additionalProperties.getOrDefault(BUILD_TIMEOUT, DEFAULT_BUILD_TIMEOUT); } public void setBuildTimeout(long buildTimeout) { - this.buildTimeout = buildTimeout; + this.additionalProperties.put(BUILD_TIMEOUT, buildTimeout); } + @JsonIgnore public boolean isDisableApiGroupCheck() { - return disableApiGroupCheck; + return Boolean.TRUE.equals(additionalProperties.get(DISABLE_API_GROUP_CHECK)); } public void setDisableApiGroupCheck(boolean disableApiGroupCheck) { - this.disableApiGroupCheck = disableApiGroupCheck; - } - - /** - * @deprecated openshiftApiGroupsEnabled is no longer honored - */ - @Deprecated - public boolean isOpenshiftApiGroupsEnabled() { - return openshiftApiGroupsEnabled; - } - - /** - * @deprecated openshiftApiGroupsEnabled is no longer honored - */ - @Deprecated - public void setOpenshiftApiGroupsEnabled(boolean openshiftApiGroupsEnabled) { - this.openshiftApiGroupsEnabled = openshiftApiGroupsEnabled; + this.additionalProperties.put(DISABLE_API_GROUP_CHECK, disableApiGroupCheck); } @Override diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/DefaultOpenShiftClient.java b/openshift-client/src/main/java/io/fabric8/openshift/client/DefaultOpenShiftClient.java index 026432b1f72..98e7020e97a 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/DefaultOpenShiftClient.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/DefaultOpenShiftClient.java @@ -24,6 +24,7 @@ import io.fabric8.kubernetes.client.DefaultKubernetesClient; import io.fabric8.kubernetes.client.ExtensionsAPIGroupClient; import io.fabric8.kubernetes.client.Handlers; +import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.RequestConfig; import io.fabric8.kubernetes.client.SimpleClientContext; @@ -189,8 +190,12 @@ /** * Class for Default Openshift Client implementing KubernetesClient interface. * It is thread safe. + * + * @deprecated direct usage should no longer be needed. Please use the {@link KubernetesClientBuilder} instead. */ -public class DefaultOpenShiftClient extends DefaultKubernetesClient implements NamespacedOpenShiftClient, OpenshiftClientContext { +@Deprecated +public class DefaultOpenShiftClient extends DefaultKubernetesClient + implements NamespacedOpenShiftClient, OpenshiftClientContext { public static final String OPENSHIFT_VERSION_ENDPOINT = "version/openshift"; @@ -350,13 +355,15 @@ public NamespacedInOutCreateable imageSt @Override public Namespaceable>> imageStreamImages() { - HasMetadataOperation> operation = Handlers.getNonListingOperation(ImageStreamImage.class, this); + HasMetadataOperation> operation = Handlers + .getNonListingOperation(ImageStreamImage.class, this); return operation::inNamespace; } @Override public NameableCreateOrDeleteable imageSignatures() { - HasMetadataOperation> operation = Handlers.getNonListingOperation(ImageSignature.class, this); + HasMetadataOperation> operation = Handlers + .getNonListingOperation(ImageSignature.class, this); return new NameableCreateOrDeleteable() { @Override @@ -383,7 +390,8 @@ public CreateOrDeleteable withName(String name) { @Override public NonNamespaceOperation> imageRegistryOperatorConfigs() { - return OpenShiftHandlers.getOperation(io.fabric8.openshift.api.model.miscellaneous.imageregistry.operator.v1.Config.class, ConfigList.class, this); + return OpenShiftHandlers.getOperation(io.fabric8.openshift.api.model.miscellaneous.imageregistry.operator.v1.Config.class, + ConfigList.class, this); } @Override @@ -428,12 +436,14 @@ public MixedOperation> eg @Override public NamespacedInOutCreateable podSecurityPolicySelfSubjectReviews() { - return OpenShiftHandlers.getCreateOnlyResourceOperation(PodSecurityPolicySelfSubjectReview.class, PodSecurityPolicySelfSubjectReview.class, this); + return OpenShiftHandlers.getCreateOnlyResourceOperation(PodSecurityPolicySelfSubjectReview.class, + PodSecurityPolicySelfSubjectReview.class, this); } @Override public NamespacedInOutCreateable podSecurityPolicySubjectReviews() { - return OpenShiftHandlers.getCreateOnlyResourceOperation(PodSecurityPolicySubjectReview.class, PodSecurityPolicySubjectReview.class, this); + return OpenShiftHandlers.getCreateOnlyResourceOperation(PodSecurityPolicySubjectReview.class, + PodSecurityPolicySubjectReview.class, this); } @Override @@ -530,15 +540,15 @@ public ExtensionsAPIGroupClient extensions() { @Override public VersionInfo getVersion() { for (Supplier supplier : new Supplier[] { - this::getOpenShiftV3Version, - this::getOpenShiftV4VersionInfo + this::getOpenShiftV3Version, + this::getOpenShiftV4VersionInfo }) { try { final VersionInfo vi = supplier.get(); if (vi != null) { return vi; } - } catch(Exception ex) { + } catch (Exception ex) { // try next } } @@ -589,7 +599,9 @@ public OpenShiftMachineAPIGroupDSL machine() { } @Override - public OpenShiftMonitoringAPIGroupDSL monitoring() { return adapt(OpenShiftMonitoringAPIGroupClient.class); } + public OpenShiftMonitoringAPIGroupDSL monitoring() { + return adapt(OpenShiftMonitoringAPIGroupClient.class); + } @Override public NonNamespaceOperation> netNamespaces() { @@ -628,17 +640,20 @@ public InOutCreateable subject @Override public InOutCreateable resourceAccessReviews() { - return OpenShiftHandlers.getCreateOnlyResourceOperation(ResourceAccessReview.class, ResourceAccessReviewResponse.class, this); + return OpenShiftHandlers.getCreateOnlyResourceOperation(ResourceAccessReview.class, ResourceAccessReviewResponse.class, + this); } @Override public NamespacedInOutCreateable localSubjectAccessReviews() { - return OpenShiftHandlers.getCreateOnlyResourceOperation(LocalSubjectAccessReview.class, SubjectAccessReviewResponse.class, this); + return OpenShiftHandlers.getCreateOnlyResourceOperation(LocalSubjectAccessReview.class, SubjectAccessReviewResponse.class, + this); } @Override public NamespacedInOutCreateable localResourceAccessReviews() { - return OpenShiftHandlers.getCreateOnlyResourceOperation(LocalResourceAccessReview.class, ResourceAccessReviewResponse.class, this); + return OpenShiftHandlers.getCreateOnlyResourceOperation(LocalResourceAccessReview.class, ResourceAccessReviewResponse.class, + this); } @Override From 14870447ced7ffebda7333323e7ff8479e98a6ee Mon Sep 17 00:00:00 2001 From: Steve Hawkins Date: Mon, 7 Mar 2022 13:20:07 -0500 Subject: [PATCH 2/3] preventing pre comments from being formatted --- ide-config/eclipse-format.xml | 708 ++++++++++-------- .../io/fabric8/kubernetes/client/Config.java | 14 +- 2 files changed, 394 insertions(+), 328 deletions(-) diff --git a/ide-config/eclipse-format.xml b/ide-config/eclipse-format.xml index 3506a440e91..1b6d84675ef 100644 --- a/ide-config/eclipse-format.xml +++ b/ide-config/eclipse-format.xml @@ -16,324 +16,392 @@ limitations under the License. --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java index d4be97aef2d..6d780abee51 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Config.java @@ -255,14 +255,12 @@ private Config(Boolean autoConfigure) { * You can also reuse this object to build your own {@link Config} object * without any auto configuration like this: * - *
-   * {
-   *   @code
-   *   Config configFromBuilder = new ConfigBuilder(Config.empty())
-   *       // ...
-   *       .build();
-   * }
-   * 
+ * + *
{@code
+   * Config configFromBuilder = new ConfigBuilder(Config.empty())
+   *                                // ...
+   *                               .build();
+   * }
* * @return a Config object without any automatic configuration */ From a6ddf0215a5ed3c8dc4efcdc91356ae9dcebacc9 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Tue, 8 Mar 2022 11:00:09 +0100 Subject: [PATCH 3/3] chore: revert code formatter profile complete replacement + use specific option Signed-off-by: Marc Nuri --- ide-config/eclipse-format.xml | 708 +++++++++++++++------------------- 1 file changed, 320 insertions(+), 388 deletions(-) diff --git a/ide-config/eclipse-format.xml b/ide-config/eclipse-format.xml index 1b6d84675ef..e0ddc060782 100644 --- a/ide-config/eclipse-format.xml +++ b/ide-config/eclipse-format.xml @@ -16,392 +16,324 @@ limitations under the License. --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +