Skip to content

Commit

Permalink
imrove: add json schema and readme for helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
csviri committed Aug 22, 2023
1 parent 0191e07 commit dcd1c49
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public class HelmChartProcessor {
"service.yaml",
"serviceaccount.yaml"
};
private static final String[] ROOT_STATIC_FILES = new String[] {
"README.md",
"values.schema.json"
};
public static final String CHART_YAML_FILENAME = "Chart.yaml";
public static final String VALUES_YAML_FILENAME = "values.yaml";
public static final String CRD_DIR = "crds";
Expand All @@ -71,18 +75,23 @@ public void handleHelmCharts(
var controllerConfigs = controllerConfigurations.getControllerConfigs().values();

createRelatedDirectories(helmDir);
copyTemplates(helmDir);
addTemplateFiles(helmDir);
addClusterRolesForReconcilers(helmDir, controllerConfigs);
addPrimaryClusterRoleBindings(helmDir, controllerConfigs);
addGeneratedDeployment(helmDir, generatedResources, controllerConfigurations);
addChartYaml(helmDir, appInfo.getName(), appInfo.getVersion());
addValuesYaml(helmDir, containerImageInfoBuildItem.getTag());
addReadmeAndSchema(helmDir);
addCRDs(new File(helmDir, CRD_DIR), generatedCRDInfoBuildItem);
} else {
log.debug("Generating helm chart is disabled");
}
}

private void addTemplateFiles(File helmDir) {
copyTemplates(helmDir.toPath().resolve(TEMPLATES_DIR), TEMPLATE_FILES);
}

private void addGeneratedDeployment(File helmDir, List<GeneratedKubernetesResourceBuildItem> generatedResources,
ControllerConfigurationsBuildItem controllerConfigurations) {
final var resources = GeneratedResourcesUtils.loadFrom(generatedResources);
Expand Down Expand Up @@ -178,6 +187,10 @@ private void addValuesYaml(File helmDir, String tag) {
}
}

private void addReadmeAndSchema(File helmDir) {
copyTemplates(helmDir.toPath(), ROOT_STATIC_FILES);
}

private void addChartYaml(File helmDir, String name, String version) {
try {
Chart chart = new Chart();
Expand All @@ -191,15 +204,14 @@ private void addChartYaml(File helmDir, String name, String version) {
}
}

private void copyTemplates(File helmDir) {
final var destinationDir = helmDir.toPath().resolve(TEMPLATES_DIR);
for (String template : TEMPLATE_FILES) {
private void copyTemplates(Path path, String[] staticTemplateFiles) {
for (String template : staticTemplateFiles) {
try (InputStream is = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(HELM_TEMPLATES_STATIC_DIR + template)) {
if (is == null) {
throw new IllegalArgumentException("Template file " + template + " doesn't exist");
}
Files.copy(is, destinationDir.resolve(template), REPLACE_EXISTING);
Files.copy(is, path.resolve(template), REPLACE_EXISTING);
} catch (IOException e) {
throw new IllegalStateException(e);
}
Expand Down
9 changes: 9 additions & 0 deletions core/deployment/src/main/resources/helm/static/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Configuration

The following values are configurable:

- `watchNamespaces` - namespaces to be watched, it's either a list of namespaces one of special values:
- `JOSDK_ALL_NAMESPACES` to watch all namespaces, or
- `JOSDK_WATCH_CURRENT` to watch the current namespace
- `version` - the current version of the application.

13 changes: 13 additions & 0 deletions core/deployment/src/main/resources/helm/static/values.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://json-schema.org/draft-07/schema#",
"title": "Values",
"type": "object",
"properties": {
"watchNamespaces": {
"type": "String"
},
"version": {
"type": "String"
}
}
}

0 comments on commit dcd1c49

Please sign in to comment.