in teamcity-kubernetes-plugin-server/src/main/java/jetbrains/buildServer/clouds/kubernetes/connector/KubeApiConnectorImpl.java [154:180]
private <T> T withKubernetesClient(boolean retrying, Function<KubernetesClient, T> function){
try {
return function.apply(myKubernetesClient);
} catch (KubernetesClientException kce){
final String operation = getOperation(kce);
LOG.warnAndDebugDetails(String.format("An error occurred at %s, ProfileId: %s, Code: %d, Status: %s", operation, myProfileId, kce.getCode(), kce.getStatus()),
KubernetesClientException.launderThrowable(kce));
if (!retrying && kce.getCode()==401){
final KubeApiConnectionCheckResult result = testConnection();
LOG.info(String.format("Test connection for %s: %s", myProfileId, result));
if (result.isNeedRefresh()){
LOG.info("Will now invalidate and recreate client for " + myProfileId);
invalidate();
KubernetesClient oldClient = myKubernetesClient;
myConfig = myCredentialsFactory.createConfig(myConnectionSettings, myAuthStrategy);
myKubernetesClient = createClient(myConfig);
FileUtil.close(oldClient);
}
return withKubernetesClient(true, function);
}
throw kce;
} catch (IllegalArgumentException illegalArgumentException){
LOG.warnAndDebugDetails(String.format("Failed to access the Kubernetes cluster: credentials are invalid or lack required permissions for %s", myProfileId),
illegalArgumentException);
throw new CloudException("Failed to access the Kubernetes cluster: credentials are invalid or lack required permissions. Please check server logs for more information", illegalArgumentException);
}
}