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();
}
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;
}
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);
}
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);
}
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);
}
Aggregations