Skip to content

Commit

Permalink
fix (kubernetes-client-api) : Config's autoConfigure should disab…
Browse files Browse the repository at this point in the history
…le auto configuration

`Config`'s autoConfigure field should behave as per expectations. We
need to make changes to ConfigBuilder and ConfigFluent in order to
achieve this.
- Add a new Constructor with additional boolean arguments `autoConfigure` and
  `shouldSetDefaultValues`
- Move generated classes `ConfigBuilder` and `ConfigFluent` to `src/main/java`
  - `ConfigBuilder` would invoke `Config` constructor to create a
    completely empty Config object instead of `new Config()` (this was enabling auto configuration)
- Make all fields in Config class use boxed types instead of primitive
  types so that we can distinguish whether they have been configured by
  user.

Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia committed Aug 7, 2024
1 parent 8d78ecf commit 2eaff74
Show file tree
Hide file tree
Showing 12 changed files with 2,701 additions and 161 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Fix #6038: Support for Gradle configuration cache
* Fix #6110: VolumeSource (and other file mode fields) in Octal are correctly interpreted
* Fix #6215: Suppressing rejected execution exception for port forwarder
* Fix #6137: `ConfigBuilder.withAutoConfigure` is not working

#### Improvements
* Fix #6008: removing the optional dependency on bouncy castle
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.kubernetes.client;

import io.fabric8.kubernetes.api.builder.VisitableBuilder;

import java.util.Optional;

import static io.fabric8.kubernetes.client.Config.disableAutoConfig;

public class ConfigBuilder extends ConfigFluent<ConfigBuilder> implements VisitableBuilder<Config, ConfigBuilder> {
public ConfigBuilder() {
this(new Config(null, null, null, null, null, null, null,
null, null, null, null, null, null, null,
null, null, null, null, null, null, null,
null, null, null, null, null,
null, null, null, null, null, null, null, null,
null, null, null, null, null, null,
null, null, null, null, null,
null, null, null, null, null, false));
}

public ConfigBuilder(ConfigFluent<?> fluent) {
this(fluent, new Config(null, null, null, null, null, null, null,
null, null, null, null, null, null, null,
null, null, null, null, null, null, null,
null, null, null, null, null,
null, null, null, null, null, null, null, null,
null, null, null, null, null, null,
null, null, null, null, null,
null, null, null, null, null, false));
}

public ConfigBuilder(ConfigFluent<?> fluent, Config instance) {
this.fluent = fluent;
fluent.copyInstance(instance);
}

public ConfigBuilder(Config instance) {
this.fluent = this;
this.copyInstance(instance);
}

ConfigFluent<?> fluent;

public Config build() {
Boolean autoConfigure = Optional.ofNullable(fluent.getAutoConfigure()).orElse(!disableAutoConfig());
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(), autoConfigure, true);
buildable.setDefaultNamespace(fluent.isDefaultNamespace());
buildable.setAuthProvider(fluent.getAuthProvider());
buildable.setAuthProvider(fluent.getAuthProvider());
buildable.setFile(fluent.getFile());
return buildable;
}
}
Loading

0 comments on commit 2eaff74

Please sign in to comment.