Skip to content

Commit

Permalink
Merge pull request #164 from irozzo-1A/in_cluster_ipv6_support
Browse files Browse the repository at this point in the history
Add support for IPv6 addresses in the in-cluster resolution
  • Loading branch information
k8s-ci-robot authored Dec 31, 2022
2 parents 0525735 + fc4f5d1 commit 1bb6fad
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion kubernetes/config/incluster_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,23 @@ static int setBasePathInCluster(char **pBasePath)
}

int basePathSize = strlen(SERVICE_HTTPS_PREFIX) + strlen(service_host_env) + strlen(service_port_env) + 2 /* 1 for ':', 1 for '\0' */ ;
bool isIPv6 = false;
if (strchr(service_host_env, ':') != NULL) {
isIPv6 = true;
// Takes into account the square brackets to escape the IP v6 address.
basePathSize += 2;
}
char *basePath = calloc(basePathSize, sizeof(char));
if (!basePath) {
fprintf(stderr, "%s: Cannot allocate the memory for base path for kubernetes service.\n", fname);
return -1;
}

snprintf(basePath, basePathSize, "%s%s:%s", SERVICE_HTTPS_PREFIX, service_host_env, service_port_env);
if (isIPv6) {
snprintf(basePath, basePathSize, "%s[%s]:%s", SERVICE_HTTPS_PREFIX, service_host_env, service_port_env);
} else {
snprintf(basePath, basePathSize, "%s%s:%s", SERVICE_HTTPS_PREFIX, service_host_env, service_port_env);
}
*pBasePath = basePath;
return 0;
}
Expand Down

0 comments on commit 1bb6fad

Please sign in to comment.