eclipse-jkube / jkube

Build and Deploy java applications on Kubernetes
https://www.eclipse.dev/jkube/
Eclipse Public License 2.0
775 stars 521 forks source link

As an user, I want to generate a Helm Chart without any Kubernetes resource #2112

Open jmesnil opened 1 year ago

jmesnil commented 1 year ago

Component

Kubernetes Maven Plugin

Is your enhancement related to a problem? Please describe

As a Java developer, I'm writing a Jakarta EE application that is deployed on Kubernetes. It is running on WildFly and needs a database. In my Java project, I'm using the kubernetes-maven-plugin to build and push a container image.

Now, I want to use Helm to package and deploy my application. My Java project does not need to create any Kubernetes resources. Instead it relies on the wildfly and postgresql Helm charts to deploy the resources.

The ideal workflow I want to achieve is:

# Push my application image in a container registry and generate a Helm Chart that depends on the wildfly and postgresql to handle the deployment on Kubernetes
$ mvn k8s:build k8s:push k8s:helm
# Deploy the full application (my app, WildFly and PostgreSQL) on Kubernetes 
$ helm install -g -f ./my-app-1.0.0.tgz 

I can already configure the expected Helm Chart from the pom.xml with:

    <helm>
      <dependencies>
        <dependency>
          <name>wildfly</name>
          <version>1.3.0</version>
          <repository>https://docs.wildfly.org/wildfly-charts/</repository>
        </dependency>
        <dependency>
          <name>postgresql</name>
          <version>12.1.0</version>
          <repository>https://charts.bitnami.com/bitnami</repository>
        </dependency>
      </dependencies>
      <parameters>
        <parameter>
          <name>wildfly.build.uri</name>
          <value>quay.io/whatever/whatever</value>
        </parameter>
        <parameter>
          <name>postgresql.auth.database</name>
          <value>the-name-of-my-db</value>
        </parameter>
      </parameters>
    </helm>

However, JKube complains when I run mvn k8s:helm

[INFO] --- k8s:1.11.0:helm (default-cli) @ wuar-demo ---
[INFO] k8s: Creating Helm Chart "wuar-demo" for Kubernetes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.185 s
[INFO] Finished at: 2023-03-29T17:28:02+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.11.0:helm (default-cli) on project wuar-demo: Chart source directory /Users/jmesnil/Developer/wildfly-up-and-running/wuar-demo/src/main/kubernetes does not exist so cannot make chart "wuar-demo". Probably you need run 'mvn kubernetes:resource' before. -> [Help 1]

Running mvn clean k8s:resource k8s:helm does not fix the failure:

[INFO] --- k8s:1.11.0:resource (default-cli) @ wuar-demo ---
[INFO] k8s: Using resource templates from /Users/jmesnil/Developer/wildfly-up-and-running/wuar-demo/src/main/jkube
[INFO] k8s: jkube-controller: Adding a default Deployment
[WARNING] k8s: jkube-git: Could not detect any git remote
[INFO] k8s: jkube-revision-history: Adding revision history limit to 2
[INFO] k8s: validating /Users/jmesnil/Developer/wildfly-up-and-running/wuar-demo/target/classes/META-INF/jkube/kubernetes/wuar-demo-deployment.yml resource
[INFO]
[INFO] --- k8s:1.11.0:helm (default-cli) @ wuar-demo ---
[INFO] k8s: Creating Helm Chart "wuar-demo" for Kubernetes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.095 s
[INFO] Finished at: 2023-03-29T17:30:07+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.11.0:helm (default-cli) on project wuar-demo: Chart source directory /Users/jmesnil/Developer/wildfly-up-and-running/wuar-demo/src/main/kubernetes does not exist so cannot make chart "wuar-demo". Probably you need run 'mvn kubernetes:resource' before. -> [Help 1]

Describe the solution you'd like

I want to use JKube to generate a Helm Chart without requiring Kubernetes resources from the Java project.

Describe alternatives you've considered

The workaround I found was to create an empty.yaml file in src/main/kubernetes with an empty content.

With that change, mvn clean k8s:resource k8s:helm works:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< wildfly-up-and-running:wuar-demo >------------------
[INFO] Building wuar-demo 1.0.0
[INFO]   from pom.xml
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- clean:3.1.0:clean (default-clean) @ wuar-demo ---
[INFO] Deleting /Users/jmesnil/Developer/wildfly-up-and-running/wuar-demo/target
[INFO]
[INFO] --- k8s:1.11.0:resource (default-cli) @ wuar-demo ---
[INFO] k8s: Using resource templates from /Users/jmesnil/Developer/wildfly-up-and-running/wuar-demo/src/main/jkube
[INFO] k8s: jkube-controller: Adding a default Deployment
[WARNING] k8s: jkube-git: Could not detect any git remote
[INFO] k8s: jkube-revision-history: Adding revision history limit to 2
[INFO] k8s: validating /Users/jmesnil/Developer/wildfly-up-and-running/wuar-demo/target/classes/META-INF/jkube/kubernetes/wuar-demo-deployment.yml resource
[INFO]
[INFO] --- k8s:1.11.0:helm (default-cli) @ wuar-demo ---
[INFO] k8s: Creating Helm Chart "wuar-demo" for Kubernetes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

And the generated Helm chart contains the expected configuration:

$ tree target/jkube/helm/wuar-demo/kubernetes
target/jkube/helm/wuar-demo/kubernetes
├── Chart.yaml
├── LICENSE
├── README.adoc
├── templates
│   └── empty.yaml
└── values.yaml

Additional context

This workaround is not blocking me but I think it is a valid use case to be able to generate a Helm Chart without any Kubernetes resource in the Java project.

From JKube point of view, I think k8s:helm should remove the requirement that Kubernetes resources exists inside the Java project (or its target dir).

manusa commented 1 year ago

Similar to #865