Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit defaults from Fabric8 kubernetes client defaults #43475

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading