Search in sources :

Example 6 with StatefulSetSpec

use of io.fabric8.kubernetes.api.model.apps.StatefulSetSpec in project fabric8-maven-plugin by fabric8io.

the class ControllerViaPluginConfigurationEnricher method create.

@Override
public void create(PlatformMode platformMode, KubernetesListBuilder builder) {
    final String name = getConfig(Config.name, MavenUtil.createDefaultResourceName(getContext().getGav().getSanitizedArtifactId()));
    ResourceConfig xmlResourceConfig = getConfiguration().getResource().orElse(null);
    final ResourceConfig config = new ResourceConfig.Builder().controllerName(name).imagePullPolicy(getImagePullPolicy(xmlResourceConfig, getConfig(Config.pullPolicy))).withReplicas(getReplicaCount(builder, xmlResourceConfig, Configs.asInt(getConfig(Config.replicaCount)))).build();
    final List<ImageConfiguration> images = getImages().orElse(Collections.emptyList());
    // 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 (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) {
                            String defaultApplicationContainerName = KubernetesResourceUtil.mergePodSpec(builder, podSpec, name, getValueFromConfig(SIDECAR, false));
                            if (defaultApplicationContainerName != null) {
                                setProcessingInstruction(NEED_IMAGECHANGE_TRIGGERS, Collections.singletonList(defaultApplicationContainerName));
                            }
                        }
                    });
                }
            }
        } 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) {
                            String defaultApplicationContainerName = KubernetesResourceUtil.mergePodSpec(builder, podSpec, name, getValueFromConfig(SIDECAR, false));
                            if (defaultApplicationContainerName != null) {
                                setProcessingInstruction(NEED_IMAGECHANGE_TRIGGERS, Collections.singletonList(defaultApplicationContainerName));
                            }
                        }
                    });
                }
            }
        }
    }
}
Also used : PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) StatefulSetSpec(io.fabric8.kubernetes.api.model.apps.StatefulSetSpec) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) StatefulSetBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) StatefulSetBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder) DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)

Aggregations

PodSpec (io.fabric8.kubernetes.api.model.PodSpec)4 StatefulSetSpec (io.fabric8.kubernetes.api.model.apps.StatefulSetSpec)4 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)3 Container (io.fabric8.kubernetes.api.model.Container)2 DeletionPropagation (io.fabric8.kubernetes.api.model.DeletionPropagation)2 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)2 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)2 Quantity (io.fabric8.kubernetes.api.model.Quantity)2 ResourceRequirements (io.fabric8.kubernetes.api.model.ResourceRequirements)2 ResourceRequirementsBuilder (io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder)2 Volume (io.fabric8.kubernetes.api.model.Volume)2 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)2 StatefulSetStatus (io.fabric8.kubernetes.api.model.apps.StatefulSetStatus)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 Resource (io.fabric8.kubernetes.client.dsl.Resource)2 Crds (io.strimzi.api.kafka.Crds)2 KafkaList (io.strimzi.api.kafka.KafkaList)2 StrimziPodSetList (io.strimzi.api.kafka.StrimziPodSetList)2 Kafka (io.strimzi.api.kafka.model.Kafka)2 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)2