Search in sources :

Example 1 with Container

use of io.dekorate.kubernetes.config.Container in project quarkus by quarkusio.

the class MinikubeManifestGenerator method addDecorators.

@Override
protected void addDecorators(String group, KubernetesConfig config) {
    super.addDecorators(group, config);
    for (Container container : config.getInitContainers()) {
        resourceRegistry.decorate(group, new AddInitContainerDecorator(config.getName(), container));
    }
    if (config.getPorts().length > 0) {
        resourceRegistry.decorate(group, new AddServiceResourceDecorator(config));
    }
    resourceRegistry.decorate(group, new AddIngressDecorator(config, Labels.createLabelsAsMap(config, "Ingress")));
}
Also used : Container(io.dekorate.kubernetes.config.Container) AddServiceResourceDecorator(io.dekorate.kubernetes.decorator.AddServiceResourceDecorator) AddIngressDecorator(io.dekorate.kubernetes.decorator.AddIngressDecorator) AddInitContainerDecorator(io.dekorate.kubernetes.decorator.AddInitContainerDecorator)

Example 2 with Container

use of io.dekorate.kubernetes.config.Container 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)

Example 3 with Container

use of io.dekorate.kubernetes.config.Container in project dekorate by dekorateio.

the class OpenshiftManifestGenerator method generate.

public void generate(OpenshiftConfig config) {
    LOGGER.info("Processing openshift configuration.");
    ImageConfiguration imageConfig = getImageConfiguration(getProject(), config, configurationRegistry);
    Optional<DeploymentConfig> existingDeploymentConfig = resourceRegistry.groups().getOrDefault(OPENSHIFT, new KubernetesListBuilder()).buildItems().stream().filter(i -> i instanceof DeploymentConfig).map(i -> (DeploymentConfig) i).filter(i -> i.getMetadata().getName().equals(config.getName())).findAny();
    if (!existingDeploymentConfig.isPresent()) {
        resourceRegistry.add(OPENSHIFT, createDeploymentConfig(config, imageConfig));
    }
    if (config.isHeadless()) {
        resourceRegistry.decorate(OPENSHIFT, new ApplyHeadlessDecorator(config.getName()));
    }
    for (Container container : config.getInitContainers()) {
        resourceRegistry.decorate(OPENSHIFT, new AddInitContainerDecorator(config.getName(), container));
    }
    if (config.getPorts().length > 0) {
        resourceRegistry.decorate(OPENSHIFT, new AddServiceResourceDecorator(config));
    }
    addDecorators(OPENSHIFT, config, imageConfig);
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) WithProject(io.dekorate.WithProject) ApplyDeploymentTriggerDecorator(io.dekorate.openshift.decorator.ApplyDeploymentTriggerDecorator) Strings(io.dekorate.utils.Strings) Images(io.dekorate.utils.Images) EditableOpenshiftConfig(io.dekorate.openshift.config.EditableOpenshiftConfig) Project(io.dekorate.project.Project) AbstractKubernetesManifestGenerator(io.dekorate.AbstractKubernetesManifestGenerator) ApplyProjectInfo(io.dekorate.project.ApplyProjectInfo) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) AddVcsUrlAnnotationDecorator(io.dekorate.kubernetes.decorator.AddVcsUrlAnnotationDecorator) OpenshiftLabels(io.dekorate.openshift.OpenshiftLabels) Label(io.dekorate.kubernetes.config.Label) ApplyDeployToApplicationConfiguration(io.dekorate.kubernetes.configurator.ApplyDeployToApplicationConfiguration) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) DeploymentConfigBuilder(io.fabric8.openshift.api.model.DeploymentConfigBuilder) OpenshiftConfig(io.dekorate.openshift.config.OpenshiftConfig) Labels(io.dekorate.utils.Labels) ConfigurationSupplier(io.dekorate.config.ConfigurationSupplier) AddLabelDecorator(io.dekorate.kubernetes.decorator.AddLabelDecorator) AddServiceResourceDecorator(io.dekorate.kubernetes.decorator.AddServiceResourceDecorator) PodTemplateSpecBuilder(io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder) ConfigKey(io.dekorate.kubernetes.config.ConfigKey) Logger(io.dekorate.Logger) ApplyReplicasDecorator(io.dekorate.openshift.decorator.ApplyReplicasDecorator) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Annotations(io.dekorate.utils.Annotations) Configuration(io.dekorate.kubernetes.config.Configuration) ConfigurationRegistry(io.dekorate.ConfigurationRegistry) LoggerFactory(io.dekorate.LoggerFactory) BuildServiceFactories(io.dekorate.BuildServiceFactories) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) AddInitContainerDecorator(io.dekorate.kubernetes.decorator.AddInitContainerDecorator) VcsConfig(io.dekorate.option.config.VcsConfig) ImageConfigurationBuilder(io.dekorate.kubernetes.config.ImageConfigurationBuilder) Container(io.dekorate.kubernetes.config.Container) AddRouteDecorator(io.dekorate.openshift.decorator.AddRouteDecorator) OpenshiftConfigBuilder(io.dekorate.openshift.config.OpenshiftConfigBuilder) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) ResourceRegistry(io.dekorate.ResourceRegistry) Optional(java.util.Optional) ApplyHeadlessDecorator(io.dekorate.kubernetes.decorator.ApplyHeadlessDecorator) OpenshiftAnnotations(io.dekorate.openshift.OpenshiftAnnotations) AddCommitIdAnnotationDecorator(io.dekorate.kubernetes.decorator.AddCommitIdAnnotationDecorator) RemoveAnnotationDecorator(io.dekorate.kubernetes.decorator.RemoveAnnotationDecorator) Git(io.dekorate.utils.Git) Container(io.dekorate.kubernetes.config.Container) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) AddServiceResourceDecorator(io.dekorate.kubernetes.decorator.AddServiceResourceDecorator) ApplyHeadlessDecorator(io.dekorate.kubernetes.decorator.ApplyHeadlessDecorator) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) AddInitContainerDecorator(io.dekorate.kubernetes.decorator.AddInitContainerDecorator)

Example 4 with Container

use of io.dekorate.kubernetes.config.Container in project dekorate by dekorateio.

the class KnativeManifestGenerator method generate.

public void generate(KnativeConfig config) {
    Optional<Service> existingService = resourceRegistry.groups().getOrDefault(KNATIVE, new KubernetesListBuilder()).buildItems().stream().filter(i -> i instanceof Service).map(i -> (Service) i).filter(i -> i.getMetadata().getName().equals(config.getName())).findAny();
    if (!existingService.isPresent()) {
        resourceRegistry.add(KNATIVE, createService(config));
    }
    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(KNATIVE, new AddVcsUrlAnnotationDecorator(config.getName(), Annotations.VCS_URL, vcsUrl));
    resourceRegistry.decorate(KNATIVE, new AddCommitIdAnnotationDecorator());
    resourceRegistry.decorate(KNATIVE, new ApplyPortNameDecorator(null, null, config.getHttpTransportVersion() != null ? config.getHttpTransportVersion().name().toLowerCase() : "http1", Ports.webPortNames().toArray(new String[Ports.webPortNames().size()])));
    addDecorators(KNATIVE, config);
    if (config.getMinScale() != null && config.getMinScale() != 0) {
        resourceRegistry.decorate(KNATIVE, new ApplyMinScaleDecorator(config.getName(), config.getMinScale()));
    }
    if (config.getMaxScale() != null && config.getMaxScale() != 0) {
        resourceRegistry.decorate(KNATIVE, new ApplyMaxScaleDecorator(config.getName(), config.getMaxScale()));
    }
    if (!config.isScaleToZeroEnabled()) {
        resourceRegistry.decorate(KNATIVE, new AddConfigMapResourceProvidingDecorator("config-autoscaler"));
        resourceRegistry.decorate(KNATIVE, new AddConfigMapDataDecorator("config-autoscaler", "enable-scale-to-zero", String.valueOf(config.isAutoDeployEnabled())));
    }
    if (Strings.isNotNullOrEmpty(config.getRevisionName())) {
        resourceRegistry.decorate(KNATIVE, new ApplyRevisionNameDecorator(config.getName(), config.getRevisionName()));
    }
    if (config.getRevisionAutoScaling() != null) {
        if (config.getRevisionAutoScaling().getMetric() != null && config.getRevisionAutoScaling().getMetric() != AutoscalingMetric.concurrency) {
            resourceRegistry.decorate(KNATIVE, new ApplyLocalAutoscalingMetricDecorator(config.getName(), config.getRevisionAutoScaling().getMetric()));
        }
        if (config.getRevisionAutoScaling().getContainerConcurrency() != null) {
            resourceRegistry.decorate(KNATIVE, new ApplyLocalContainerConcurrencyDecorator(config.getName(), config.getRevisionAutoScaling().getContainerConcurrency()));
        }
        // Local autoscaling configuration
        if (config.getRevisionAutoScaling().getAutoScalerClass() != null && config.getRevisionAutoScaling().getAutoScalerClass() != AutoScalerClass.kpa) {
            resourceRegistry.decorate(KNATIVE, new ApplyLocalAutoscalingClassDecorator(config.getName(), config.getRevisionAutoScaling().getAutoScalerClass()));
        }
        if (config.getRevisionAutoScaling().getTarget() != null && config.getRevisionAutoScaling().getTarget() != 0) {
            resourceRegistry.decorate(KNATIVE, new ApplyLocalAutoscalingTargetDecorator(config.getName(), config.getRevisionAutoScaling().getTarget()));
        }
        if (config.getRevisionAutoScaling().getTarget() != null && config.getRevisionAutoScaling().getTarget() != 200 && config.getRevisionAutoScaling().getMetric() == AutoscalingMetric.rps) {
            resourceRegistry.decorate(KNATIVE, new ApplyLocalContainerConcurrencyDecorator(config.getName(), config.getRevisionAutoScaling().getTarget()));
        }
        if (config.getRevisionAutoScaling().getTargetUtilizationPercentage() != null && config.getRevisionAutoScaling().getTargetUtilizationPercentage() != 70) {
            resourceRegistry.decorate(KNATIVE, new ApplyLocalContainerConcurrencyDecorator(config.getName(), config.getRevisionAutoScaling().getTargetUtilizationPercentage()));
        }
    }
    // Global autoscaling configuration
    if (config.getGlobalAutoScaling() != null) {
        if (!isDefault(config.getGlobalAutoScaling())) {
            resourceRegistry.decorate(KNATIVE, new AddConfigMapResourceProvidingDecorator("config-autoscaler"));
            if (config.getGlobalAutoScaling().getAutoScalerClass() != null && config.getGlobalAutoScaling().getAutoScalerClass() != AutoScalerClass.kpa) {
                resourceRegistry.decorate(KNATIVE, new ApplyGlobalAutoscalingClassDecorator(config.getGlobalAutoScaling().getAutoScalerClass()));
            }
            if (config.getGlobalAutoScaling().getRequestsPerSecond() != null && config.getGlobalAutoScaling().getRequestsPerSecond() != 200) {
                resourceRegistry.decorate(KNATIVE, new ApplyGlobalRequestsPerSecondTargetDecorator(config.getGlobalAutoScaling().getRequestsPerSecond()));
            }
            if (config.getGlobalAutoScaling().getTargetUtilizationPercentage() != null && config.getGlobalAutoScaling().getTargetUtilizationPercentage() != 70) {
                resourceRegistry.decorate(KNATIVE, new ApplyGlobalContainerConcurrencyDecorator(config.getGlobalAutoScaling().getTargetUtilizationPercentage()));
            }
        }
        if (config.getGlobalAutoScaling().getContainerConcurrency() != null && config.getGlobalAutoScaling().getContainerConcurrency() != 0) {
            resourceRegistry.decorate(KNATIVE, new AddConfigMapResourceProvidingDecorator("config-defaults"));
            resourceRegistry.decorate(KNATIVE, new ApplyGlobalContainerConcurrencyDecorator(config.getGlobalAutoScaling().getContainerConcurrency()));
        }
    }
    for (Traffic traffic : config.getTraffic()) {
        String revisionName = Strings.isNotNullOrEmpty(config.getRevisionName()) ? config.getRevisionName() : null;
        String tag = Strings.isNotNullOrEmpty(traffic.getTag()) ? traffic.getTag() : null;
        boolean latestRevision = revisionName == null ? true : traffic.isLatestRevision();
        long percentage = traffic.getPercentage();
        resourceRegistry.decorate(KNATIVE, new ApplyTrafficDecorator(config.getName(), revisionName, latestRevision, percentage, tag));
    }
    // Revision specific stuff
    for (Container container : config.getSidecars()) {
        resourceRegistry.decorate(KNATIVE, new AddSidecarToRevisionDecorator(config.getName(), container));
    }
    for (SecretVolume volume : config.getSecretVolumes()) {
        validateVolume(volume);
        resourceRegistry.decorate(KNATIVE, new AddSecretVolumeToRevisionDecorator(volume));
    }
    for (ConfigMapVolume volume : config.getConfigMapVolumes()) {
        validateVolume(volume);
        resourceRegistry.decorate(KNATIVE, new AddConfigMapVolumeToRevisionDecorator(volume));
    }
    for (PersistentVolumeClaimVolume volume : config.getPvcVolumes()) {
        resourceRegistry.decorate(KNATIVE, new AddPvcVolumeToRevisionDecorator(volume));
    }
    for (AzureFileVolume volume : config.getAzureFileVolumes()) {
        resourceRegistry.decorate(KNATIVE, new AddAzureFileVolumeToRevisionDecorator(volume));
    }
    for (AzureDiskVolume volume : config.getAzureDiskVolumes()) {
        resourceRegistry.decorate(KNATIVE, new AddAzureDiskVolumeToRevisionDecorator(volume));
    }
    for (AwsElasticBlockStoreVolume volume : config.getAwsElasticBlockStoreVolumes()) {
        resourceRegistry.decorate(KNATIVE, new AddAwsElasticBlockStoreVolumeToRevisionDecorator(volume));
    }
    for (HostAlias hostAlias : config.getHostAliases()) {
        resourceRegistry.decorate(KNATIVE, new AddHostAliasesToRevisionDecorator(hostAlias));
    }
}
Also used : WithProject(io.dekorate.WithProject) Strings(io.dekorate.utils.Strings) LabelBuilder(io.dekorate.kubernetes.config.LabelBuilder) Project(io.dekorate.project.Project) ApplyMinScaleDecorator(io.dekorate.knative.decorator.ApplyMinScaleDecorator) KnativeConfigBuilder(io.dekorate.knative.config.KnativeConfigBuilder) AddAzureFileVolumeToRevisionDecorator(io.dekorate.knative.decorator.AddAzureFileVolumeToRevisionDecorator) EditableKnativeConfig(io.dekorate.knative.config.EditableKnativeConfig) AddVcsUrlAnnotationDecorator(io.dekorate.kubernetes.decorator.AddVcsUrlAnnotationDecorator) ApplyDeployToApplicationConfiguration(io.dekorate.kubernetes.configurator.ApplyDeployToApplicationConfiguration) AddSidecarToRevisionDecorator(io.dekorate.knative.decorator.AddSidecarToRevisionDecorator) AzureDiskVolume(io.dekorate.kubernetes.config.AzureDiskVolume) SecretVolume(io.dekorate.kubernetes.config.SecretVolume) AutoScalerClass(io.dekorate.knative.config.AutoScalerClass) AddConfigMapVolumeToRevisionDecorator(io.dekorate.knative.decorator.AddConfigMapVolumeToRevisionDecorator) ApplyLocalAutoscalingClassDecorator(io.dekorate.knative.decorator.ApplyLocalAutoscalingClassDecorator) ApplyPortNameDecorator(io.dekorate.kubernetes.decorator.ApplyPortNameDecorator) AddLabelDecorator(io.dekorate.kubernetes.decorator.AddLabelDecorator) HostAlias(io.dekorate.kubernetes.config.HostAlias) ApplyLocalAutoscalingTargetDecorator(io.dekorate.knative.decorator.ApplyLocalAutoscalingTargetDecorator) Configuration(io.dekorate.kubernetes.config.Configuration) ConfigurationRegistry(io.dekorate.ConfigurationRegistry) KnativeConfig(io.dekorate.knative.config.KnativeConfig) ApplyTrafficDecorator(io.dekorate.knative.decorator.ApplyTrafficDecorator) VcsConfig(io.dekorate.option.config.VcsConfig) ApplyLocalAutoscalingMetricDecorator(io.dekorate.knative.decorator.ApplyLocalAutoscalingMetricDecorator) AddConfigMapResourceProvidingDecorator(io.dekorate.kubernetes.decorator.AddConfigMapResourceProvidingDecorator) Traffic(io.dekorate.knative.config.Traffic) Ports(io.dekorate.utils.Ports) AutoscalingMetric(io.dekorate.knative.config.AutoscalingMetric) ApplyMaxScaleDecorator(io.dekorate.knative.decorator.ApplyMaxScaleDecorator) ApplyRevisionNameDecorator(io.dekorate.knative.decorator.ApplyRevisionNameDecorator) AddAwsElasticBlockStoreVolumeToRevisionDecorator(io.dekorate.knative.decorator.AddAwsElasticBlockStoreVolumeToRevisionDecorator) AddHostAliasesToRevisionDecorator(io.dekorate.knative.decorator.AddHostAliasesToRevisionDecorator) ResourceRegistry(io.dekorate.ResourceRegistry) ApplyLocalContainerConcurrencyDecorator(io.dekorate.knative.decorator.ApplyLocalContainerConcurrencyDecorator) Optional(java.util.Optional) AzureFileVolume(io.dekorate.kubernetes.config.AzureFileVolume) ApplyGlobalContainerConcurrencyDecorator(io.dekorate.knative.decorator.ApplyGlobalContainerConcurrencyDecorator) Images(io.dekorate.utils.Images) Service(io.fabric8.knative.serving.v1.Service) AbstractKubernetesManifestGenerator(io.dekorate.AbstractKubernetesManifestGenerator) ConfigMapVolume(io.dekorate.kubernetes.config.ConfigMapVolume) ApplyProjectInfo(io.dekorate.project.ApplyProjectInfo) ServiceBuilder(io.fabric8.knative.serving.v1.ServiceBuilder) Labels(io.dekorate.utils.Labels) PersistentVolumeClaimVolume(io.dekorate.kubernetes.config.PersistentVolumeClaimVolume) ConfigurationSupplier(io.dekorate.config.ConfigurationSupplier) ApplyGlobalAutoscalingClassDecorator(io.dekorate.knative.decorator.ApplyGlobalAutoscalingClassDecorator) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Annotations(io.dekorate.utils.Annotations) AddConfigMapDataDecorator(io.dekorate.kubernetes.decorator.AddConfigMapDataDecorator) AddPvcVolumeToRevisionDecorator(io.dekorate.knative.decorator.AddPvcVolumeToRevisionDecorator) BuildServiceFactories(io.dekorate.BuildServiceFactories) GlobalAutoScaling(io.dekorate.knative.config.GlobalAutoScaling) AwsElasticBlockStoreVolume(io.dekorate.kubernetes.config.AwsElasticBlockStoreVolume) AddSecretVolumeToRevisionDecorator(io.dekorate.knative.decorator.AddSecretVolumeToRevisionDecorator) ImageConfigurationBuilder(io.dekorate.kubernetes.config.ImageConfigurationBuilder) Container(io.dekorate.kubernetes.config.Container) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) AddAzureDiskVolumeToRevisionDecorator(io.dekorate.knative.decorator.AddAzureDiskVolumeToRevisionDecorator) AddCommitIdAnnotationDecorator(io.dekorate.kubernetes.decorator.AddCommitIdAnnotationDecorator) Git(io.dekorate.utils.Git) ApplyGlobalRequestsPerSecondTargetDecorator(io.dekorate.knative.decorator.ApplyGlobalRequestsPerSecondTargetDecorator) AddConfigMapVolumeToRevisionDecorator(io.dekorate.knative.decorator.AddConfigMapVolumeToRevisionDecorator) AzureDiskVolume(io.dekorate.kubernetes.config.AzureDiskVolume) PersistentVolumeClaimVolume(io.dekorate.kubernetes.config.PersistentVolumeClaimVolume) AddAzureDiskVolumeToRevisionDecorator(io.dekorate.knative.decorator.AddAzureDiskVolumeToRevisionDecorator) ApplyGlobalContainerConcurrencyDecorator(io.dekorate.knative.decorator.ApplyGlobalContainerConcurrencyDecorator) Traffic(io.dekorate.knative.config.Traffic) AddSidecarToRevisionDecorator(io.dekorate.knative.decorator.AddSidecarToRevisionDecorator) VcsConfig(io.dekorate.option.config.VcsConfig) ApplyPortNameDecorator(io.dekorate.kubernetes.decorator.ApplyPortNameDecorator) AddConfigMapDataDecorator(io.dekorate.kubernetes.decorator.AddConfigMapDataDecorator) ApplyRevisionNameDecorator(io.dekorate.knative.decorator.ApplyRevisionNameDecorator) AddConfigMapResourceProvidingDecorator(io.dekorate.kubernetes.decorator.AddConfigMapResourceProvidingDecorator) ApplyLocalAutoscalingMetricDecorator(io.dekorate.knative.decorator.ApplyLocalAutoscalingMetricDecorator) AddPvcVolumeToRevisionDecorator(io.dekorate.knative.decorator.AddPvcVolumeToRevisionDecorator) Container(io.dekorate.kubernetes.config.Container) AddCommitIdAnnotationDecorator(io.dekorate.kubernetes.decorator.AddCommitIdAnnotationDecorator) ApplyTrafficDecorator(io.dekorate.knative.decorator.ApplyTrafficDecorator) AddAzureFileVolumeToRevisionDecorator(io.dekorate.knative.decorator.AddAzureFileVolumeToRevisionDecorator) ApplyMaxScaleDecorator(io.dekorate.knative.decorator.ApplyMaxScaleDecorator) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ApplyLocalAutoscalingTargetDecorator(io.dekorate.knative.decorator.ApplyLocalAutoscalingTargetDecorator) AwsElasticBlockStoreVolume(io.dekorate.kubernetes.config.AwsElasticBlockStoreVolume) ApplyLocalContainerConcurrencyDecorator(io.dekorate.knative.decorator.ApplyLocalContainerConcurrencyDecorator) ConfigMapVolume(io.dekorate.kubernetes.config.ConfigMapVolume) AddSecretVolumeToRevisionDecorator(io.dekorate.knative.decorator.AddSecretVolumeToRevisionDecorator) ApplyGlobalAutoscalingClassDecorator(io.dekorate.knative.decorator.ApplyGlobalAutoscalingClassDecorator) SecretVolume(io.dekorate.kubernetes.config.SecretVolume) AddHostAliasesToRevisionDecorator(io.dekorate.knative.decorator.AddHostAliasesToRevisionDecorator) Service(io.fabric8.knative.serving.v1.Service) AddVcsUrlAnnotationDecorator(io.dekorate.kubernetes.decorator.AddVcsUrlAnnotationDecorator) ApplyLocalAutoscalingClassDecorator(io.dekorate.knative.decorator.ApplyLocalAutoscalingClassDecorator) ApplyMinScaleDecorator(io.dekorate.knative.decorator.ApplyMinScaleDecorator) AzureFileVolume(io.dekorate.kubernetes.config.AzureFileVolume) HostAlias(io.dekorate.kubernetes.config.HostAlias) WithProject(io.dekorate.WithProject) Project(io.dekorate.project.Project) ApplyGlobalRequestsPerSecondTargetDecorator(io.dekorate.knative.decorator.ApplyGlobalRequestsPerSecondTargetDecorator) AddAwsElasticBlockStoreVolumeToRevisionDecorator(io.dekorate.knative.decorator.AddAwsElasticBlockStoreVolumeToRevisionDecorator)

Example 5 with Container

use of io.dekorate.kubernetes.config.Container in project dekorate by dekorateio.

the class AbstractKubernetesManifestGenerator method addDecorators.

/**
 * Add all decorator to the resources.
 * This method will read the config and then add all the required decorator to the resources.
 * The method is intended to be called from the generate method and thus marked as protected.
 *
 * @param group The group..
 * @param config The config.
 */
protected void addDecorators(String group, C config) {
    if (Strings.isNotNullOrEmpty(config.getServiceAccount())) {
        resourceRegistry.decorate(new ApplyServiceAccountNamedDecorator(config.getName(), config.getServiceAccount()));
    }
    if (config.getImagePullPolicy() != ImagePullPolicy.IfNotPresent) {
        resourceRegistry.decorate(group, new ApplyImagePullPolicyDecorator(config.getImagePullPolicy()));
    }
    for (String imagePullSecret : config.getImagePullSecrets()) {
        resourceRegistry.decorate(new AddImagePullSecretDecorator(config.getName(), imagePullSecret));
    }
    // Metadata handling
    Labels.createLabels(config).forEach(l -> {
        resourceRegistry.decorate(group, new AddLabelDecorator(config.getName(), l));
        resourceRegistry.decorate(group, new AddToSelectorDecorator(config.getName(), l.getKey(), l.getValue()));
        resourceRegistry.decorate(group, new AddToMatchingLabelsDecorator(config.getName(), l.getKey(), l.getValue()));
    });
    for (Annotation annotation : config.getAnnotations()) {
        resourceRegistry.decorate(new AddAnnotationDecorator(config.getName(), annotation));
    }
    if (Strings.isNotNullOrEmpty(config.getServiceAccount())) {
        resourceRegistry.decorate(group, new ApplyServiceAccountNamedDecorator(config.getName(), config.getServiceAccount()));
    }
    if (config.getImagePullPolicy() != ImagePullPolicy.IfNotPresent) {
        resourceRegistry.decorate(group, new ApplyImagePullPolicyDecorator(config.getName(), config.getImagePullPolicy()));
    }
    for (String imagePullSecret : config.getImagePullSecrets()) {
        resourceRegistry.decorate(group, new AddImagePullSecretDecorator(config.getName(), imagePullSecret));
    }
    for (HostAlias hostAlias : config.getHostAliases()) {
        resourceRegistry.decorate(new AddHostAliasesDecorator(config.getName(), hostAlias));
    }
    for (Container container : config.getSidecars()) {
        resourceRegistry.decorate(group, new AddSidecarDecorator(config.getName(), container));
    }
    for (Env env : config.getEnvVars()) {
        resourceRegistry.decorate(group, new AddEnvVarDecorator(config.getName(), config.getName(), env));
    }
    for (Port port : config.getPorts()) {
        resourceRegistry.decorate(group, new AddPortDecorator(config.getName(), config.getName(), port));
    }
    for (Mount mount : config.getMounts()) {
        resourceRegistry.decorate(group, new AddMountDecorator(config.getName(), config.getName(), mount));
    }
    for (SecretVolume volume : config.getSecretVolumes()) {
        validateVolume(volume);
        resourceRegistry.decorate(group, new AddSecretVolumeDecorator(volume));
    }
    for (ConfigMapVolume volume : config.getConfigMapVolumes()) {
        validateVolume(volume);
        resourceRegistry.decorate(group, new AddConfigMapVolumeDecorator(volume));
    }
    for (PersistentVolumeClaimVolume volume : config.getPvcVolumes()) {
        resourceRegistry.decorate(group, new AddPvcVolumeDecorator(volume));
    }
    for (AzureFileVolume volume : config.getAzureFileVolumes()) {
        resourceRegistry.decorate(group, new AddAzureFileVolumeDecorator(volume));
    }
    for (AzureDiskVolume volume : config.getAzureDiskVolumes()) {
        resourceRegistry.decorate(group, new AddAzureDiskVolumeDecorator(volume));
    }
    for (AwsElasticBlockStoreVolume volume : config.getAwsElasticBlockStoreVolumes()) {
        resourceRegistry.decorate(group, new AddAwsElasticBlockStoreVolumeDecorator(volume));
    }
    if (config.getCommand() != null && config.getCommand().length > 0) {
        resourceRegistry.decorate(group, new ApplyCommandDecorator(config.getName(), config.getName(), config.getCommand()));
    }
    if (config.getArguments() != null && config.getArguments().length > 0) {
        resourceRegistry.decorate(group, new ApplyArgsDecorator(config.getName(), config.getName(), config.getArguments()));
    }
    if (Probes.isConfigured(config.getLivenessProbe())) {
        resourceRegistry.decorate(group, new AddLivenessProbeDecorator(config.getName(), config.getName(), config.getLivenessProbe()));
    }
    if (Probes.isConfigured(config.getReadinessProbe())) {
        resourceRegistry.decorate(group, new AddReadinessProbeDecorator(config.getName(), config.getName(), config.getReadinessProbe()));
    }
    // Container resources
    if (config.getLimitResources() != null) {
        if (Strings.isNotNullOrEmpty(config.getLimitResources().getCpu())) {
            resourceRegistry.decorate(group, new ApplyLimitsCpuDecorator(config.getName(), config.getName(), config.getLimitResources().getCpu()));
        }
        if (Strings.isNotNullOrEmpty(config.getLimitResources().getMemory())) {
            resourceRegistry.decorate(group, new ApplyLimitsMemoryDecorator(config.getName(), config.getName(), config.getLimitResources().getMemory()));
        }
    }
    if (config.getRequestResources() != null) {
        if (Strings.isNotNullOrEmpty(config.getRequestResources().getCpu())) {
            resourceRegistry.decorate(group, new ApplyRequestsCpuDecorator(config.getName(), config.getName(), config.getRequestResources().getCpu()));
        }
        if (Strings.isNotNullOrEmpty(config.getRequestResources().getMemory())) {
            resourceRegistry.decorate(group, new ApplyRequestsMemoryDecorator(config.getName(), config.getName(), config.getRequestResources().getMemory()));
        }
    }
    resourceRegistry.decorate(group, new RemoveProbesFromInitContainerDecorator());
}
Also used : AddPvcVolumeDecorator(io.dekorate.kubernetes.decorator.AddPvcVolumeDecorator) AddImagePullSecretDecorator(io.dekorate.kubernetes.decorator.AddImagePullSecretDecorator) AddAzureFileVolumeDecorator(io.dekorate.kubernetes.decorator.AddAzureFileVolumeDecorator) AzureDiskVolume(io.dekorate.kubernetes.config.AzureDiskVolume) PersistentVolumeClaimVolume(io.dekorate.kubernetes.config.PersistentVolumeClaimVolume) AddLivenessProbeDecorator(io.dekorate.kubernetes.decorator.AddLivenessProbeDecorator) AddAzureDiskVolumeDecorator(io.dekorate.kubernetes.decorator.AddAzureDiskVolumeDecorator) Port(io.dekorate.kubernetes.config.Port) ApplyLimitsMemoryDecorator(io.dekorate.kubernetes.decorator.ApplyLimitsMemoryDecorator) Mount(io.dekorate.kubernetes.config.Mount) AddEnvVarDecorator(io.dekorate.kubernetes.decorator.AddEnvVarDecorator) AddConfigMapVolumeDecorator(io.dekorate.kubernetes.decorator.AddConfigMapVolumeDecorator) Env(io.dekorate.kubernetes.config.Env) AddSidecarDecorator(io.dekorate.kubernetes.decorator.AddSidecarDecorator) ApplyRequestsMemoryDecorator(io.dekorate.kubernetes.decorator.ApplyRequestsMemoryDecorator) ApplyImagePullPolicyDecorator(io.dekorate.kubernetes.decorator.ApplyImagePullPolicyDecorator) Container(io.dekorate.kubernetes.config.Container) ApplyLimitsCpuDecorator(io.dekorate.kubernetes.decorator.ApplyLimitsCpuDecorator) AddToSelectorDecorator(io.dekorate.kubernetes.decorator.AddToSelectorDecorator) AddPortDecorator(io.dekorate.kubernetes.decorator.AddPortDecorator) AwsElasticBlockStoreVolume(io.dekorate.kubernetes.config.AwsElasticBlockStoreVolume) ConfigMapVolume(io.dekorate.kubernetes.config.ConfigMapVolume) ApplyCommandDecorator(io.dekorate.kubernetes.decorator.ApplyCommandDecorator) RemoveProbesFromInitContainerDecorator(io.dekorate.kubernetes.decorator.RemoveProbesFromInitContainerDecorator) AddAnnotationDecorator(io.dekorate.kubernetes.decorator.AddAnnotationDecorator) AddHostAliasesDecorator(io.dekorate.kubernetes.decorator.AddHostAliasesDecorator) SecretVolume(io.dekorate.kubernetes.config.SecretVolume) AddToMatchingLabelsDecorator(io.dekorate.kubernetes.decorator.AddToMatchingLabelsDecorator) AddAwsElasticBlockStoreVolumeDecorator(io.dekorate.kubernetes.decorator.AddAwsElasticBlockStoreVolumeDecorator) Annotation(io.dekorate.kubernetes.config.Annotation) HostAlias(io.dekorate.kubernetes.config.HostAlias) AzureFileVolume(io.dekorate.kubernetes.config.AzureFileVolume) ApplyArgsDecorator(io.dekorate.kubernetes.decorator.ApplyArgsDecorator) AddReadinessProbeDecorator(io.dekorate.kubernetes.decorator.AddReadinessProbeDecorator) ApplyRequestsCpuDecorator(io.dekorate.kubernetes.decorator.ApplyRequestsCpuDecorator) AddSecretVolumeDecorator(io.dekorate.kubernetes.decorator.AddSecretVolumeDecorator) AddLabelDecorator(io.dekorate.kubernetes.decorator.AddLabelDecorator) ApplyServiceAccountNamedDecorator(io.dekorate.kubernetes.decorator.ApplyServiceAccountNamedDecorator) AddMountDecorator(io.dekorate.kubernetes.decorator.AddMountDecorator)

Aggregations

Container (io.dekorate.kubernetes.config.Container)5 WithProject (io.dekorate.WithProject)3 ImageConfiguration (io.dekorate.kubernetes.config.ImageConfiguration)3 AddCommitIdAnnotationDecorator (io.dekorate.kubernetes.decorator.AddCommitIdAnnotationDecorator)3 AddInitContainerDecorator (io.dekorate.kubernetes.decorator.AddInitContainerDecorator)3 AddLabelDecorator (io.dekorate.kubernetes.decorator.AddLabelDecorator)3 AddServiceResourceDecorator (io.dekorate.kubernetes.decorator.AddServiceResourceDecorator)3 AddVcsUrlAnnotationDecorator (io.dekorate.kubernetes.decorator.AddVcsUrlAnnotationDecorator)3 VcsConfig (io.dekorate.option.config.VcsConfig)3 Project (io.dekorate.project.Project)3 AbstractKubernetesManifestGenerator (io.dekorate.AbstractKubernetesManifestGenerator)2 BuildServiceFactories (io.dekorate.BuildServiceFactories)2 ConfigurationRegistry (io.dekorate.ConfigurationRegistry)2 ResourceRegistry (io.dekorate.ResourceRegistry)2 ConfigurationSupplier (io.dekorate.config.ConfigurationSupplier)2 Configuration (io.dekorate.kubernetes.config.Configuration)2 ImageConfigurationBuilder (io.dekorate.kubernetes.config.ImageConfigurationBuilder)2 ApplyDeployToApplicationConfiguration (io.dekorate.kubernetes.configurator.ApplyDeployToApplicationConfiguration)2 AddIngressDecorator (io.dekorate.kubernetes.decorator.AddIngressDecorator)2 ApplyHeadlessDecorator (io.dekorate.kubernetes.decorator.ApplyHeadlessDecorator)2