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