Search in sources :

Example 6 with ServiceAccount

use of io.fabric8.kubernetes.api.model.ServiceAccount in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetesTestCase method testInitWhileExternalTokenFileNameNotGiven.

@Test(description = "Test init method when external service account token file name is NOT given")
public void testInitWhileExternalTokenFileNameNotGiven() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class);
    ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
    sdKubernetes.setClient(openShiftClient);
    try {
        sdKubernetes.initImpl(createImplParametersMap(""));
    } catch (ServiceDiscoveryException e) {
        // since pod's token is then searched, this is exception msg we get
        Assert.assertEquals(e.getCause().getMessage(), "Error while reading file /var/run/secrets/kubernetes.io/serviceaccount/token");
    }
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ServiceDiscoveryException(org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 7 with ServiceAccount

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

the class KubernetesServiceAccountsProducerTest method listTest.

@Test
public void listTest() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    List<ServiceAccount> result = template.requestBody("direct:list", "", List.class);
    boolean fabric8Exists = false;
    Iterator<ServiceAccount> it = result.iterator();
    while (it.hasNext()) {
        ServiceAccount service = it.next();
        if ("fabric8".equalsIgnoreCase(service.getMetadata().getName())) {
            fabric8Exists = true;
        }
    }
    assertTrue(fabric8Exists);
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Test(org.junit.Test)

Example 8 with ServiceAccount

use of io.fabric8.kubernetes.api.model.ServiceAccount 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

ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)6 DoneableServiceAccount (io.fabric8.kubernetes.api.model.DoneableServiceAccount)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Test (org.junit.Test)3 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 Secret (io.fabric8.kubernetes.api.model.Secret)1 ServiceAccountList (io.fabric8.kubernetes.api.model.ServiceAccountList)1 Resource (io.fabric8.kubernetes.client.dsl.Resource)1 DoneableTemplate (io.fabric8.openshift.api.model.DoneableTemplate)1 Template (io.fabric8.openshift.api.model.Template)1 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)1 Optional (java.util.Optional)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1 ServiceDiscoveryException (org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException)1