Search in sources :

Example 1 with ObjectMeta

use of io.fabric8.kubernetes.api.model.ObjectMeta in project camel by apache.

the class KubernetesServiceAccountsProducerTest method createAndDeleteServiceAccount.

@Test
public void createAndDeleteServiceAccount() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    Exchange ex = template.request("direct:create", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT_NAME, "test");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SERVICE_ACCOUNTS_LABELS, labels);
            ServiceAccount s = new ServiceAccount();
            s.setKind("ServiceAccount");
            Map<String, String> mp = new HashMap<String, String>();
            mp.put("username", Base64.encodeBase64String("pippo".getBytes()));
            mp.put("password", Base64.encodeBase64String("password".getBytes()));
            ObjectMeta meta = new ObjectMeta();
            meta.setName("test");
            s.setMetadata(meta);
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT, s);
        }
    });
    ServiceAccount sec = ex.getOut().getBody(ServiceAccount.class);
    assertEquals(sec.getMetadata().getName(), "test");
    ex = template.request("direct:delete", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT_NAME, "test");
        }
    });
    boolean secDeleted = ex.getOut().getBody(Boolean.class);
    assertTrue(secDeleted);
}
Also used : Exchange(org.apache.camel.Exchange) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Processor(org.apache.camel.Processor) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with ObjectMeta

use of io.fabric8.kubernetes.api.model.ObjectMeta in project camel by apache.

the class KubernetesSecretsProducerTest method createAndDeleteSecret.

@Test
public void createAndDeleteSecret() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    Exchange ex = template.request("direct:create", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SECRET_NAME, "test");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SECRETS_LABELS, labels);
            Secret s = new Secret();
            s.setKind("Secret");
            Map<String, String> mp = new HashMap<String, String>();
            mp.put("username", Base64.encodeBase64String("pippo".getBytes()));
            mp.put("password", Base64.encodeBase64String("password".getBytes()));
            s.setData(mp);
            ObjectMeta meta = new ObjectMeta();
            meta.setName("test");
            s.setMetadata(meta);
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SECRET, s);
        }
    });
    Secret sec = ex.getOut().getBody(Secret.class);
    assertEquals(sec.getMetadata().getName(), "test");
    ex = template.request("direct:delete", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SECRET_NAME, "test");
        }
    });
    boolean secDeleted = ex.getOut().getBody(Boolean.class);
    assertTrue(secDeleted);
}
Also used : Exchange(org.apache.camel.Exchange) Secret(io.fabric8.kubernetes.api.model.Secret) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Processor(org.apache.camel.Processor) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 Test (org.junit.Test)2 Secret (io.fabric8.kubernetes.api.model.Secret)1 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)1