use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project strimzi by strimzi.
the class AbstractModel method createDeployment.
protected Deployment createDeployment(List<ContainerPort> ports, Probe livenessProbe, Probe readinessProbe, DeploymentStrategy updateStrategy, Map<String, String> deploymentAnnotations, Map<String, String> podAnnotations) {
Container container = new ContainerBuilder().withName(name).withImage(getImage()).withEnv(getEnvVars()).withPorts(ports).withLivenessProbe(livenessProbe).withReadinessProbe(readinessProbe).build();
Deployment dep = new DeploymentBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName()).withNamespace(namespace).withAnnotations(deploymentAnnotations).endMetadata().withNewSpec().withStrategy(updateStrategy).withReplicas(replicas).withNewTemplate().withNewMetadata().withLabels(getLabelsWithName()).withAnnotations(podAnnotations).endMetadata().withNewSpec().withServiceAccountName(getServiceAccountName()).withContainers(container).endSpec().endTemplate().endSpec().build();
return dep;
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project elastest-torm by elastest.
the class K8sService method deployResourcesFromProject.
public List<PodInfo> deployResourcesFromProject(String projectName, String namespace) throws Exception {
PodInfo podInfo = new PodInfo();
List<PodInfo> podsInfoList = new ArrayList<>();
DockerProject project = projects.get(projectName);
logger.debug("Project to deploy: {}", projectName);
logger.debug("Resources as string: {}", project.getYml());
namespace = namespace == null || namespace.isEmpty() ? DEFAULT_NAMESPACE : namespace;
try (InputStream is = IOUtils.toInputStream(project.getYml(), CharEncoding.UTF_8)) {
List<HasMetadata> resourcesMetadata = client.load(is).inNamespace(namespace).get();
project.getEnv().put("ETM_K8S_API_TOKEN", getServiceAccountToken());
project.getEnv().put("ETM_K8S_API_URL", client.getConfiguration().getMasterUrl());
logger.debug("Add these environment variables:");
project.getEnv().forEach((key, value) -> {
logger.debug("Env var {} with value {}", key, value);
});
logger.debug("Number of deployments loaded: {}", resourcesMetadata.size());
for (HasMetadata metadata : resourcesMetadata) {
switch(metadata.getKind()) {
case "Deployment":
String deploymentName = ((Deployment) metadata).getMetadata().getName();
logger.debug("Editing and deploying service {}:", deploymentName);
DeploymentBuilder deploymentBuilder = new DeploymentBuilder(((Deployment) metadata));
Deployment deployment = deploymentBuilder.editSpec().editTemplate().editMetadata().addToLabels(project.getLabels()).endMetadata().editSpec().editContainer(0).addAllToEnv(getEnvVarListFromMap(project.getEnv())).endContainer().endSpec().endTemplate().endSpec().build();
logger.debug("Deployment {} content: {}", deploymentName, deployment.toString());
client.apps().deployments().inNamespace(namespace).createOrReplace(deployment);
client.apps().deployments().inNamespace(namespace).withName(deploymentName).waitUntilReady(5, TimeUnit.MINUTES);
break;
case "PersistentVolumeClaim":
PersistentVolumeClaimBuilder pVCBuilder = new PersistentVolumeClaimBuilder((PersistentVolumeClaim) metadata);
if (client.persistentVolumeClaims().inNamespace(namespace).withName("elastest-" + projectName + "-data-claim").get() == null) {
client.persistentVolumeClaims().inNamespace(namespace).create(pVCBuilder.build());
}
break;
case "Service":
logger.debug("Creating k8s service \"{}\" with data {}", ((Service) metadata).getMetadata().getName(), metadata.toString());
ServiceBuilder serviceBuilder = new ServiceBuilder((Service) metadata);
if (client.services().inNamespace(namespace).withName(projectName).get() == null) {
client.services().inNamespace(namespace).create(serviceBuilder.build());
}
default:
break;
}
}
} catch (IOException | InterruptedException e) {
logger.error("Error loading deployment from a yaml string");
e.printStackTrace();
throw e;
}
return podsInfoList;
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project strimzi by strimzi.
the class KafkaClientsTemplates method kafkaClients.
public static DeploymentBuilder kafkaClients(String namespaceName, boolean tlsListener, String kafkaClientsName, boolean hostnameVerification, String listenerName, String secretPrefix, KafkaUser... kafkaUsers) {
Map<String, String> label = new HashMap<>();
label.put(Constants.KAFKA_CLIENTS_LABEL_KEY, Constants.KAFKA_CLIENTS_LABEL_VALUE);
label.put(Constants.DEPLOYMENT_TYPE, DeploymentTypes.KafkaClients.name());
DeploymentBuilder kafkaClient = new DeploymentBuilder().withNewMetadata().withName(kafkaClientsName).withLabels(label).withNamespace(namespaceName).endMetadata().withNewSpec().withNewSelector().addToMatchLabels("app", kafkaClientsName).addToMatchLabels(label).endSelector().withReplicas(1).withNewTemplate().withNewMetadata().addToLabels("app", kafkaClientsName).addToLabels(label).endMetadata().withSpec(createClientSpec(namespaceName, tlsListener, kafkaClientsName, hostnameVerification, listenerName, secretPrefix, kafkaUsers)).endTemplate().endSpec();
return kafkaClient;
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project strimzi by strimzi.
the class ScraperTemplates method scraperPod.
public static DeploymentBuilder scraperPod(String namespaceName, String podName) {
Map<String, String> label = new HashMap<>();
label.put(Constants.SCRAPER_LABEL_KEY, Constants.SCRAPER_LABEL_VALUE);
label.put(Constants.DEPLOYMENT_TYPE, DeploymentTypes.Scraper.name());
return new DeploymentBuilder().withNewMetadata().withName(podName).withLabels(label).withNamespace(namespaceName).endMetadata().withNewSpec().withNewSelector().addToMatchLabels("app", podName).addToMatchLabels(label).endSelector().withReplicas(1).withNewTemplate().withNewMetadata().addToLabels("app", podName).addToLabels(label).endMetadata().withNewSpec().withContainers(new ContainerBuilder().withName(podName).withImage("registry.access.redhat.com/ubi8/openjdk-11:latest").withCommand("sleep").withArgs("infinity").withImagePullPolicy(Environment.COMPONENTS_IMAGE_PULL_POLICY).withResources(new ResourceRequirementsBuilder().addToRequests("memory", new Quantity("200M")).build()).build()).endSpec().endTemplate().endSpec();
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project strimzi by strimzi.
the class MockKube2ControllersTest method testDeploymentController.
@Test
public void testDeploymentController() {
final String deploymentName = "my-deployment";
client.apps().deployments().inNamespace(NAMESPACE).create(new DeploymentBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(deploymentName).endMetadata().withNewSpec().withReplicas(3).withSelector(new LabelSelector(null, Map.of("app", "my-app"))).withNewTemplate().withNewSpec().withContainers(new ContainerBuilder().withName("nginx").withImage("nginx:1.14.2").build()).endSpec().endTemplate().endSpec().build());
TestUtils.waitFor("Wait for deployment to have status", 100L, 10_000L, () -> client.apps().deployments().inNamespace(NAMESPACE).withName(deploymentName).get() != null && client.apps().deployments().inNamespace(NAMESPACE).withName(deploymentName).get().getStatus() != null);
Deployment createdDeployment = client.apps().deployments().inNamespace(NAMESPACE).withName(deploymentName).get();
assertThat(createdDeployment, is(notNullValue()));
assertThat(createdDeployment.getStatus(), is(notNullValue()));
assertThat(createdDeployment.getStatus().getReplicas(), is(3));
assertThat(createdDeployment.getStatus().getAvailableReplicas(), is(3));
assertThat(createdDeployment.getStatus().getObservedGeneration(), is(1L));
}
Aggregations