Search in sources :

Example 96 with Client

use of io.fabric8.kubernetes.client.Client in project kie-wb-common by kiegroup.

the class OpenShiftNameServiceClientListener method trigger.

@Override
public void trigger(OpenShiftClient client, OpenShiftRuntimeConfig runtimeConfig) {
    String prjName = runtimeConfig.getProjectName();
    RouteList routeList = client.getDelegate().routes().inNamespace(prjName).list();
    String routerHost = System.getProperty(OpenShiftNameServiceClientListener.class.getName() + ".routerHost", "10.34.75.115");
    OpenShiftNameService.setRoutes(routeList, routerHost);
}
Also used : RouteList(io.fabric8.openshift.api.model.RouteList)

Example 97 with Client

use of io.fabric8.kubernetes.client.Client in project syndesis-qe by syndesisio.

the class FtpTemplate method deploy.

public static void deploy() {
    List<ContainerPort> ports = new LinkedList<>();
    ports.add(new ContainerPortBuilder().withName("ftp-cmd").withContainerPort(2121).withProtocol("TCP").build());
    for (int i = 0; i < 10; i++) {
        ContainerPort dataPort = new ContainerPortBuilder().withName("ftp-data-" + i).withContainerPort(2300 + i).withProtocol("TCP").build();
        ports.add(dataPort);
    }
    OpenShiftUtils.client().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(APP_NAME).withImage("dsimansk/ftpd:latest").addAllToPorts(ports).endContainer().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
    ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, APP_NAME);
    serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("ftp-cmd").withPort(2121).withTargetPort(new IntOrString(2121)).build());
    for (int i = 0; i < 10; i++) {
        serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("ftp-data-" + i).withPort(2300 + i).withTargetPort(new IntOrString(2300 + i)).build());
    }
    OpenShiftUtils.getInstance().client().services().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
    try {
        OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.areExactlyNPodsReady(LABEL_NAME, APP_NAME, 1));
        Thread.sleep(20 * 1000);
    } catch (InterruptedException | TimeoutException e) {
        log.error("Wait for {} deployment failed ", APP_NAME, e);
    }
    Account ftpAccount = new Account();
    ftpAccount.setService("ftp");
    Map<String, String> accountParameters = new HashMap<>();
    accountParameters.put("host", "ftpd");
    accountParameters.put("port", "2121");
    ftpAccount.setProperties(accountParameters);
    AccountsDirectory.getInstance().addAccount("FTP", ftpAccount);
}
Also used : Account(io.syndesis.qe.accounts.Account) HashMap(java.util.HashMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) LinkedList(java.util.LinkedList) ServiceSpecBuilder(io.fabric8.kubernetes.api.model.ServiceSpecBuilder) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) TimeoutException(java.util.concurrent.TimeoutException)

Example 98 with Client

use of io.fabric8.kubernetes.client.Client 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)

Example 99 with Client

use of io.fabric8.kubernetes.client.Client in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method buildConfig.

/**
 * Build configurations for Openshift client
 *
 * @throws ContainerBasedGatewayException if failed to configure Openshift client
 */
private Config buildConfig() throws ContainerBasedGatewayException {
    System.setProperty(TRY_KUBE_CONFIG, "false");
    System.setProperty(TRY_SERVICE_ACCOUNT, "true");
    ConfigBuilder configBuilder;
    if (masterURL != null) {
        configBuilder = new ConfigBuilder().withMasterUrl(masterURL);
    } else {
        throw new ContainerBasedGatewayException("Kubernetes Master URL is not provided!", ExceptionCodes.ERROR_INITIALIZING_DEDICATED_CONTAINER_BASED_GATEWAY);
    }
    if (!StringUtils.isEmpty(saTokenFileName)) {
        configBuilder.withOauthToken(resolveToken("encrypted" + saTokenFileName));
    }
    return configBuilder.build();
}
Also used : ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)

Example 100 with Client

use of io.fabric8.kubernetes.client.Client in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method initImpl.

/**
 * @see ContainerBasedGatewayGenerator#initImpl(Map)
 */
@Override
void initImpl(Map<String, String> implParameters) throws ContainerBasedGatewayException {
    try {
        setValues(implParameters);
        setClient(new DefaultOpenShiftClient(buildConfig()));
    } catch (KubernetesClientException e) {
        String msg = "Error occurred while creating Default Openshift Client";
        throw new ContainerBasedGatewayException(msg, e, ExceptionCodes.ERROR_INITIALIZING_DEDICATED_CONTAINER_BASED_GATEWAY);
    }
}
Also used : ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)42 Test (org.junit.Test)34 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)29 Service (io.fabric8.kubernetes.api.model.Service)24 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)23 IOException (java.io.IOException)23 File (java.io.File)22 ArrayList (java.util.ArrayList)21 HashMap (java.util.HashMap)20 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)18 Pod (io.fabric8.kubernetes.api.model.Pod)14 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)14 ClientInvokerImpl (io.fabric8.dosgi.tcp.ClientInvokerImpl)8 ServerInvokerImpl (io.fabric8.dosgi.tcp.ServerInvokerImpl)8 URL (java.net.URL)8 Map (java.util.Map)8 ServerInvoker (io.fabric8.dosgi.io.ServerInvoker)7 DockerClient (io.fabric8.docker.client.DockerClient)6 MalformedURLException (java.net.MalformedURLException)6 Session (io.fabric8.arquillian.kubernetes.Session)5