Skip to content

Commit

Permalink
feat: Allow connecting to a separate K8s server when running in a K8s…
Browse files Browse the repository at this point in the history
… cluster (#385)
  • Loading branch information
CH3CHO authored Dec 18, 2024
1 parent e2a7e27 commit 3d8a553
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class KubernetesClientService {

private final OkHttpClient okHttpClient = new OkHttpClient();

private Boolean inCluster;
private final Boolean inClusterMode;

private final String kubeConfig;

Expand Down Expand Up @@ -120,17 +120,17 @@ public KubernetesClientService(HigressServiceConfig config) throws IOException {
this.controllerIngressClassName = config.getIngressClassName();
this.controllerJwtPolicy = config.getControllerJwtPolicy();
this.controllerAccessToken = config.getControllerAccessToken();
this.inCluster = isInCluster();
this.inClusterMode = Strings.isNullOrEmpty(kubeConfig) && isInCluster();

if (inCluster) {
if (inClusterMode) {
client = ClientBuilder.cluster().build();
log.info("init KubernetesClientService InCluster");
log.info("init KubernetesClientService with InCluster mode");
} else {
String kubeConfigPath = !Strings.isNullOrEmpty(kubeConfig) ? kubeConfig : KUBE_CONFIG_DEFAULT_PATH;
try (FileReader reader = new FileReader(kubeConfigPath)) {
client = ClientBuilder.kubeconfig(KubeConfig.loadKubeConfig(reader)).build();
}
log.info("init KubernetesClientService LoadKubeConfig");
log.info("init KubernetesClientService with KubeConfig: {}", kubeConfigPath);
}

initializeK8sCapabilities();
Expand Down Expand Up @@ -584,11 +584,11 @@ private void checkResponseStatus(V1Status status) {
}

private Request buildControllerRequest(String path) throws IOException {
String serviceHost = inCluster ? controllerServiceName + "." + controllerNamespace : controllerServiceHost;
String serviceHost = inClusterMode ? controllerServiceName + "." + controllerNamespace : controllerServiceHost;
String url = "http://" + serviceHost + ":" + controllerServicePort + path;
Request.Builder builder = new Request.Builder().url(url);
String token = controllerAccessToken;
if (Strings.isNullOrEmpty(token) && inCluster) {
if (Strings.isNullOrEmpty(token) && inClusterMode) {
token = readTokenFromFile();
}
if (!Strings.isNullOrEmpty(token)) {
Expand Down

0 comments on commit 3d8a553

Please sign in to comment.