This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 202
Fix fabric8:helm feature in kubernetes mode #1628
Comments
if these changes don't harm the current plugin's flow, I would be happy to integrate this. |
@rohanKanojia They don't :
|
@Beennnn why don't you create a PR? |
Ok. I will work on this soon. |
@Beennnn : Are you working on PR for this? Otherwise I can pick it up. |
I had a bit of time to create PR for this. |
Sorry I cannot work on this these days. Feel free to pick it up. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Why do I need HELM ?
The documentation https://maven.fabric8.io/#fabric8:helm states
So, I raise my voice... 👍 I think the HELM feature can be considered as the de-facto standard for kubernetes configuration file packaging:
Why fabric8:helm ?
Because I love fabric8 , and because fabric8 provides HELM support. 👍
Why fabric8:helm does not work ?
I tried to run fabric8:helm using the documentation, with what I consider as a general use case as described here : #1072 (comment)
It did not work as is, but with several bug fixes I successfully made it work. I propose contributions below to fix it.
FIX BUG 1: use of .yaml extensions instead of .yml
HELM uses ".yaml" extension for
But the fabric core code is base on ".yml" extension: https://github.com/fabric8io/fabric8-maven-plugin/blob/master/core/src/main/java/io/fabric8/maven/core/util/ResourceFileType.java#L42
As a consequence, generating HELM resources will required converting ".yml" extensions to ".yaml".
This is taken into account into the code of the HelmMojo, but not in the code base of the fabric8 plugin.
FIX BUG 1A: FileUtil.stripPostfix is broken
In HelmMojo::copyResourceFilesToTemplatesDir there is a call to FileUtil.stripPostfix(...) to remove the ".yml" extension:
name = FileUtil.stripPostfix(name, ".yml") + YAML_EXTENSION;
see : https://github.com/fabric8io/fabric8-maven-plugin/blob/master/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/HelmMojo.java#L362
I suggest the fix below:
The content of the stripPostfixMethod should be fixed adding a first parameter with value "0" as this:
FIX BUG 1B: ResourceUtil.save cannot write ".yaml" extension files
There are 3 calls to ResourceUtil.save in HelmMojo:
All are made with a file name with the ".yaml" extension.
For example in line 224:
But the ResourceUtil.save() method adds the ".yml" extension without testing if an extension is not already set.
In fact, the entry point is the save() method see:
https://github.com/fabric8io/fabric8-maven-plugin/blob/master/core/src/main/java/io/fabric8/maven/core/util/ResourceUtil.java#L62
This method calls
type.addExtensionIfMissing(file);
https://github.com/fabric8io/fabric8-maven-plugin/blob/master/core/src/main/java/io/fabric8/maven/core/util/ResourceFileType.java#L62
I suggest the fix below:
With this approach, the extension is added only if there is no existing extension. And so, I works with ".yaml" extensions if already set as in the HelmMojo code.
Note: this approach is the more flexible, but other alternatives could be considered:
FIX BUG? 2: Unable to find the template file and resources
How is the sourceDir documented ?
According to the documentation, the source dir is defined as this:
sourceDir | Where to find the resource descriptors generated with fabric8:resource. By default this is:
How is it expected by the HelmMojo code ?
But in the HelmMojo, the default value for sourceDir is set like this (see https://github.com/fabric8io/fabric8-maven-plugin/blob/master/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/HelmMojo.java#L177):
Where type.getSourceDir() is set to "k8s-template" in HelmConfig (see https://github.com/fabric8io/fabric8-maven-plugin/blob/master/core/src/main/java/io/fabric8/maven/core/config/HelmConfig.java#L79) :
kubernetes("helm", "k8s-template", "Kubernetes"),
The value "k8s-template" is also used for the expected location of the template file (see https://github.com/fabric8io/fabric8-maven-plugin/blob/master/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/HelmMojo.java#L83 ):
This appears to be very odd to me... I cannot find documentation on this usage...
So... How to make it work ?
Very easily !
The HelmMojo code is clearly expecting the template file to be located at the sample place as the template resources. So I added a file named "template.yml" in the src/main/facbric8 directory:
src/main/fabric8 contains:
My template.yml file content is:
To fix it, I simply overrode the default values in the pom.xml file:
So... Why isn't it configured as this by default ?
Do you think the default configuration could be reverted ?
CONCLUSION
With very simple changes, the helm feature can be easily fixed:
How do this contribution can be integrated ?
Thanks,
Ben.
The text was updated successfully, but these errors were encountered: