Skip to content

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

Open
@chenqia2

Description

@chenqia2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions