use of io.dekorate.kubernetes.config.ConfigMapVolume 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));
}
}
use of io.dekorate.kubernetes.config.ConfigMapVolume 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());
}
Aggregations