Skip to content

Commit

Permalink
Merge pull request #43475 from metacosm/fix-kube-client-defaults
Browse files Browse the repository at this point in the history
Inherit defaults from Fabric8 kubernetes client defaults
  • Loading branch information
gastaldi authored Sep 25, 2024
2 parents 5050908 + 243b4d3 commit 239eb5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.Duration;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;

import io.quarkus.runtime.annotations.ConfigDocSection;
import io.quarkus.runtime.annotations.ConfigPhase;
Expand Down Expand Up @@ -93,39 +94,33 @@ public interface KubernetesClientBuildConfig {
/**
* Watch reconnect interval
*/
@WithDefault("PT1S") // default lifted from Kubernetes Client
Duration watchReconnectInterval();
Optional<Duration> watchReconnectInterval();

/**
* Maximum reconnect attempts in case of watch failure
* By default there is no limit to the number of reconnect attempts
*/
@WithDefault("-1") // default lifted from Kubernetes Client
int watchReconnectLimit();
OptionalInt watchReconnectLimit();

/**
* Maximum amount of time to wait for a connection with the API server to be established
*/
@WithDefault("PT10S") // default lifted from Kubernetes Client
Duration connectionTimeout();
Optional<Duration> connectionTimeout();

/**
* Maximum amount of time to wait for a request to the API server to be completed
*/
@WithDefault("PT10S") // default lifted from Kubernetes Client
Duration requestTimeout();
Optional<Duration> requestTimeout();

/**
* Maximum number of retry attempts for API requests that fail with an HTTP code of >= 500
*/
@WithDefault("0") // default lifted from Kubernetes Client
Integer requestRetryBackoffLimit();
OptionalInt requestRetryBackoffLimit();

/**
* Time interval between retry attempts for API requests that fail with an HTTP code of >= 500
*/
@WithDefault("PT1S") // default lifted from Kubernetes Client
Duration requestRetryBackoffInterval();
Optional<Duration> requestRetryBackoffInterval();

/**
* HTTP proxy used to access the Kubernetes API server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.kubernetes.client.runtime;

import java.time.Duration;
import java.util.Optional;

import org.eclipse.microprofile.config.ConfigProvider;

Expand All @@ -23,10 +24,11 @@ public static Config createConfig(KubernetesClientBuildConfig buildConfig) {
boolean trustAll = buildConfig.trustCerts().isPresent() ? buildConfig.trustCerts().get() : globalTrustAll;
return new ConfigBuilder()
.withTrustCerts(trustAll)
.withWatchReconnectInterval((int) buildConfig.watchReconnectInterval().toMillis())
.withWatchReconnectLimit(buildConfig.watchReconnectLimit())
.withConnectionTimeout((int) buildConfig.connectionTimeout().toMillis())
.withRequestTimeout((int) buildConfig.requestTimeout().toMillis())
.withWatchReconnectInterval(
millisAsInt(buildConfig.watchReconnectInterval()).orElse(base.getWatchReconnectInterval()))
.withWatchReconnectLimit(buildConfig.watchReconnectLimit().orElse(base.getWatchReconnectLimit()))
.withConnectionTimeout(millisAsInt(buildConfig.connectionTimeout()).orElse(base.getConnectionTimeout()))
.withRequestTimeout(millisAsInt(buildConfig.requestTimeout()).orElse(base.getRequestTimeout()))
.withMasterUrl(buildConfig.apiServerUrl().or(() -> buildConfig.masterUrl()).orElse(base.getMasterUrl()))
.withNamespace(buildConfig.namespace().orElse(base.getNamespace()))
.withUsername(buildConfig.username().orElse(base.getUsername()))
Expand All @@ -46,11 +48,17 @@ public static Config createConfig(KubernetesClientBuildConfig buildConfig) {
.withProxyPassword(buildConfig.proxyPassword().orElse(base.getProxyPassword()))
.withNoProxy(buildConfig.noProxy().map(list -> list.toArray(new String[0])).orElse(base.getNoProxy()))
.withHttp2Disable(base.isHttp2Disable())
.withRequestRetryBackoffInterval((int) buildConfig.requestRetryBackoffInterval().toMillis())
.withRequestRetryBackoffLimit(buildConfig.requestRetryBackoffLimit())
.withRequestRetryBackoffInterval(millisAsInt(buildConfig.requestRetryBackoffInterval())
.orElse(base.getRequestRetryBackoffInterval()))
.withRequestRetryBackoffLimit(buildConfig.requestRetryBackoffLimit().orElse(base.getRequestRetryBackoffLimit()))
.build();
}

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private static Optional<Integer> millisAsInt(Optional<Duration> duration) {
return duration.map(d -> (int) d.toMillis());
}

public static KubernetesClient createClient(KubernetesClientBuildConfig buildConfig) {
return new KubernetesClientBuilder().withConfig(createConfig(buildConfig)).build();
}
Expand Down

0 comments on commit 239eb5e

Please sign in to comment.