use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.
the class SessionListener method generateSecrets.
private Set<Secret> generateSecrets(KubernetesClient client, Session session, ObjectMeta meta) {
Set<Secret> secrets = new HashSet<>();
Map<String, String> annotations = meta.getAnnotations();
if (annotations != null && !annotations.isEmpty()) {
for (Map.Entry<String, String> entry : annotations.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (SecretKeys.isSecretKey(key)) {
SecretKeys keyType = SecretKeys.fromValue(key);
for (String name : Secrets.getNames(value)) {
Map<String, String> data = new HashMap<>();
Secret secret = null;
try {
secret = client.secrets().inNamespace(session.getNamespace()).withName(name).get();
} catch (Exception e) {
// ignore - probably doesn't exist
}
if (secret == null) {
for (String c : Secrets.getContents(value, name)) {
data.put(c, keyType.generate());
}
secret = client.secrets().inNamespace(session.getNamespace()).createNew().withNewMetadata().withName(name).endMetadata().withData(data).done();
secrets.add(secret);
}
}
}
}
}
return secrets;
}
use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.
the class J4pClientProvider method lookup.
@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
KubernetesClient client = this.clientInstance.get();
Session session = this.sessionInstance.get();
JolokiaClients jolokiaClients = new JolokiaClients(client);
String serviceName = getServiceName(qualifiers);
String podName = getPodName(qualifiers);
String replicationControllerName = getReplicationControllerName(qualifiers);
if (Strings.isNotBlank(serviceName)) {
Service service = client.services().inNamespace(session.getNamespace()).withName(serviceName).get();
if (service != null) {
return jolokiaClients.clientForService(service);
}
}
if (Strings.isNotBlank(podName)) {
Pod pod = client.pods().inNamespace(session.getNamespace()).withName(serviceName).get();
if (pod != null) {
return jolokiaClients.clientForPod(pod);
}
}
if (Strings.isNotBlank(replicationControllerName)) {
ReplicationController replicationController = client.replicationControllers().inNamespace(session.getNamespace()).withName(replicationControllerName).get();
if (replicationController != null) {
return jolokiaClients.clientForReplicationController(replicationController);
}
}
return null;
}
use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.
the class PodResourceProvider method lookup.
@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
KubernetesClient client = this.clientInstance.get();
Session session = sessionInstance.get();
String name = getPodName(qualifiers);
if (name != null) {
return client.pods().inNamespace(session.getNamespace()).withName(name).get();
}
// Gets the first pod found that matches the labels.
Map<String, String> labels = getLabels(qualifiers);
PodList list = client.pods().inNamespace(session.getNamespace()).withLabels(labels).list();
List<Pod> pods = notNullList(list.getItems());
if (!pods.isEmpty()) {
return pods.get(0);
}
return null;
}
use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.
the class ReplicationControllerListResourceProvider method lookup.
@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
KubernetesClient client = this.clientInstance.get();
Session session = sessionInstance.get();
Map<String, String> labels = getLabels(qualifiers);
if (labels.isEmpty()) {
return client.replicationControllers().inNamespace(session.getNamespace()).list();
} else {
return client.replicationControllers().inNamespace(session.getNamespace()).withLabels(labels).list();
}
}
use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.
the class ReplicationControllerResourceProvider method lookup.
@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
KubernetesClient client = this.clientInstance.get();
Session session = sessionInstance.get();
String name = getReplicationControllerName(qualifiers);
return client.replicationControllers().inNamespace(session.getNamespace()).withName(name).get();
}
Aggregations