Search in sources :

Example 6 with Template

use of io.fabric8.openshift.api.model.Template in project camel by apache.

the class KubernetesReplicationControllersConsumerTest method createAndDeleteReplicationController.

@Test
public void createAndDeleteReplicationController() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED", "DELETED", "MODIFIED", "MODIFIED", "MODIFIED");
    Exchange ex = template.request("direct:createReplicationController", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, "test");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS, labels);
            ReplicationControllerSpec rcSpec = new ReplicationControllerSpec();
            rcSpec.setReplicas(2);
            PodTemplateSpecBuilder builder = new PodTemplateSpecBuilder();
            PodTemplateSpec t = builder.withNewMetadata().withName("nginx-template").addToLabels("server", "nginx").endMetadata().withNewSpec().addNewContainer().withName("wildfly").withImage("jboss/wildfly").addNewPort().withContainerPort(80).endPort().endContainer().endSpec().build();
            rcSpec.setTemplate(t);
            Map<String, String> selectorMap = new HashMap<String, String>();
            selectorMap.put("server", "nginx");
            rcSpec.setSelector(selectorMap);
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_SPEC, rcSpec);
        }
    });
    ReplicationController rc = ex.getOut().getBody(ReplicationController.class);
    assertEquals(rc.getMetadata().getName(), "test");
    ex = template.request("direct:deleteReplicationController", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, "test");
        }
    });
    boolean rcDeleted = ex.getOut().getBody(Boolean.class);
    assertTrue(rcDeleted);
    Thread.sleep(3000);
    mockResultEndpoint.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Processor(org.apache.camel.Processor) PodTemplateSpecBuilder(io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) HashMap(java.util.HashMap) Map(java.util.Map) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec) Test(org.junit.Test)

Example 7 with Template

use of io.fabric8.openshift.api.model.Template in project syndesis-qe by syndesisio.

the class AmqTemplate method deploy.

public static void deploy() {
    Template template = null;
    try (InputStream is = ClassLoader.getSystemResourceAsStream("templates/syndesis-amq.yml")) {
        template = OpenShiftUtils.client().templates().load(is).get();
    } catch (IOException ex) {
        throw new IllegalArgumentException("Unable to read template ", ex);
    }
    Map<String, String> templateParams = new HashMap<>();
    templateParams.put("MQ_USERNAME", "amq");
    templateParams.put("MQ_PASSWORD", "topSecret");
    // try to clean previous broker
    cleanUp();
    OpenShiftUtils.client().templates().withName("syndesis-amq").delete();
    KubernetesList processedTemplate = OpenShiftUtils.getInstance().recreateAndProcessTemplate(template, templateParams);
    OpenShiftUtils.getInstance().createResources(processedTemplate);
    try {
        OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.isAPodReady("application", "broker"));
    } catch (InterruptedException | TimeoutException e) {
        log.error("Wait for syndesis-server failed ", e);
    }
    // this is not part of deployment, but let's have it the same method:
    AmqTemplate.addAccounts();
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Template(io.fabric8.openshift.api.model.Template) TimeoutException(java.util.concurrent.TimeoutException)

Example 8 with Template

use of io.fabric8.openshift.api.model.Template in project syndesis-qe by syndesisio.

the class SyndesisTemplate method deploy.

public static void deploy() {
    OpenShiftUtils.getInstance().cleanAndAssert();
    // get & create restricted SA
    OpenShiftUtils.getInstance().createServiceAccount(getSupportSA());
    // get token from SA `oc secrets get-token` && wait until created to prevent 404
    TestUtils.waitForEvent(Optional::isPresent, () -> OpenShiftUtils.getInstance().getSecrets().stream().filter(s -> s.getMetadata().getName().startsWith("syndesis-oauth-client-token")).findFirst(), TimeUnit.MINUTES, 2, TimeUnit.SECONDS, 5);
    Secret secret = OpenShiftUtils.getInstance().getSecrets().stream().filter(s -> s.getMetadata().getName().startsWith("syndesis-oauth-client-token")).findFirst().get();
    // token is Base64 encoded by default
    String oauthTokenEncoded = secret.getData().get("token");
    byte[] oauthTokenBytes = Base64.decodeBase64(oauthTokenEncoded);
    String oauthToken = new String(oauthTokenBytes);
    // get the template
    Template template = getTemplate();
    // set params
    Map<String, String> templateParams = new HashMap<>();
    templateParams.put("ROUTE_HOSTNAME", TestConfiguration.openShiftNamespace() + "." + TestConfiguration.syndesisUrlSuffix());
    templateParams.put("OPENSHIFT_MASTER", TestConfiguration.openShiftUrl());
    templateParams.put("OPENSHIFT_PROJECT", TestConfiguration.openShiftNamespace());
    templateParams.put("OPENSHIFT_OAUTH_CLIENT_SECRET", oauthToken);
    templateParams.put("TEST_SUPPORT_ENABLED", "true");
    // process & create
    KubernetesList processedTemplate = OpenShiftUtils.getInstance().recreateAndProcessTemplate(template, templateParams);
    OpenShiftUtils.getInstance().createResources(processedTemplate);
    OpenShiftUtils.createRestRoute(TestConfiguration.openShiftNamespace(), TestConfiguration.syndesisUrlSuffix());
    // TODO: there's a bug in openshift-client, we need to initialize manually
    OpenShiftUtils.client().roleBindings().createOrReplaceWithNew().withNewMetadata().withName("syndesis:editors").endMetadata().withNewRoleRef().withName("edit").endRoleRef().addNewSubject().withKind("ServiceAccount").withName(Component.SERVER.getName()).withNamespace(TestConfiguration.openShiftNamespace()).endSubject().addToUserNames(String.format("system:serviceaccount:%s:%s", TestConfiguration.openShiftNamespace(), Component.SERVER.getName())).done();
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) Optional(java.util.Optional) HashMap(java.util.HashMap) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) DoneableTemplate(io.fabric8.openshift.api.model.DoneableTemplate) Template(io.fabric8.openshift.api.model.Template)

Aggregations

HashMap (java.util.HashMap)5 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)3 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)3 PodTemplateSpecBuilder (io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder)3 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)3 ReplicationControllerSpec (io.fabric8.kubernetes.api.model.ReplicationControllerSpec)3 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)3 Map (java.util.Map)3 Exchange (org.apache.camel.Exchange)3 Processor (org.apache.camel.Processor)3 Test (org.junit.Test)3 ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)3 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)2 Template (io.fabric8.openshift.api.model.Template)2 Secret (io.fabric8.kubernetes.api.model.Secret)1 Service (io.fabric8.kubernetes.api.model.Service)1 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)1 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)1 DoneableTemplate (io.fabric8.openshift.api.model.DoneableTemplate)1 IOException (java.io.IOException)1