Skip to content

Commit

Permalink
fix: k8s:resource replaces template variables in provided fragments, …
Browse files Browse the repository at this point in the history
…k8s:helm doesn't.

- Moved logic from ResourceMojo to separate service
- Fixed Resource generation, template placeholders are replaced only in aggregated YAML file (kubernetes.yml)
  not in individual resource files.
- Placeholder/variable replacement can be turned off (jkube.interpolateTemplateParameters)
- Fixed Helm chart generation, template placeholders are NOT replaced.
  Provided support for Parameters with no default value (values.yml) will only contain those which have a default.
  The rest of parameters can be specified with `--set` option
- Added integration test to verify behavior for resource and helm YAML generation.

Signed-off-by: Marc Nuri <[email protected]>

WIP fix: k8s:resource replaces template variables in provided fragments, k8s:helm doesn't.

- Moved logic from ResourceMojo to separate service
- Fixed Resource generation, template placeholders are replaced only in aggregated YAML file (kubernetes.yml)
  not in individual resource files.
- Placeholder/variable replacement can be turned off (jkube.interpolateTemplateParameters)
- Fixed Helm chart generation, template placeholders are NOT replaced.
  Provided support for Parameters with no default value (values.yml) will only contain those which have a default.
  The rest of parameters can be specified with `--set` option
- Added integration test to verify behavior for resource and helm YAML generation.

Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Sep 30, 2020
1 parent ca5dbd2 commit a80ecbd
Show file tree
Hide file tree
Showing 34 changed files with 1,452 additions and 276 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Usage:
* Fix #384: Enricher defined Container environment variables get merged with vars defined in Image Build Configuration
* Fix #385: WildFly Bootable JAR - Add native support for slim Bootable JAR
* Fix #415: Fixed resource validation for new json-schema-validator version
* Fix #356: Add further support for tls termination and insecureEdgeTerminationPolicy in pom.xml
* Fix #327: k8s:resource replaces template variables in provided fragments, k8s:helm doesn't.

### 1.0.0 (2020-09-09)
* Fix #351: Fix AutoTLSEnricher - add annotation + volume config to resource
Expand All @@ -47,7 +49,6 @@ Usage:
* Fix #362: Quarkus supports S2I builds both for JVM and native mode
* Fix #297: Added missing documentation for WatchMojo configuration parameters
* Fix #371: WebAppGenerator path configuration is no longer ignored
* Fix #356: Add further support for tls termination and insecureEdgeTerminationPolicy in pom.xml

### 1.0.0-rc-1 (2020-07-23)
* Fix #252: Replace Quarkus Native Base image with ubi-minimal (same as in `Dockerfile.native`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/**
* Represents a generic task to be executed on a object.
*/
@FunctionalInterface
public interface Task<T> {

void execute(T object) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.config.service;

import io.fabric8.kubernetes.api.model.KubernetesListBuilder;
import org.eclipse.jkube.kit.config.resource.PlatformMode;
import org.eclipse.jkube.kit.config.resource.ProcessorConfig;

public interface EnricherManager {

void createDefaultResources(PlatformMode platformMode, final KubernetesListBuilder builder);
void createDefaultResources(PlatformMode platformMode, ProcessorConfig enricherConfig, final KubernetesListBuilder builder);

void enrich(PlatformMode platformMode, final KubernetesListBuilder builder);
void enrich(PlatformMode platformMode, final ProcessorConfig enricherConfig, final KubernetesListBuilder builder);

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,24 @@ public class JKubeServiceHub implements Closeable {
private KubernetesClient client;
private LazyBuilder<ArtifactResolverService> artifactResolverService;
private LazyBuilder<BuildService> buildService;
private LazyBuilder<ResourceService> resourceService;
private LazyBuilder<ApplyService> applyService;
private LazyBuilder<UndeployService> undeployService;
private LazyBuilder<MigrateService> migrateService;

@Builder
public JKubeServiceHub(
ClusterAccess clusterAccess, RuntimeMode platformMode, KitLogger log,
ServiceHub dockerServiceHub, JKubeConfiguration configuration, BuildServiceConfig buildServiceConfig) {
ServiceHub dockerServiceHub, JKubeConfiguration configuration,
BuildServiceConfig buildServiceConfig,
LazyBuilder<ResourceService> resourceService) {
this.clusterAccess = clusterAccess;
this.platformMode = platformMode;
this.log = log;
this.dockerServiceHub = dockerServiceHub;
this.configuration = configuration;
this.buildServiceConfig = buildServiceConfig;
this.resourceService = resourceService;
init();
}

Expand Down Expand Up @@ -136,6 +140,10 @@ public BuildService getBuildService() {
return buildService.get();
}

public ResourceService getResourceService() {
return resourceService.get();
}

public ApplyService getApplyService() {
return applyService.get();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.config.service;

import java.io.File;
import java.io.IOException;

import org.eclipse.jkube.kit.common.KitLogger;
import org.eclipse.jkube.kit.common.util.ResourceClassifier;
import org.eclipse.jkube.kit.config.resource.PlatformMode;

import io.fabric8.kubernetes.api.model.KubernetesList;

public interface ResourceService {

KubernetesList generateResources(PlatformMode platformMode, EnricherManager enricherManager, KitLogger log)
throws IOException;

File writeResources(KubernetesList resources, ResourceClassifier classifier, KitLogger log) throws IOException;

@FunctionalInterface
interface ResourceFileProcessor {

File[] processResources(File[] resources) throws IOException;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.config.service;

import java.io.File;

import org.eclipse.jkube.kit.common.JavaProject;
import org.eclipse.jkube.kit.common.ResourceFileType;
import org.eclipse.jkube.kit.config.resource.ResourceConfig;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* Class to hold configuration parameters for the Resource service.
*/
@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Getter
@EqualsAndHashCode
public class ResourceServiceConfig {

private JavaProject project;
private File resourceDir;
private File targetDir;
private ResourceFileType resourceFileType;
private ResourceConfig resourceConfig;
private ResourceService.ResourceFileProcessor resourceFilesProcessor;
private boolean interpolateTemplateParameters;

}
14 changes: 13 additions & 1 deletion jkube-kit/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,25 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jkube</groupId>
<artifactId>jkube-kit-resource-service</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jkube</groupId>
<artifactId>jkube-kit-resource-helm</artifactId>
<version>${project.version}</version>
</dependency>

<!-- == jkube ===================================== -->
<dependency>
<groupId>org.eclipse.jkube</groupId>
<artifactId>jkube-kit-profiles</artifactId>
<version>${project.version}</version>
</dependency>

<!-- == Fabric8 Kubernetes Client ===================================== -->
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
Expand Down
1 change: 1 addition & 0 deletions jkube-kit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<module>enricher/generic</module>
<module>enricher/specific</module>
<module>profile</module>
<module>resource/service</module>
<module>resource/helm</module>
<module>watcher/api</module>
<module>watcher/standard</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ private static void createTemplateParameters(HelmConfig helmConfig, File outputD
.orElse(Collections.emptyList()).stream()
.map(Template::getParameters).flatMap(List::stream)
.map(HelmParameter::new).collect(Collectors.toList());
final Map<String, String> values = helmParameters.stream().collect(Collectors.toMap(
HelmParameter::getHelmName, hp -> hp.getParameter().getValue()));
final Map<String, String> values = helmParameters.stream()
.filter(hp -> hp.getParameter().getValue() != null)
.collect(Collectors.toMap(HelmParameter::getHelmName, hp -> hp.getParameter().getValue()));

File outputChartFile = new File(outputDir, VALUES_FILENAME);
ResourceUtil.save(outputChartFile, values, ResourceFileType.yaml);
Expand Down
55 changes: 55 additions & 0 deletions jkube-kit/resource/service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2019 Red Hat, Inc.
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
which is available at:
https://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
Contributors:
Red Hat, Inc. - initial API and implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.jkube</groupId>
<artifactId>jkube-kit-parent</artifactId>
<version>1.0.1-SNAPSHOT</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>

<artifactId>jkube-kit-resource-service</artifactId>

<name>JKube Kit :: Resource :: Service</name>

<dependencies>

<dependency>
<groupId>org.eclipse.jkube</groupId>
<artifactId>jkube-kit-enricher-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jkube</groupId>
<artifactId>jkube-kit-profiles</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit a80ecbd

Please sign in to comment.