Search in sources :

Example 1 with Build

use of io.fabric8.openshift.api.model.Build in project che by eclipse.

the class OpenShiftConnector method createOpenShiftDeployment.

private String createOpenShiftDeployment(String workspaceID, String imageName, String sanitizedContainerName, Set<String> exposedPorts, String[] envVariables, String[] volumes, boolean runContainerAsRoot) {
    String deploymentName = CHE_OPENSHIFT_RESOURCES_PREFIX + workspaceID;
    LOG.info("Creating OpenShift deployment {}", deploymentName);
    Map<String, String> selector = Collections.singletonMap(OPENSHIFT_DEPLOYMENT_LABEL, deploymentName);
    LOG.info("Adding container {} to OpenShift deployment {}", sanitizedContainerName, deploymentName);
    Long UID = runContainerAsRoot ? UID_ROOT : UID_USER;
    Container container = new ContainerBuilder().withName(sanitizedContainerName).withImage(imageName).withEnv(KubernetesEnvVar.getEnvFrom(envVariables)).withPorts(KubernetesContainer.getContainerPortsFrom(exposedPorts)).withImagePullPolicy(OPENSHIFT_IMAGE_PULL_POLICY_IFNOTPRESENT).withNewSecurityContext().withRunAsUser(UID).withPrivileged(true).endSecurityContext().withLivenessProbe(getLivenessProbeFrom(exposedPorts)).withVolumeMounts(getVolumeMountsFrom(volumes, workspaceID)).build();
    PodSpec podSpec = new PodSpecBuilder().withContainers(container).withVolumes(getVolumesFrom(volumes, workspaceID)).withServiceAccountName(this.openShiftCheServiceAccount).build();
    Deployment deployment = new DeploymentBuilder().withNewMetadata().withName(deploymentName).withNamespace(this.openShiftCheProjectName).endMetadata().withNewSpec().withReplicas(1).withNewSelector().withMatchLabels(selector).endSelector().withNewTemplate().withNewMetadata().withLabels(selector).endMetadata().withSpec(podSpec).endTemplate().endSpec().build();
    deployment = openShiftClient.extensions().deployments().inNamespace(this.openShiftCheProjectName).create(deployment);
    LOG.info("OpenShift deployment {} created", deploymentName);
    return deployment.getMetadata().getName();
}
Also used : PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) KubernetesContainer(org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesContainer) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)

Example 2 with Build

use of io.fabric8.openshift.api.model.Build in project che by eclipse.

the class OpenShiftConnector method getVolumeMountsFrom.

private List<VolumeMount> getVolumeMountsFrom(String[] volumes, String workspaceID) {
    List<VolumeMount> vms = new ArrayList<>();
    for (String volume : volumes) {
        String mountPath = volume.split(":", 3)[1];
        String volumeName = getVolumeName(volume);
        VolumeMount vm = new VolumeMountBuilder().withMountPath(mountPath).withName("ws-" + workspaceID + "-" + volumeName).build();
        vms.add(vm);
    }
    return vms;
}
Also used : ArrayList(java.util.ArrayList) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder)

Example 3 with Build

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

the class KubernetesServicesProducer method doCreateService.

protected void doCreateService(Exchange exchange, String operation) throws Exception {
    Service service = null;
    String serviceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    ServiceSpec serviceSpec = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_SPEC, ServiceSpec.class);
    if (ObjectHelper.isEmpty(serviceName)) {
        LOG.error("Create a specific service require specify a service name");
        throw new IllegalArgumentException("Create a specific service require specify a service name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Create a specific service require specify a namespace name");
        throw new IllegalArgumentException("Create a specific service require specify a namespace name");
    }
    if (ObjectHelper.isEmpty(serviceSpec)) {
        LOG.error("Create a specific service require specify a service spec bean");
        throw new IllegalArgumentException("Create a specific service require specify a service spec bean");
    }
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_SERVICE_LABELS, Map.class);
    Service serviceCreating = new ServiceBuilder().withNewMetadata().withName(serviceName).withLabels(labels).endMetadata().withSpec(serviceSpec).build();
    service = getEndpoint().getKubernetesClient().services().inNamespace(namespaceName).create(serviceCreating);
    exchange.getOut().setBody(service);
}
Also used : ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) DoneableService(io.fabric8.kubernetes.api.model.DoneableService) Service(io.fabric8.kubernetes.api.model.Service) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

Example 4 with Build

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

the class KubernetesNamespacesProducer method doCreateNamespace.

protected void doCreateNamespace(Exchange exchange, String operation) {
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Create a specific namespace require specify a namespace name");
        throw new IllegalArgumentException("Create a specific namespace require specify a namespace name");
    }
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, Map.class);
    Namespace ns = new NamespaceBuilder().withNewMetadata().withName(namespaceName).withLabels(labels).endMetadata().build();
    Namespace namespace = getEndpoint().getKubernetesClient().namespaces().create(ns);
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(namespace);
}
Also used : DoneableNamespace(io.fabric8.kubernetes.api.model.DoneableNamespace) Namespace(io.fabric8.kubernetes.api.model.Namespace) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder)

Example 5 with Build

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

the class KubernetesBuildConfigsProducer method doGetBuildConfig.

protected void doGetBuildConfig(Exchange exchange, String operation) throws Exception {
    BuildConfig buildConfig = null;
    String buildConfigName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILD_CONFIG_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (ObjectHelper.isEmpty(buildConfigName)) {
        LOG.error("Get a specific Build Config require specify a Build Config name");
        throw new IllegalArgumentException("Get a specific Build Config require specify a Build Config name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Get a specific Build Config require specify a namespace name");
        throw new IllegalArgumentException("Get a specific Build Config require specify a namespace name");
    }
    buildConfig = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs().inNamespace(namespaceName).withName(buildConfigName).get();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(buildConfig);
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DoneableBuildConfig(io.fabric8.openshift.api.model.DoneableBuildConfig) BuildConfig(io.fabric8.openshift.api.model.BuildConfig)

Aggregations

Test (org.junit.Test)255 ArrayList (java.util.ArrayList)74 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)69 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)68 HashMap (java.util.HashMap)66 File (java.io.File)53 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)51 IOException (java.io.IOException)50 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)45 Pod (io.fabric8.kubernetes.api.model.Pod)37 Map (java.util.Map)35 Service (io.fabric8.kubernetes.api.model.Service)34 FabricService (io.fabric8.api.FabricService)33 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)30 Container (io.fabric8.api.Container)29 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)28 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)27 List (java.util.List)26 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)25 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)25