Skip to content

java.net.SocketTimeoutException when applyManifest to private cluster using OkHttpClient with dns #3970

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

Open
chenqia2 opened this issue Mar 11, 2025 · 2 comments

Comments

@chenqia2
Copy link

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 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:

  1. create an OkHttpClient with custom dns being set
  2. create an ApiClient with setHttpClient from step 1
  3. 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.

@chenqia2
Copy link
Author

@brendandburns would appreciated if you can take a look, thanks

@brendandburns
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants