Search in sources :

Example 76 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project strimzi by strimzi.

the class BundleResource method buildBundleDeployment.

public DeploymentBuilder buildBundleDeployment() {
    Deployment clusterOperator = DeploymentResource.getDeploymentFromYaml(PATH_TO_CO_CONFIG);
    // Get env from config file
    List<EnvVar> envVars = clusterOperator.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
    // Get default CO image
    String coImage = clusterOperator.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
    // Update images
    for (EnvVar envVar : envVars) {
        switch(envVar.getName()) {
            case "STRIMZI_NAMESPACE":
                envVar.setValue(namespaceToWatch);
                envVar.setValueFrom(null);
                break;
            case "STRIMZI_FULL_RECONCILIATION_INTERVAL_MS":
                envVar.setValue(Long.toString(reconciliationInterval));
                break;
            case "STRIMZI_OPERATION_TIMEOUT_MS":
                envVar.setValue(Long.toString(operationTimeout));
                break;
            case "STRIMZI_FEATURE_GATES":
                envVar.setValue(Environment.STRIMZI_FEATURE_GATES);
            default:
                if (envVar.getName().contains("KAFKA_BRIDGE_IMAGE")) {
                    envVar.setValue(Environment.useLatestReleasedBridge() ? envVar.getValue() : Environment.BRIDGE_IMAGE);
                } else if (envVar.getName().contains("STRIMZI_DEFAULT")) {
                    envVar.setValue(StUtils.changeOrgAndTag(envVar.getValue()));
                } else if (envVar.getName().contains("IMAGES")) {
                    envVar.setValue(StUtils.changeOrgAndTagInImageMap(envVar.getValue()));
                }
        }
    }
    envVars.add(new EnvVar("STRIMZI_IMAGE_PULL_POLICY", Environment.COMPONENTS_IMAGE_PULL_POLICY, null));
    envVars.add(new EnvVar("STRIMZI_LOG_LEVEL", Environment.STRIMZI_LOG_LEVEL, null));
    if (extraEnvVars != null) {
        envVars.forEach(envVar -> extraEnvVars.stream().filter(extraVar -> envVar.getName().equals(extraVar.getName())).findFirst().ifPresent(xVar -> envVar.setValue(xVar.getValue())));
    }
    if (Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET != null && !Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET.isEmpty()) {
        // for strimzi-operator
        List<LocalObjectReference> imagePullSecrets = Collections.singletonList(new LocalObjectReference(Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET));
        clusterOperator.getSpec().getTemplate().getSpec().setImagePullSecrets(imagePullSecrets);
        // for kafka
        envVars.add(new EnvVar("STRIMZI_IMAGE_PULL_SECRETS", Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET, null));
    }
    // adding custom evn vars specified by user in installation
    if (extraEnvVars != null) {
        envVars.addAll(extraEnvVars);
    }
    // Remove duplicates from envVars
    List<EnvVar> envVarsWithoutDuplicates = envVars.stream().distinct().collect(Collectors.toList());
    // Apply updated env variables
    clusterOperator.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(envVarsWithoutDuplicates);
    return new DeploymentBuilder(clusterOperator).editMetadata().withName(name).withNamespace(namespaceInstallTo).addToLabels(Constants.DEPLOYMENT_TYPE, DeploymentTypes.BundleClusterOperator.name()).endMetadata().editSpec().withNewSelector().addToMatchLabels("name", Constants.STRIMZI_DEPLOYMENT_NAME).addToMatchLabels(this.extraLabels).endSelector().editTemplate().editMetadata().addToLabels(this.extraLabels).endMetadata().editSpec().editFirstContainer().withImage(StUtils.changeOrgAndTag(coImage)).withImagePullPolicy(Environment.OPERATOR_IMAGE_PULL_POLICY).endContainer().editFirstVolume().editEmptyDir().withNewSizeLimit("2Mi").endEmptyDir().endVolume().endSpec().endTemplate().endSpec();
}
Also used : Environment(io.strimzi.systemtest.Environment) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Constants(io.strimzi.systemtest.Constants) DeploymentTypes(io.strimzi.systemtest.enums.DeploymentTypes) HashMap(java.util.HashMap) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) Collectors(java.util.stream.Collectors) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) ArrayList(java.util.ArrayList) List(java.util.List) DeploymentUtils(io.strimzi.systemtest.utils.kubeUtils.controllers.DeploymentUtils) ResourceManager(io.strimzi.systemtest.resources.ResourceManager) Map(java.util.Map) TestUtils(io.strimzi.test.TestUtils) ResourceType(io.strimzi.systemtest.resources.ResourceType) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentResource(io.strimzi.systemtest.resources.kubernetes.DeploymentResource) StUtils(io.strimzi.systemtest.utils.StUtils) Collections(java.util.Collections) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)

Example 77 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project apicurio-registry by Apicurio.

the class DeploymentResourceType method getDefaultPostgresql.

public static Deployment getDefaultPostgresql(String name, String namespace) {
    return new DeploymentBuilder().withNewMetadata().addToLabels("app", name).withName(name).withNamespace(namespace).endMetadata().withNewSpec().withReplicas(1).withNewSelector().addToMatchLabels("app", name).endSelector().withNewTemplate().withNewMetadata().addToLabels("app", name).endMetadata().withNewSpec().withContainers(getDefaultPostgresqlContainer(name)).withVolumes(new Volume() {

        {
            setName(name);
            setPersistentVolumeClaim(new PersistentVolumeClaimVolumeSource() {

                {
                    setClaimName(name);
                }
            });
        }
    }).withRestartPolicy("Always").endSpec().endTemplate().endSpec().build();
}
Also used : Volume(io.fabric8.kubernetes.api.model.Volume) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) PersistentVolumeClaimVolumeSource(io.fabric8.kubernetes.api.model.PersistentVolumeClaimVolumeSource)

Example 78 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project strimzi-kafka-operator 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();
}
Also used : ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) HashMap(java.util.HashMap) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)

Example 79 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project module-ballerina-c2c by ballerina-platform.

the class DeploymentHandler method generate.

/**
 * Generate kubernetes deployment definition from annotation.
 *
 * @param deploymentModel @{@link DeploymentModel} definition
 * @throws KubernetesPluginException If an error occurs while generating artifact.
 */
private void generate(DeploymentModel deploymentModel) throws KubernetesPluginException {
    List<ContainerPort> containerPorts = null;
    if (deploymentModel.getPorts() != null) {
        containerPorts = deploymentModel.getPorts();
    }
    Container container = generateContainer(deploymentModel, containerPorts);
    Deployment deployment = new DeploymentBuilder().withNewMetadata().withName(deploymentModel.getName()).withLabels(deploymentModel.getLabels()).withAnnotations(deploymentModel.getAnnotations()).withNamespace(dataHolder.getNamespace()).endMetadata().withNewSpec().withNewSelector().withMatchLabels(deploymentModel.getLabels()).endSelector().withStrategy(deploymentModel.getStrategy()).withReplicas(deploymentModel.getReplicas()).withNewTemplate().withNewMetadata().addToLabels(deploymentModel.getLabels()).addToAnnotations(deploymentModel.getPodAnnotations()).endMetadata().withNewSpec().withContainers(container).withImagePullSecrets(getImagePullSecrets(deploymentModel)).withVolumes(populateVolume(deploymentModel)).withNodeSelector(deploymentModel.getNodeSelector()).endSpec().endTemplate().endSpec().build();
    try {
        String deploymentContent = KubernetesUtils.asYaml(deployment);
        String outputFileName = DEPLOYMENT_FILE_POSTFIX + KubernetesConstants.YAML;
        if (dataHolder.isSingleYaml()) {
            outputFileName = deployment.getMetadata().getName() + KubernetesConstants.YAML;
        }
        KubernetesUtils.writeToFile(deploymentContent, outputFileName);
    } catch (IOException e) {
        Diagnostic diagnostic = C2CDiagnosticCodes.createDiagnostic(C2CDiagnosticCodes.ARTIFACT_GEN_FAILED, new NullLocation(), "deployment", deploymentModel.getName());
        throw new KubernetesPluginException(diagnostic);
    }
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) NullLocation(io.ballerina.c2c.diagnostics.NullLocation) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Diagnostic(io.ballerina.tools.diagnostics.Diagnostic) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IOException(java.io.IOException) KubernetesPluginException(io.ballerina.c2c.exceptions.KubernetesPluginException) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)

Example 80 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project iobserve-analysis by research-iobserve.

the class AllocationExecutor method execute.

@Override
public void execute(final AllocateNodeAction action) {
    final ResourceContainer resourceContainer = action.getTargetResourceContainer();
    final String rcName = this.normalizeComponentName(resourceContainer.getEntityName());
    final Map<String, String> labels = this.computeDeploymentLabels(resourceContainer);
    // Build deployment blueprint
    final Deployment podDeployment = // 
    new DeploymentBuilder().withApiVersion(// 
    AllocationExecutor.API_VERSION).withKind(// 
    "Deployment").withNewMetadata().withLabels(// 
    labels).withName(// 
    rcName).endMetadata().withNewSpec().withReplicas(// 
    1).withNewSelector().addToMatchLabels(AllocationExecutor.COMPONENT_LABEL_KEY, // 
    rcName).endSelector().withNewTemplate().withNewMetadata().addToLabels(AllocationExecutor.COMPONENT_LABEL_KEY, // 
    rcName).withName(// 
    rcName).endMetadata().withNewSpec().withHostname(// 
    rcName).withSubdomain(// 
    this.subdomain).addNewContainer().withImage(// 
    this.imageLocator).withName(// 
    "").withNewResources().endResources().addNewEnv().withName(// 
    "LOGGER").withValue(// 
    "%LOGGER%").endEnv().endContainer().endSpec().endTemplate().endSpec().build();
    this.podsToDeploy.put(rcName, podDeployment);
    if (AllocationExecutor.LOGGER.isDebugEnabled()) {
        AllocationExecutor.LOGGER.debug("Created blueprint for pod deployment " + podDeployment.getMetadata().getName());
    }
}
Also used : Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Aggregations

DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)153 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)80 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)60 Test (org.junit.Test)60 Test (org.junit.jupiter.api.Test)32 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)26 Expectations (mockit.Expectations)26 Test (org.testng.annotations.Test)22 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)17 ArrayList (java.util.ArrayList)17 Container (io.fabric8.kubernetes.api.model.Container)16 HashMap (java.util.HashMap)16 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)15 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)15 DeploymentBuilder (io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)14 Properties (java.util.Properties)14 Pod (io.fabric8.kubernetes.api.model.Pod)13 PodTemplateSpecBuilder (io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder)13 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)12 InternalRecipe (org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe)12