Skip to content
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

feat: Allow connecting to a separate K8s server when running in a K8s cluster #385

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading