mirror of https://github.com/k3s-io/k3s
Merge pull request #8025 from caesarxuchao/cassandra-example
update the KubernetesSeedProvider.java in example example/cassandra to v1beta3pull/6/head
commit
8c4a730a5b
|
@ -24,7 +24,7 @@ spec:
|
|||
value: 512M
|
||||
- name: HEAP_NEWSIZE
|
||||
value: 100M
|
||||
image: "kubernetes/cassandra:v2"
|
||||
image: gcr.io/google_containers/cassandra:v3
|
||||
name: cassandra
|
||||
ports:
|
||||
- containerPort: 9042
|
||||
|
|
|
@ -10,8 +10,8 @@ spec:
|
|||
- /run.sh
|
||||
resources:
|
||||
limits:
|
||||
cpu: "1"
|
||||
image: kubernetes/cassandra:v2
|
||||
cpu: "1"
|
||||
image: gcr.io/google_containers/cassandra:v3
|
||||
name: cassandra
|
||||
ports:
|
||||
- name: cql
|
||||
|
|
Binary file not shown.
|
@ -5,6 +5,16 @@
|
|||
<version>0.0.2</version>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
|
@ -21,9 +21,20 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class KubernetesSeedProvider implements SeedProvider {
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
static class Address {
|
||||
public String IP;
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
static class Subset {
|
||||
public List<Address> addresses;
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
static class Endpoints {
|
||||
public String[] endpoints;
|
||||
public List<Subset> subsets;
|
||||
}
|
||||
|
||||
private static String getEnvOrDefault(String var, String def) {
|
||||
|
@ -64,20 +75,21 @@ public class KubernetesSeedProvider implements SeedProvider {
|
|||
|
||||
String host = protocol + "://" + hostName + ":" + hostPort;
|
||||
String serviceName = getEnvOrDefault("CASSANDRA_SERVICE", "cassandra");
|
||||
String path = "/api/v1beta3/endpoints/";
|
||||
String path = "/api/v1beta3/namespaces/default/endpoints/";
|
||||
try {
|
||||
URL url = new URL(host + path + serviceName);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Endpoints endpoints = mapper.readValue(url, Endpoints.class);
|
||||
if (endpoints != null) {
|
||||
// Here is a problem point, endpoints.endpoints can be null in first node cases.
|
||||
if (endpoints.endpoints != null){
|
||||
for (String endpoint : endpoints.endpoints) {
|
||||
String[] parts = endpoint.split(":");
|
||||
list.add(InetAddress.getByName(parts[0]));
|
||||
}
|
||||
URL url = new URL(host + path + serviceName);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Endpoints endpoints = mapper.readValue(url, Endpoints.class);
|
||||
if (endpoints != null) {
|
||||
// Here is a problem point, endpoints.subsets can be null in first node cases.
|
||||
if (endpoints.subsets != null && !endpoints.subsets.isEmpty()){
|
||||
for (Subset subset : endpoints.subsets) {
|
||||
for (Address address : subset.addresses) {
|
||||
list.add(InetAddress.getByName(address.IP));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
logger.warn("Request to kubernetes apiserver failed");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue