Search in sources :

Example 1 with ApplyImageDecorator

use of io.dekorate.kubernetes.decorator.ApplyImageDecorator in project quarkus by quarkusio.

the class MinikubeManifestGenerator method generate.

public void generate(KubernetesConfig config) {
    ImageConfiguration imageConfig = getImageConfiguration(getProject(), config, configurationRegistry);
    Optional<Deployment> existingDeployment = resourceRegistry.groups().getOrDefault(MINIKUBE, new KubernetesListBuilder()).buildItems().stream().filter(i -> i instanceof Deployment).map(i -> (Deployment) i).filter(i -> i.getMetadata().getName().equals(config.getName())).findAny();
    if (!existingDeployment.isPresent()) {
        resourceRegistry.add(MINIKUBE, createDeployment(config, imageConfig));
    }
    addDecorators(MINIKUBE, config);
    if (config.isHeadless()) {
        resourceRegistry.decorate(MINIKUBE, new ApplyHeadlessDecorator(config.getName()));
    }
    if (config.getReplicas() != 1) {
        resourceRegistry.decorate(MINIKUBE, new ApplyReplicasToDeploymentDecorator(config.getName(), config.getReplicas()));
        resourceRegistry.decorate(MINIKUBE, new ApplyReplicasToStatefulSetDecorator(config.getName(), config.getReplicas()));
    }
    String image = Strings.isNotNullOrEmpty(imageConfig.getImage()) ? imageConfig.getImage() : Images.getImage(imageConfig.isAutoPushEnabled() ? (Strings.isNullOrEmpty(imageConfig.getRegistry()) ? DEFAULT_REGISTRY : imageConfig.getRegistry()) : imageConfig.getRegistry(), imageConfig.getGroup(), imageConfig.getName(), imageConfig.getVersion());
    resourceRegistry.decorate(MINIKUBE, new ApplyImageDecorator(config.getName(), image));
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) WithProject(io.dekorate.WithProject) Strings(io.dekorate.utils.Strings) Images(io.dekorate.utils.Images) KubernetesConfigBuilder(io.dekorate.kubernetes.config.KubernetesConfigBuilder) AddIngressDecorator(io.dekorate.kubernetes.decorator.AddIngressDecorator) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) Project(io.dekorate.project.Project) AbstractKubernetesManifestGenerator(io.dekorate.AbstractKubernetesManifestGenerator) ApplyProjectInfo(io.dekorate.project.ApplyProjectInfo) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) ApplyDeployToApplicationConfiguration(io.dekorate.kubernetes.configurator.ApplyDeployToApplicationConfiguration) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Labels(io.dekorate.utils.Labels) ConfigurationSupplier(io.dekorate.config.ConfigurationSupplier) AddServiceResourceDecorator(io.dekorate.kubernetes.decorator.AddServiceResourceDecorator) ApplyImageDecorator(io.dekorate.kubernetes.decorator.ApplyImageDecorator) PodTemplateSpecBuilder(io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder) EditableKubernetesConfig(io.dekorate.kubernetes.config.EditableKubernetesConfig) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) Configuration(io.dekorate.kubernetes.config.Configuration) ConfigurationRegistry(io.dekorate.ConfigurationRegistry) BuildServiceFactories(io.dekorate.BuildServiceFactories) AddInitContainerDecorator(io.dekorate.kubernetes.decorator.AddInitContainerDecorator) ImageConfigurationBuilder(io.dekorate.kubernetes.config.ImageConfigurationBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Container(io.dekorate.kubernetes.config.Container) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) ResourceRegistry(io.dekorate.ResourceRegistry) KubernetesConfig(io.dekorate.kubernetes.config.KubernetesConfig) Optional(java.util.Optional) ApplyHeadlessDecorator(io.dekorate.kubernetes.decorator.ApplyHeadlessDecorator) ApplyReplicasToDeploymentDecorator(io.dekorate.kubernetes.decorator.ApplyReplicasToDeploymentDecorator) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) ApplyReplicasToDeploymentDecorator(io.dekorate.kubernetes.decorator.ApplyReplicasToDeploymentDecorator) ApplyImageDecorator(io.dekorate.kubernetes.decorator.ApplyImageDecorator) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ApplyHeadlessDecorator(io.dekorate.kubernetes.decorator.ApplyHeadlessDecorator)

Example 2 with ApplyImageDecorator

use of io.dekorate.kubernetes.decorator.ApplyImageDecorator in project dekorate by dekorateio.

the class KubernetesManifestGenerator method addDecorators.

@Override
protected void addDecorators(String group, KubernetesConfig config) {
    super.addDecorators(group, config);
    ImageConfiguration imageConfig = getImageConfiguration(getProject(), config, configurationRegistry);
    String image = Strings.isNotNullOrEmpty(imageConfig.getImage()) ? imageConfig.getImage() : Images.getImage(imageConfig.isAutoPushEnabled() ? (Strings.isNullOrEmpty(imageConfig.getRegistry()) ? DEFAULT_REGISTRY : imageConfig.getRegistry()) : imageConfig.getRegistry(), imageConfig.getGroup(), imageConfig.getName(), imageConfig.getVersion());
    Container appContainer = new ContainerBuilder().withName(config.getName()).withImage(image).withImagePullPolicy(ImagePullPolicy.IfNotPresent).addNewEnvVar().withName(KUBERNETES_NAMESPACE).withField(METADATA_NAMESPACE).endEnvVar().build();
    Project project = getProject();
    Optional<VcsConfig> vcsConfig = configurationRegistry.get(VcsConfig.class);
    String remote = vcsConfig.map(VcsConfig::getRemote).orElse(Git.ORIGIN);
    boolean httpsPrefered = vcsConfig.map(VcsConfig::isHttpsPreferred).orElse(false);
    String vcsUrl = project.getScmInfo() != null && Strings.isNotNullOrEmpty(project.getScmInfo().getRemote().get(Git.ORIGIN)) ? Git.getRemoteUrl(project.getRoot(), remote, httpsPrefered).orElse(Labels.UNKNOWN) : Labels.UNKNOWN;
    resourceRegistry.decorate(group, new AddVcsUrlAnnotationDecorator(config.getName(), Annotations.VCS_URL, vcsUrl));
    resourceRegistry.decorate(group, new AddCommitIdAnnotationDecorator());
    resourceRegistry.decorate(group, new ApplyApplicationContainerDecorator(config.getName(), appContainer));
    resourceRegistry.decorate(group, new ApplyImageDecorator(config.getName(), image));
    for (Container container : config.getInitContainers()) {
        resourceRegistry.decorate(group, new AddInitContainerDecorator(config.getName(), container));
    }
    if (config.getPorts().length > 0) {
        resourceRegistry.decorate(group, new AddServiceResourceDecorator(config));
    }
    Ports.getHttpPort(config).ifPresent(p -> {
        resourceRegistry.decorate(group, new AddIngressDecorator(config, Labels.createLabelsAsMap(config, "Ingress")));
        resourceRegistry.decorate(group, new AddIngressRuleDecorator(config.getName(), config.getHost(), p));
    });
    if (config.isHeadless()) {
        resourceRegistry.decorate(KUBERNETES, new ApplyHeadlessDecorator(config.getName()));
    }
    if (config.getReplicas() != null && config.getReplicas() != 1) {
        resourceRegistry.decorate(KUBERNETES, new ApplyReplicasDecorator(config.getName(), config.getReplicas()));
    }
    resourceRegistry.decorate(KUBERNETES, new ApplyDeploymentStrategyDecorator(config.getName(), config.getDeploymentStrategy(), config.getRollingUpdate()));
}
Also used : AddIngressRuleDecorator(io.dekorate.kubernetes.decorator.AddIngressRuleDecorator) ApplyApplicationContainerDecorator(io.dekorate.kubernetes.decorator.ApplyApplicationContainerDecorator) ApplyImageDecorator(io.dekorate.kubernetes.decorator.ApplyImageDecorator) AddVcsUrlAnnotationDecorator(io.dekorate.kubernetes.decorator.AddVcsUrlAnnotationDecorator) AddServiceResourceDecorator(io.dekorate.kubernetes.decorator.AddServiceResourceDecorator) VcsConfig(io.dekorate.option.config.VcsConfig) ApplyHeadlessDecorator(io.dekorate.kubernetes.decorator.ApplyHeadlessDecorator) AddIngressDecorator(io.dekorate.kubernetes.decorator.AddIngressDecorator) ApplyDeploymentStrategyDecorator(io.dekorate.kubernetes.decorator.ApplyDeploymentStrategyDecorator) WithProject(io.dekorate.WithProject) Project(io.dekorate.project.Project) Container(io.dekorate.kubernetes.config.Container) ContainerBuilder(io.dekorate.kubernetes.config.ContainerBuilder) AddCommitIdAnnotationDecorator(io.dekorate.kubernetes.decorator.AddCommitIdAnnotationDecorator) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) ApplyReplicasDecorator(io.dekorate.kubernetes.decorator.ApplyReplicasDecorator) AddInitContainerDecorator(io.dekorate.kubernetes.decorator.AddInitContainerDecorator)

Aggregations

WithProject (io.dekorate.WithProject)2 Container (io.dekorate.kubernetes.config.Container)2 ImageConfiguration (io.dekorate.kubernetes.config.ImageConfiguration)2 AddIngressDecorator (io.dekorate.kubernetes.decorator.AddIngressDecorator)2 AddInitContainerDecorator (io.dekorate.kubernetes.decorator.AddInitContainerDecorator)2 AddServiceResourceDecorator (io.dekorate.kubernetes.decorator.AddServiceResourceDecorator)2 ApplyHeadlessDecorator (io.dekorate.kubernetes.decorator.ApplyHeadlessDecorator)2 ApplyImageDecorator (io.dekorate.kubernetes.decorator.ApplyImageDecorator)2 Project (io.dekorate.project.Project)2 AbstractKubernetesManifestGenerator (io.dekorate.AbstractKubernetesManifestGenerator)1 BuildServiceFactories (io.dekorate.BuildServiceFactories)1 ConfigurationRegistry (io.dekorate.ConfigurationRegistry)1 ResourceRegistry (io.dekorate.ResourceRegistry)1 ConfigurationSupplier (io.dekorate.config.ConfigurationSupplier)1 Configuration (io.dekorate.kubernetes.config.Configuration)1 ContainerBuilder (io.dekorate.kubernetes.config.ContainerBuilder)1 EditableKubernetesConfig (io.dekorate.kubernetes.config.EditableKubernetesConfig)1 ImageConfigurationBuilder (io.dekorate.kubernetes.config.ImageConfigurationBuilder)1 KubernetesConfig (io.dekorate.kubernetes.config.KubernetesConfig)1 KubernetesConfigBuilder (io.dekorate.kubernetes.config.KubernetesConfigBuilder)1