/helm-maven-plugin

Maven Plugin for Helm Charts

Primary LanguageKotlinApache License 2.0Apache-2.0

Helm Maven Plugin

Build Status Badge

A Maven plugin that makes Maven properties available in your Helm Charts. It can be used to automatically package your Helm Chart, render it and upload it to a Chart Museum.

Usage

Add the following to your pom.xml

<build>
  <plugins>
    ...
    <plugin>
      <groupId>com.deviceinsight.helm</groupId>
      <artifactId>helm-maven-plugin</artifactId>
      <version>2.1.0</version>
      <configuration>
        <chartName>my-chart</chartName>
        <chartRepoUrl>https://kubernetes-charts.storage.googleapis.com/</chartRepoUrl>
        <helmVersion>2.13.0</helmVersion>
        <strictLint>true</strictLint>
        <valuesFile>src/test/helm/my-chart/values.yaml</valuesFile>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>package</goal>
            <goal>lint</goal>
            <goal>template</goal>
            <goal>deploy</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

In the same Maven module, put your helm charts into src/main/helm/<chartName>. In the Chart.yaml, you can use the ${artifactId} and ${project.version} Maven placeholders. You can also use Maven properties.

An example for a Chart.yaml is:

apiVersion: v1
description: A Helm chart installing Rubicon
name: ${artifactId}
version: ${project.version}
home: https://gitlab.device-insight.com/deviceinsight/rubicon
maintainers:
  - name: Device Insight
    url: https://www.device-insight.com

You probably also will adjust the templates/deployment.yaml so that the correct docker image is used. An example snippet:

[...]
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}/rubicon:${project.version}"
[...]

Configuration

Property Default Description

chartName

The Maven artifactId

The name of the chart

chartRepoUrl

"https://kubernetes-helm.storage.googleapis.com/"

The URL of the Chart repository where dependencies are required from and where charts should be published to

chartRepoUsername

None

The username for basic authentication against the chart repo

chartRepoPassword

None

The password for basic authentication against the chart repo

chartFolder

"src/main/helm/<chartName>"

The location of the chart files (e.g. Chart.yaml).

skipSnapshots

true

If true, SNAPSHOT versions will be built, but not deployed.

helmGroupId

"com.deviceinsight.helm"

The helm binary groupId

helmArtifactId

"helm"

The helm binary artifactId

helmVersion

None

The helm binary version

helm.skip

false

If true, execution will be skipped entirely

strictLint

false

If true, linting fails on warnings (see: Lint)

valuesFile

None

values file that should be used for goals Lint, Template

outputFile

target/test-classes/helm.yaml

output file for template goal

deployAtEnd

false

If true, the helm chart is deployed at the end of a multi-module Maven build. This option does not make sense for single-module Maven projects.

Goals

Package

Goal packages a chart directory into a chart archive using the helm package command.

Deploy

Goal publishes the packaged chart in the configured chart repository.

Lint

Goal examines a chart for possible issues using the helm lint command.

  • A values file can be provided via parameter valueFile

  • Strict linting can be configured via parameter strictLint

Template

goal locally renders templates using the helm template command.

  • A values file can be provided via parameter valueFile

  • An output file can be provided via parameter outputFile

Example

To use the deployAtEnd functionality it’s mandatory to put the Helm Maven Plugin configuration in the parent pom.

<build>
  <plugins>
    ...
    <plugin>
	  <groupId>com.deviceinsight.helm</groupId>
	  <artifactId>helm-maven-plugin</artifactId>
	  <version>2.1.0</version>
	  <configuration>
		<chartName>my-chart</chartName>
		<chartRepoUrl>https://kubernetes-charts.storage.googleapis.com/</chartRepoUrl>
		<helmVersion>2.13.0</helmVersion>
		<strictLint>true</strictLint>
		<valuesFile>src/test/helm/my-chart/values.yaml</valuesFile>
		<deployAtEnd>true</deployAtEnd>
	  </configuration>
	  <executions>
		<execution>
		  <goals>
			<goal>package</goal>
			<goal>lint</goal>
			<goal>template</goal>
			<goal>deploy</goal>
		  </goals>
		</execution>
	  </executions>
	</plugin>
  </plugins>
</build>

Releasing

Creating a new release involves the following steps:

  1. ./mvnw -DenableSshAgent=true jgitflow:release-start jgitflow:release-finish

    Note
    The -DenableSshAgent=true is only necessary, if you cloned the repository via SSH.
  2. git push origin master

  3. git push --tags

  4. git push origin develop

In order to deploy the release to Maven Central, you need to create an account at https://issues.sonatype.org and configure your account in ~/.m2/settings.xml:

<settings>
  <servers>
    <server>
      <id>ossrh</id>
      <username>your-jira-id</username>
      <password>your-jira-pwd</password>
    </server>
  </servers>
</settings>

The account also needs access to the project on Maven Central. This can be requested by another project member.

Then check out the release you want to deploy (git checkout x.y.z) and run ./mvnw deploy -Prelease.