use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project flink by apache.
the class KubernetesJobManagerFactory method createJobManagerDeployment.
private static Deployment createJobManagerDeployment(FlinkPod flinkPod, KubernetesJobManagerParameters kubernetesJobManagerParameters) {
final Container resolvedMainContainer = flinkPod.getMainContainer();
final Pod resolvedPod = new PodBuilder(flinkPod.getPodWithoutMainContainer()).editOrNewSpec().addToContainers(resolvedMainContainer).endSpec().build();
return new DeploymentBuilder().withApiVersion(Constants.APPS_API_VERSION).editOrNewMetadata().withName(KubernetesUtils.getDeploymentName(kubernetesJobManagerParameters.getClusterId())).withAnnotations(kubernetesJobManagerParameters.getAnnotations()).withLabels(kubernetesJobManagerParameters.getLabels()).withOwnerReferences(kubernetesJobManagerParameters.getOwnerReference().stream().map(e -> KubernetesOwnerReference.fromMap(e).getInternalResource()).collect(Collectors.toList())).endMetadata().editOrNewSpec().withReplicas(kubernetesJobManagerParameters.getReplicas()).editOrNewTemplate().withMetadata(resolvedPod.getMetadata()).withSpec(resolvedPod.getSpec()).endTemplate().editOrNewSelector().addToMatchLabels(kubernetesJobManagerParameters.getSelectors()).endSelector().endSpec().build();
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project TOSCAna by StuPro-TOSCAna.
the class ResourceDeployment method build.
@Override
public ResourceDeployment build() {
ArrayList<Container> containers = new ArrayList<>();
// Create the Container objects of the containers belonging in the Pod
pod.getContainers().forEach(e -> {
Container container = new ContainerBuilder().withImage(e.getDockerImageTag().get()).withName(e.getCleanStackName()).withImagePullPolicy("Always").addAllToPorts(e.getOpenPorts().stream().map(Port::toContainerPort).collect(Collectors.toList())).build();
containers.add(container);
});
deployment = new DeploymentBuilder().withNewMetadata().withName(pod.getDeploymentName()).addToLabels("app", name).endMetadata().withNewSpec().withReplicas(pod.getReplicaCount()).withNewSelector().addToMatchLabels("app", name).endSelector().withNewTemplate().withNewMetadata().withName(name).addToLabels("app", name).endMetadata().withNewSpec().addAllToContainers(containers).endSpec().endTemplate().endSpec().build();
return this;
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project fabric8 by jboss-fuse.
the class YamlSerialiseTest method testSerialiseYaml.
@Test
public void testSerialiseYaml() throws Exception {
Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("foo").endMetadata().withNewSpec().withReplicas(1).withNewTemplate().withNewSpec().addNewContainer().withImage("cheese").endContainer().endSpec().endTemplate().endSpec().build();
File outFile = new File(new File(basedir), "target/test-data/deployment.yml");
outFile.getParentFile().mkdirs();
KubernetesHelper.saveYamlNotEmpty(deployment, outFile);
String yaml = IOHelpers.readFully(outFile);
System.out.println("YAML: " + yaml);
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project fabric8-maven-plugin by fabric8io.
the class DefaultControllerEnricher method addMissingResources.
@Override
public void addMissingResources(KubernetesListBuilder builder) {
final String name = getConfig(Config.name, MavenUtil.createDefaultResourceName(getProject()));
final ResourceConfig config = new ResourceConfig.Builder().controllerName(name).imagePullPolicy(getConfig(Config.pullPolicy)).withReplicas(Configs.asInt(getConfig(Config.replicaCount))).build();
final List<ImageConfiguration> images = getImages();
// Check if at least a replica set is added. If not add a default one
if (!KubernetesResourceUtil.checkForKind(builder, POD_CONTROLLER_KINDS)) {
// At least one image must be present, otherwise the resulting config will be invalid
if (!Lists.isNullOrEmpty(images)) {
String type = getConfig(Config.type);
if ("deployment".equalsIgnoreCase(type)) {
log.info("Adding a default Deployment");
builder.addToDeploymentItems(deployHandler.getDeployment(config, images));
} else if ("statefulSet".equalsIgnoreCase(type)) {
log.info("Adding a default StatefulSet");
builder.addToStatefulSetItems(statefulSetHandler.getStatefulSet(config, images));
} else if ("daemonSet".equalsIgnoreCase(type)) {
log.info("Adding a default DaemonSet");
builder.addToDaemonSetItems(daemonSetHandler.getDaemonSet(config, images));
} else if ("replicaSet".equalsIgnoreCase(type)) {
log.info("Adding a default ReplicaSet");
builder.addToReplicaSetItems(rsHandler.getReplicaSet(config, images));
} else if ("replicationController".equalsIgnoreCase(type)) {
log.info("Adding a default ReplicationController");
builder.addToReplicationControllerItems(rcHandler.getReplicationController(config, images));
} else if ("job".equalsIgnoreCase(type)) {
log.info("Adding a default Job");
builder.addToJobItems(jobHandler.getJob(config, images));
}
}
} else if (KubernetesResourceUtil.checkForKind(builder, "StatefulSet")) {
final StatefulSetSpec spec = statefulSetHandler.getStatefulSet(config, images).getSpec();
if (spec != null) {
builder.accept(new TypedVisitor<StatefulSetBuilder>() {
@Override
public void visit(StatefulSetBuilder statefulSetBuilder) {
statefulSetBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
mergeStatefulSetSpec(statefulSetBuilder, spec);
}
});
if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
final PodSpec podSpec = spec.getTemplate().getSpec();
builder.accept(new TypedVisitor<PodSpecBuilder>() {
@Override
public void visit(PodSpecBuilder builder) {
KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
}
});
}
}
} else {
final DeploymentSpec spec = deployHandler.getDeployment(config, images).getSpec();
if (spec != null) {
builder.accept(new TypedVisitor<DeploymentBuilder>() {
@Override
public void visit(DeploymentBuilder deploymentBuilder) {
deploymentBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
mergeDeploymentSpec(deploymentBuilder, spec);
}
});
if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
final PodSpec podSpec = spec.getTemplate().getSpec();
builder.accept(new TypedVisitor<PodSpecBuilder>() {
@Override
public void visit(PodSpecBuilder builder) {
KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
}
});
}
}
}
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project fabric8-maven-plugin by fabric8io.
the class KubernetesResourceUtil method mergeDeployments.
protected static HasMetadata mergeDeployments(Deployment resource1, Deployment resource2, Logger log, boolean switchOnLocalCustomisation) {
Deployment resource1OrCopy = resource1;
if (!switchOnLocalCustomisation) {
// lets copy the original to avoid modifying it
resource1OrCopy = new DeploymentBuilder(resource1OrCopy).build();
}
HasMetadata answer = resource1OrCopy;
DeploymentSpec spec1 = resource1OrCopy.getSpec();
DeploymentSpec spec2 = resource2.getSpec();
if (spec1 == null) {
resource1OrCopy.setSpec(spec2);
} else {
PodTemplateSpec template1 = spec1.getTemplate();
PodTemplateSpec template2 = null;
if (spec2 != null) {
template2 = spec2.getTemplate();
}
if (template1 != null && template2 != null) {
mergeMetadata(template1, template2);
}
if (template1 == null) {
spec1.setTemplate(template2);
} else {
PodSpec podSpec1 = template1.getSpec();
PodSpec podSpec2 = null;
if (template2 != null) {
podSpec2 = template2.getSpec();
}
if (podSpec1 == null) {
template1.setSpec(podSpec2);
} else {
String defaultName = null;
PodTemplateSpec updateTemplate = template1;
if (switchOnLocalCustomisation) {
HasMetadata override = resource2;
if (isLocalCustomisation(podSpec1)) {
updateTemplate = template2;
PodSpec tmp = podSpec1;
podSpec1 = podSpec2;
podSpec2 = tmp;
} else {
answer = resource2;
override = resource1OrCopy;
}
mergeMetadata(answer, override);
} else {
mergeMetadata(resource1OrCopy, resource2);
}
if (updateTemplate != null) {
if (podSpec2 == null) {
updateTemplate.setSpec(podSpec1);
} else {
PodSpecBuilder podSpecBuilder = new PodSpecBuilder(podSpec1);
mergePodSpec(podSpecBuilder, podSpec2, defaultName);
updateTemplate.setSpec(podSpecBuilder.build());
}
}
return answer;
}
}
}
log.info("Merging 2 resources for " + getKind(resource1OrCopy) + " " + getName(resource1OrCopy) + " from " + getSourceUrlAnnotation(resource1OrCopy) + " and " + getSourceUrlAnnotation(resource2) + " and removing " + getSourceUrlAnnotation(resource1OrCopy));
return resource1OrCopy;
}
Aggregations