java
java copied to clipboard
java.net.SocketTimeoutException when applyManifest to private cluster using OkHttpClient with dns
Describe the bug After we upgraded our k8s java client version from 18.0.1 to 20.0.0, we start seeing java.net.SocketTimeoutException when applyManifest to private cluster using OkHttpClient with dns. The same code has no issue for version 18.0.1, has same issue for version 20.0.0 and 23.0.0. our code is: ` private ApiClient buildApiClient(final KubeConfigToken kubeConfigToken) { ApiClient apiClient = newApiClient(kubeConfigToken); if (kubeConfigToken.getIsPrivateAccessEnabled()) { OkHttpClient httpClient = okHttpClientwithDns(apiClient.getHttpClient().newBuilder(), kubeConfigToken); apiClient.setHttpClient(httpClient); } return apiClient; }
public OkHttpClient okHttpClientwithDns(OkHttpClient.Builder apiClientBuilder, KubeConfigToken kubeConfigToken) {
String dnsProxyIp = "dns://" + kubeConfigToken.getDnsProxyIp();
List<String> hostNames = prepareHostNames(kubeConfigToken);
return apiClientBuilder
.dns(new CustomDns(dnsProxyIp, hostNames))
.build();
}when we are using this client as shown below:Class clazz = resource.getClass();
KubectlApply kubectlApply = (KubectlApply) Kubectl.apply(clazz).fieldManager("kubectl")
.forceConflict(true).resource((KubernetesObject) resource).namespace(namespace);
KubectlApply kubectlApplyClient;
kubectlApplyClient = (KubectlApply) kubectlApply.apiClient(apiClient);
kubectlApplyClient = (KubectlApply) kubectlApplyClient.skipDiscovery();
ModelMapper.refresh(newDiscovery(kubeConfigToken), Duration.ZERO);
we got SocketTimeoutException with stack trace:Unable to invoke apply command for resource: helloworld of kind: Deployment in namespace: default:
io.kubernetes.client.openapi.ApiException: Message: java.net.SocketTimeoutException: Connect timed out
HTTP response code: 0
HTTP response body: null
HTTP response headers: null
at io.kubernetes.client.openapi.ApiClient.execute(ApiClient.java:1032)
at io.kubernetes.client.Discovery.get(Discovery.java:192)
at io.kubernetes.client.Discovery.versionDiscovery(Discovery.java:169)
at io.kubernetes.client.Discovery.legacyCoreApi(Discovery.java:161)
at io.kubernetes.client.Discovery.findAll(Discovery.java:51)
at io.kubernetes.client.util.ModelMapper.refresh(ModelMapper.java:273)`
Our observation is that this issue only happens for OkHttpClient with dns being set. there is no such issue when we use it for our public cluster, which doesn't need
Client Version
both 20.0.0 and 23.0.0 have this issue
Kubernetes Version
1.31.0 and 1.30.0
Java Version Java 17
To Reproduce Steps to reproduce the behavior:
- create an OkHttpClient with custom dns being set
- create an ApiClient with setHttpClient from step 1
- use the client from setp2 to apply manifest file. Expected behavior no exception, the manifest will be applied.
KubeConfig If applicable, add a KubeConfig file with secrets redacted.
Server (please complete the following information):
- OS: [e.g. Linux]
- Environment [e.g. container]
- Cloud [e.g. Azure]
Additional context Add any other context about the problem here.
@brendandburns would appreciated if you can take a look, thanks
My guess is that between 18 and 20 the version of the OkHTTP library changed and there is some difference/bug in that library.
I don't have a cluster that requires custom DNS so it is hard for me to reproduce this and given that it works when you don't specify DNS, it seems to be a problem in OkHTTP, not this client.
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle stale - Close this issue with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle rotten - Close this issue with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closed
You can:
- Reopen this issue with
/reopen - Mark this issue as fresh with
/remove-lifecycle rotten - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
@k8s-triage-robot: Closing this issue, marking it as "Not Planned".
In response to this:
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied- After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied- After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closedYou can:
- Reopen this issue with
/reopen- Mark this issue as fresh with
/remove-lifecycle rotten- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.