added better logging and different type of exception handling when we do not have k8s
This commit is contained in:
parent
3b35ed8da2
commit
c6a9abbef0
Binary file not shown.
|
@ -43,6 +43,7 @@ The following environment variables may be used to override the default configur
|
||||||
| KUBERNETES_PORT_443_TCP_PORT | 443 | API port number |
|
| KUBERNETES_PORT_443_TCP_PORT | 443 | API port number |
|
||||||
| CASSANDRA_SERVICE | cassandra | Default service name for lookup |
|
| CASSANDRA_SERVICE | cassandra | Default service name for lookup |
|
||||||
| POD_NAMESPACE | default | Default pod service namespace |
|
| POD_NAMESPACE | default | Default pod service namespace |
|
||||||
|
| K8S_ACCOUNT_TOKEN | /var/run/secrets/kubernetes.io/serviceaccount/token | Default path to service token |
|
||||||
|
|
||||||
# Using
|
# Using
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ import java.util.Map;
|
||||||
* <li>CASSANDRA_SERVICE defaults to cassandra</li>
|
* <li>CASSANDRA_SERVICE defaults to cassandra</li>
|
||||||
* <li>POD_NAMESPACE defaults to 'default'</li>
|
* <li>POD_NAMESPACE defaults to 'default'</li>
|
||||||
* <li>CASSANDRA_SERVICE_NUM_SEEDS defaults to 8 seeds</li>
|
* <li>CASSANDRA_SERVICE_NUM_SEEDS defaults to 8 seeds</li>
|
||||||
|
* <li>K8S_ACCOUNT_TOKEN defaults to the path for the default token</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public class KubernetesSeedProvider implements SeedProvider {
|
public class KubernetesSeedProvider implements SeedProvider {
|
||||||
|
@ -107,10 +108,11 @@ public class KubernetesSeedProvider implements SeedProvider {
|
||||||
String path = String.format("/api/v1/namespaces/%s/endpoints/", podNamespace);
|
String path = String.format("/api/v1/namespaces/%s/endpoints/", podNamespace);
|
||||||
String seedSizeVar = getEnvOrDefault("CASSANDRA_SERVICE_NUM_SEEDS", "8");
|
String seedSizeVar = getEnvOrDefault("CASSANDRA_SERVICE_NUM_SEEDS", "8");
|
||||||
Integer seedSize = Integer.valueOf(seedSizeVar);
|
Integer seedSize = Integer.valueOf(seedSizeVar);
|
||||||
|
String accountToken = getEnvOrDefault("K8S_ACCOUNT_TOKEN", "/var/run/secrets/kubernetes.io/serviceaccount/token");
|
||||||
|
|
||||||
List<InetAddress> seeds = new ArrayList<InetAddress>();
|
List<InetAddress> seeds = new ArrayList<InetAddress>();
|
||||||
try {
|
try {
|
||||||
String token = getServiceAccountToken();
|
String token = getServiceAccountToken(accountToken);
|
||||||
|
|
||||||
SSLContext ctx = SSLContext.getInstance("SSL");
|
SSLContext ctx = SSLContext.getInstance("SSL");
|
||||||
ctx.init(null, trustAll, new SecureRandom());
|
ctx.init(null, trustAll, new SecureRandom());
|
||||||
|
@ -222,13 +224,12 @@ public class KubernetesSeedProvider implements SeedProvider {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getServiceAccountToken() throws IOException {
|
private static String getServiceAccountToken(String file) {
|
||||||
String file = "/var/run/secrets/kubernetes.io/serviceaccount/token";
|
|
||||||
try {
|
try {
|
||||||
return new String(Files.readAllBytes(Paths.get(file)));
|
return new String(Files.readAllBytes(Paths.get(file)));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn("unable to load service account token");
|
logger.warn("unable to load service account token" + file);
|
||||||
throw e;
|
throw new RuntimeException("Unable to load services account token " + file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue