Skip to content

Commit 1bb6fad

Browse files
authored
Merge pull request #164 from irozzo-1A/in_cluster_ipv6_support
Add support for IPv6 addresses in the in-cluster resolution
2 parents 0525735 + fc4f5d1 commit 1bb6fad

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

kubernetes/config/incluster_config.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,23 @@ static int setBasePathInCluster(char **pBasePath)
6565
}
6666

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

74-
snprintf(basePath, basePathSize, "%s%s:%s", SERVICE_HTTPS_PREFIX, service_host_env, service_port_env);
80+
if (isIPv6) {
81+
snprintf(basePath, basePathSize, "%s[%s]:%s", SERVICE_HTTPS_PREFIX, service_host_env, service_port_env);
82+
} else {
83+
snprintf(basePath, basePathSize, "%s%s:%s", SERVICE_HTTPS_PREFIX, service_host_env, service_port_env);
84+
}
7585
*pBasePath = basePath;
7686
return 0;
7787
}

0 commit comments

Comments
 (0)