use of io.fabric8.kubernetes.api.model.Namespace in project che by eclipse.
the class OpenShiftConnector method createImageStreamTag.
/**
* Creates a new ImageStreamTag
*
* @param sourceImageWithTag the image that the ImageStreamTag will track
* @param imageStreamTagName the name of the imageStream tag (e.g. {@code <ImageStream name>:<Tag name>})
* @return the created ImageStreamTag
* @throws IOException When {@code sourceImageWithTag} metadata cannot be found
*/
private ImageStreamTag createImageStreamTag(String sourceImageWithTag, String imageStreamTagName) throws IOException {
try {
openShiftClient.imageStreamTags().inNamespace(openShiftCheProjectName).createOrReplaceWithNew().withNewMetadata().withName(imageStreamTagName).endMetadata().withNewTag().withNewFrom().withKind("DockerImage").withName(sourceImageWithTag).endFrom().endTag().done();
// Wait for image metadata to be pulled
for (int waitCount = 0; waitCount < OPENSHIFT_IMAGESTREAM_MAX_WAIT_COUNT; waitCount++) {
Thread.sleep(OPENSHIFT_IMAGESTREAM_WAIT_DELAY);
ImageStreamTag createdTag = openShiftClient.imageStreamTags().inNamespace(openShiftCheProjectName).withName(imageStreamTagName).get();
if (createdTag != null) {
LOG.info(String.format("Created ImageStreamTag %s in namespace %s", createdTag.getMetadata().getName(), openShiftCheProjectName));
return createdTag;
}
}
throw new ImageNotFoundException(String.format("Image %s not found.", sourceImageWithTag));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException(e.getLocalizedMessage(), e);
}
}
use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesServicesProducer method doGetService.
protected void doGetService(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);
if (ObjectHelper.isEmpty(serviceName)) {
LOG.error("Get a specific service require specify a service name");
throw new IllegalArgumentException("Get a specific service require specify a service name");
}
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Get a specific service require specify a namespace name");
throw new IllegalArgumentException("Get a specific service require specify a namespace name");
}
service = getEndpoint().getKubernetesClient().services().inNamespace(namespaceName).withName(serviceName).get();
exchange.getOut().setBody(service);
}
use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesNamespacesProducerTest method listTest.
@Test
public void listTest() throws Exception {
if (ObjectHelper.isEmpty(authToken)) {
return;
}
List<Namespace> result = template.requestBody("direct:list", "", List.class);
boolean defaultExists = false;
Iterator<Namespace> it = result.iterator();
while (it.hasNext()) {
Namespace namespace = it.next();
if ("default".equalsIgnoreCase(namespace.getMetadata().getName())) {
defaultExists = true;
}
}
assertTrue(defaultExists);
}
use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesNamespacesProducerTest method createAndDeleteNamespace.
@Test
public void createAndDeleteNamespace() throws Exception {
if (ObjectHelper.isEmpty(authToken)) {
return;
}
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: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);
}
use of io.fabric8.kubernetes.api.model.Namespace in project camel by apache.
the class KubernetesNamespacesProducerTest method createListByLabelsAndDeleteNamespace.
@Test
public void createListByLabelsAndDeleteNamespace() throws Exception {
if (ObjectHelper.isEmpty(authToken)) {
return;
}
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);
}
Aggregations