Search in sources :

Example 46 with DeploymentConfig

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

the class OpenShiftUtils method updateEnvVarInDeploymentConfig.

public static void updateEnvVarInDeploymentConfig(String dcName, String key, String value) {
    DeploymentConfig dc = getInstance().getDeploymentConfig(dcName);
    List<EnvVar> vars = dc.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
    Optional<EnvVar> var = vars.stream().filter(a -> a.getName().equalsIgnoreCase(key)).findFirst();
    if (var.isPresent()) {
        var.get().setValue(value);
    } else {
        log.warn("Variable " + key + " not found in " + dcName + " deployment config, creating it.");
        vars.add(new EnvVar(key, value, null));
    }
    dc.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(vars);
    getInstance().updateDeploymentconfig(dc);
}
Also used : Arrays(java.util.Arrays) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OpenShifts(cz.xtf.core.openshift.OpenShifts) LocalPortForward(io.fabric8.kubernetes.client.LocalPortForward) TimeoutException(java.util.concurrent.TimeoutException) Matcher(java.util.regex.Matcher) OpenShiftBinary(cz.xtf.core.openshift.OpenShiftBinary) VersionInfo(io.fabric8.kubernetes.client.VersionInfo) OpenShift(cz.xtf.core.openshift.OpenShift) TestConfiguration(io.syndesis.qe.TestConfiguration) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) InfraFail(io.syndesis.qe.test.InfraFail) Predicate(java.util.function.Predicate) Pod(io.fabric8.kubernetes.api.model.Pod) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) PodResource(io.fabric8.kubernetes.client.dsl.PodResource) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Assertions.fail(org.assertj.core.api.Assertions.fail) Stream(java.util.stream.Stream) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) OpenShiftWaitUtils(io.syndesis.qe.wait.OpenShiftWaitUtils) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig)

Example 47 with DeploymentConfig

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

the class HTTPValidationSteps method configureKeystore.

@When("^configure keystore in (HTTP|HTTPS) integration dc$")
public void configureKeystore(String protocol) {
    if ("HTTP".equals(protocol)) {
        return;
    }
    try {
        OpenShiftWaitUtils.waitFor(() -> !OpenShiftUtils.getInstance().deploymentConfigs().withLabel("syndesis.io/type", "integration").list().getItems().isEmpty(), 300000L);
    } catch (TimeoutException | InterruptedException e) {
        fail("Unable to find integration deployment config after 5 minutes");
    } catch (Exception e) {
    // ignore
    }
    List<DeploymentConfig> integrationDcs = OpenShiftUtils.getInstance().deploymentConfigs().withLabel("syndesis.io/type", "integration").list().getItems();
    Assertions.assertThat(integrationDcs).as("There should be only one integration deployment config").hasSize(1);
    DeploymentConfig dc = integrationDcs.get(0);
    log.debug("Waiting until next integration state check interval");
    String serverLog = OpenShiftUtils.getPodLogs("syndesis-server");
    while (serverLog.equals(OpenShiftUtils.getPodLogs("syndesis-server"))) {
        TestUtils.sleepIgnoreInterrupt(5000L);
    }
    TestUtils.withRetry(() -> {
        try {
            // @formatter:off
            OpenShiftUtils.getInstance().deploymentConfigs().withName(dc.getMetadata().getName()).edit().editSpec().editTemplate().editSpec().addNewVolume().withName("keystore").withNewSecret().withSecretName(HTTPEndpoints.KEYSTORE_SECRET_NAME).endSecret().endVolume().editFirstContainer().addNewVolumeMount().withNewMountPath("/opt/jboss/").withName("keystore").endVolumeMount().addToEnv(new EnvVar("JAVA_OPTIONS", "-Djackson.deserialization.whitelist.packages=io.syndesis.common.model,io.atlasmap" + " -Djavax.net.ssl.trustStore=/opt/jboss/keystore.p12 -Djavax.net.ssl.trustStorePassword=tomcat -Djavax.net.ssl.trustStoreAlias=tomcat", null)).endContainer().endSpec().endTemplate().endSpec().done();
            // @formatter:on
            // Just to be sure, delete the integration pod if it exists, so that the change in DC is picked up
            OpenShiftUtils.getInstance().deletePods("syndesis.io/type", "integration");
            return true;
        } catch (KubernetesClientException kce) {
            log.debug("Caught KubernetesClientException: ", kce);
            return false;
        }
    }, 3, 30000L, "Unable to edit deployment config");
}
Also used : EnvVar(io.fabric8.kubernetes.api.model.EnvVar) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) When(io.cucumber.java.en.When)

Example 48 with DeploymentConfig

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

the class OpenshiftValidationSteps method checkSar.

@Then("check that SAR check is enabled for namespace {string}")
public void checkSar(String namespace) {
    if (namespace.isEmpty()) {
        namespace = TestConfiguration.openShiftNamespace();
    }
    DeploymentConfig dc = OpenShiftUtils.getInstance().getDeploymentConfig("syndesis-oauthproxy");
    Optional<String> sarArg = dc.getSpec().getTemplate().getSpec().getContainers().get(0).getArgs().stream().filter(arg -> arg.contains("--openshift-sar")).findFirst();
    assertThat(sarArg).isPresent();
    assertThat(sarArg.get()).contains("\"namespace\":\"" + namespace + "\"");
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) Then(io.cucumber.java.en.Then) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) Kafka(io.syndesis.qe.resource.impl.Kafka) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) AMQ(io.syndesis.qe.resource.impl.AMQ) HTTPEndpoints(io.syndesis.qe.resource.impl.HTTPEndpoints) Given(io.cucumber.java.en.Given) Map(java.util.Map) Service(io.fabric8.kubernetes.api.model.Service) DataTable(io.cucumber.datatable.DataTable) MongoDb36(io.syndesis.qe.resource.impl.MongoDb36) TestConfiguration(io.syndesis.qe.TestConfiguration) InfraFail(io.syndesis.qe.test.InfraFail) When(io.cucumber.java.en.When) HorizontalPodAutoscalerBuilder(io.fabric8.kubernetes.api.model.HorizontalPodAutoscalerBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) OpenShiftUtils(io.syndesis.qe.utils.OpenShiftUtils) MySQL(io.syndesis.qe.resource.impl.MySQL) SFTP(io.syndesis.qe.resource.impl.SFTP) WildFlyS2i(io.syndesis.qe.resource.impl.WildFlyS2i) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) TestUtils(io.syndesis.qe.utils.TestUtils) ResourceFactory(io.syndesis.qe.resource.ResourceFactory) FTP(io.syndesis.qe.resource.impl.FTP) Kudu(io.syndesis.qe.resource.impl.Kudu) Optional(java.util.Optional) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) IRC(io.syndesis.qe.resource.impl.IRC) OpenShiftWaitUtils(io.syndesis.qe.wait.OpenShiftWaitUtils) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Then(io.cucumber.java.en.Then)

Example 49 with DeploymentConfig

use of io.fabric8.openshift.api.model.DeploymentConfig in project fabric8 by fabric8io.

the class Util method displaySessionStatus.

public static void displaySessionStatus(KubernetesClient client, Session session) throws MultiException {
    if (client == null) {
        session.getLogger().warn("No KubernetesClient for session: " + session.getId());
        return;
    }
    if (client.isAdaptable(OpenShiftClient.class)) {
        OpenShiftClient oClient = client.adapt(OpenShiftClient.class);
        List<DeploymentConfig> deploymentConfigs = oClient.deploymentConfigs().inNamespace(session.getNamespace()).list().getItems();
        if (deploymentConfigs == null) {
            throw new MultiException("No deployment configs found in namespace" + session.getNamespace());
        }
        for (DeploymentConfig deploymentConfig : deploymentConfigs) {
            session.getLogger().info("Deployment config:" + KubernetesHelper.getName(deploymentConfig));
        }
    } else {
        List<Deployment> deployments = client.extensions().deployments().inNamespace(session.getNamespace()).list().getItems();
        if (deployments == null) {
            throw new MultiException("No deployments found in namespace" + session.getNamespace());
        }
        for (Deployment deployment : deployments) {
            session.getLogger().info("Deployment:" + KubernetesHelper.getName(deployment));
        }
    }
    List<Pod> pods = client.pods().inNamespace(session.getNamespace()).list().getItems();
    if (pods == null) {
        throw new MultiException("No pods found in namespace" + session.getNamespace());
    }
    for (Pod pod : pods) {
        session.getLogger().info("Pod:" + KubernetesHelper.getName(pod) + " Status:" + pod.getStatus());
    }
    List<Service> svcs = client.services().inNamespace(session.getNamespace()).list().getItems();
    if (svcs == null) {
        throw new MultiException("No services found in namespace" + session.getNamespace());
    }
    for (Service service : svcs) {
        session.getLogger().info("Service:" + KubernetesHelper.getName(service) + " IP:" + getPortalIP(service) + " Port:" + getPorts(service));
    }
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) Service(io.fabric8.kubernetes.api.model.Service) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) MultiException(io.fabric8.utils.MultiException)

Example 50 with DeploymentConfig

use of io.fabric8.openshift.api.model.DeploymentConfig in project fabric8 by fabric8io.

the class KubernetesHelper method summaryText.

/**
 * Returns a short summary text message for the given kubernetes resource
 */
public static String summaryText(DeploymentConfig entity) {
    StringBuilder buffer = new StringBuilder();
    DeploymentConfigSpec spec = entity.getSpec();
    if (spec != null) {
        buffer.append("replicas: " + spec.getReplicas());
        PodTemplateSpec podTemplateSpec = spec.getTemplate();
        if (podTemplateSpec != null) {
            appendSummaryText(buffer, podTemplateSpec);
        }
    }
    return buffer.toString();
}
Also used : DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec)

Aggregations

DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)41 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)15 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)14 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)13 Service (io.fabric8.kubernetes.api.model.Service)13 Pod (io.fabric8.kubernetes.api.model.Pod)11 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)11 IOException (java.io.IOException)11 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)9 Test (org.junit.Test)9 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)8 DeploymentConfigSpec (io.fabric8.openshift.api.model.DeploymentConfigSpec)8 Route (io.fabric8.openshift.api.model.Route)8 List (java.util.List)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)7 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)7 ImageStream (io.fabric8.openshift.api.model.ImageStream)7 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 Controller (io.fabric8.kubernetes.api.Controller)6