use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesServiceAccountsProducer method doCreateServiceAccount.
protected void doCreateServiceAccount(Exchange exchange, String operation) throws Exception {
ServiceAccount sa = null;
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
ServiceAccount saToCreate = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT, ServiceAccount.class);
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Create a specific Service Account require specify a namespace name");
throw new IllegalArgumentException("Create a specific Service Account require specify a namespace name");
}
if (ObjectHelper.isEmpty(saToCreate)) {
LOG.error("Create a specific Service Account require specify a Service Account bean");
throw new IllegalArgumentException("Create a specific Service Account require specify a Service Account bean");
}
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_ACCOUNTS_LABELS, Map.class);
sa = getEndpoint().getKubernetesClient().serviceAccounts().inNamespace(namespaceName).create(saToCreate);
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(sa);
}
use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesServiceAccountsProducer method doGetServiceAccount.
protected void doGetServiceAccount(Exchange exchange, String operation) throws Exception {
ServiceAccount sa = null;
String saName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT_NAME, String.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (ObjectHelper.isEmpty(saName)) {
LOG.error("Get a specific Service Account require specify a Service Account name");
throw new IllegalArgumentException("Get a specific Service Account require specify a Service Account name");
}
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Get a specific Service Account require specify a namespace name");
throw new IllegalArgumentException("Get a specific Service Account require specify a namespace name");
}
sa = getEndpoint().getKubernetesClient().serviceAccounts().inNamespace(namespaceName).withName(saName).get();
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(sa);
}
use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesServicesProducer method doCreateService.
protected void doCreateService(Exchange exchange, String operation) throws Exception {
Service service = null;
String serviceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_NAME, String.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
ServiceSpec serviceSpec = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_SPEC, ServiceSpec.class);
if (ObjectHelper.isEmpty(serviceName)) {
LOG.error("Create a specific service require specify a service name");
throw new IllegalArgumentException("Create a specific service require specify a service name");
}
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Create a specific service require specify a namespace name");
throw new IllegalArgumentException("Create a specific service require specify a namespace name");
}
if (ObjectHelper.isEmpty(serviceSpec)) {
LOG.error("Create a specific service require specify a service spec bean");
throw new IllegalArgumentException("Create a specific service require specify a service spec bean");
}
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_LABELS, Map.class);
Service serviceCreating = new ServiceBuilder().withNewMetadata().withName(serviceName).withLabels(labels).endMetadata().withSpec(serviceSpec).build();
service = getEndpoint().getKubernetesClient().services().inNamespace(namespaceName).create(serviceCreating);
exchange.getOut().setBody(service);
}
use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesNamespacesConsumerTest method createAndDeletePod.
@Test
public void createAndDeletePod() throws Exception {
if (ObjectHelper.isEmpty(authToken)) {
return;
}
mockResultEndpoint.expectedMessageCount(5);
mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED", "MODIFIED", "MODIFIED", "MODIFIED", "DELETED");
Exchange ex = template.request("direct:createNamespace", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
Map<String, String> labels = new HashMap<String, String>();
labels.put("this", "rocks");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, labels);
}
});
Namespace ns = ex.getOut().getBody(Namespace.class);
assertEquals(ns.getMetadata().getName(), "test");
ex = template.request("direct:listByLabels", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Map<String, String> labels = new HashMap<String, String>();
labels.put("this", "rocks");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, labels);
}
});
List<Namespace> result = ex.getOut().getBody(List.class);
boolean testExists = false;
Iterator<Namespace> it = result.iterator();
while (it.hasNext()) {
Namespace namespace = it.next();
if ("test".equalsIgnoreCase(namespace.getMetadata().getName())) {
testExists = true;
}
}
assertTrue(testExists);
ex = template.request("direct:deleteNamespace", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "test");
}
});
boolean nsDeleted = ex.getOut().getBody(Boolean.class);
assertTrue(nsDeleted);
Thread.sleep(3000);
mockResultEndpoint.assertIsSatisfied();
}
use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesNamespacesProducer method doCreateNamespace.
protected void doCreateNamespace(Exchange exchange, String operation) {
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Create a specific namespace require specify a namespace name");
throw new IllegalArgumentException("Create a specific namespace require specify a namespace name");
}
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, Map.class);
Namespace ns = new NamespaceBuilder().withNewMetadata().withName(namespaceName).withLabels(labels).endMetadata().build();
Namespace namespace = getEndpoint().getKubernetesClient().namespaces().create(ns);
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(namespace);
}
Aggregations