Skip to content

Commit

Permalink
Upgrade to helm 3.
Browse files Browse the repository at this point in the history
Introduces go module and config schema version v2.
Adds --skip-crds option/excludeCRDs field.
  • Loading branch information
mgoltzsche committed Dec 13, 2020
1 parent 3862cb3 commit b455984
Show file tree
Hide file tree
Showing 48 changed files with 819 additions and 537 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN go build -o khelm -ldflags "-X main.khelmVersion=$KHELM_VERSION -X main.helm

FROM alpine:3.12
RUN mkdir /helm && chown root:nobody /helm && chmod 775 /helm
ENV HELM_HOME=/helm
ENV HELM_REPOSITORY_CONFIG=/helm/repository/repositories.yaml
ENV HELM_REPOSITORY_CACHE=/helm/cache
COPY --from=build /usr/local/bin/khelm /usr/local/bin/khelmfn
ENTRYPOINT ["/usr/local/bin/khelmfn"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ KUSTOMIZE_VERSION ?= 3.8.7

REV := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown')
VERSION ?= $(shell echo "$$(git for-each-ref refs/tags/ --count=1 --sort=-version:refname --format='%(refname:short)' 2>/dev/null)-dev-$(REV)" | sed 's/^v//')
HELM_VERSION := $(shell grep k8s\.io/helm go.mod | sed -E -e 's/k8s\.io\/helm|\s+|\+.*//g' -e 's/^v//')
HELM_VERSION := $(shell grep helm\.sh/helm/ go.mod | sed -E -e 's/helm\.sh\/helm\/v3|\s+//g' -e 's/^v//')
GO_LDFLAGS := -X main.khelmVersion=$(VERSION) -X main.helmVersion=$(HELM_VERSION)
BUILDTAGS ?=

Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,22 @@ Though plugin support in kustomize is still an alpha feature and may be removed

Install using curl (linux amd64):
```sh
mkdir -p $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v1/chartrenderer
curl -fsSL https://github.com/mgoltzsche/khelm/releases/latest/download/khelm-linux-amd64 > $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v1/chartrenderer/ChartRenderer
chmod u+x $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v1/chartrenderer/ChartRenderer
mkdir -p $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer
curl -fsSL https://github.com/mgoltzsche/khelm/releases/latest/download/khelm-linux-amd64 > $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer/ChartRenderer
chmod u+x $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer/ChartRenderer
```
or using `go`:
```sh
go get github.com/mgoltzsche/khelm/cmd/khelm
mkdir -p $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v1/chartrenderer
mv $GOPATH/bin/khelm $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v1/chartrenderer/ChartRenderer
go get github.com/mgoltzsche/khelm/v2/cmd/khelm
mkdir -p $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer
mv $GOPATH/bin/khelm $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer/ChartRenderer
```

#### Plugin usage example

A _plugin descriptor_ specifies the helm repository, chart, version and values that should be used in a kubernetes-style resource can be referenced in the `generators` section of a `kustomization.yaml` and can look as follows:
```yaml
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: cert-manager # fallback for `name`
Expand Down Expand Up @@ -151,7 +151,7 @@ docker run mgoltzsche/khelm:latest template cert-manager --version=0.9.x --repo=

### Go API

The khelm Go API `github.com/mgoltzsche/khelm/pkg/helm` provides a simple templating interface on top of the Helm Go API.
The khelm Go API `github.com/mgoltzsche/khelm/v2/pkg/helm` provides a simple templating interface on top of the Helm Go API.
It exposes a `Helm` struct that provides a `Render()` function that returns the rendered resources as `kyaml` objects.

## Configuration options
Expand All @@ -166,8 +166,9 @@ It exposes a `Helm` struct that provides a `Render()` function that returns the
| `apiVersions` | `--api-versions` | Kubernetes api versions used for Capabilities.APIVersions. |
| `kubeVersion` | `--kube-version` | Kubernetes version used for Capabilities.KubeVersion. |
| `name` | `--name` | Release name used to render the chart. |
| `verify` | `--verify` | If enabled verifies the signature of all charts using the `keyring` (see [Helm 2 provenance and integrity](https://v2.helm.sh/docs/provenance/)). |
| `verify` | `--verify` | If enabled verifies the signature of all charts using the `keyring` (see [Helm 3 provenance and integrity](https://helm.sh/docs/topics/provenance/)). |
| `keyring` | `--keyring` | GnuPG keyring file (default `~/.gnupg/pubring.gpg`). |
| `excludeCRDs` | `--skip-crds` | If true Custom Resource Definitions are excluded from the output. |
| `exclude` | | List of resource selectors that exclude matching resources from the output. Fails if a selector doesn't match any resource. |
| `exclude[].apiVersion` | | Excludes resources by apiVersion. |
| `exclude[].kind` | | Excludes resources by kind. |
Expand Down
2 changes: 1 addition & 1 deletion cmd/khelm/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os/signal"
"syscall"

"github.com/mgoltzsche/khelm/pkg/helm"
"github.com/mgoltzsche/khelm/v2/pkg/helm"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/khelm/fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strconv"
"strings"

"github.com/mgoltzsche/khelm/internal/output"
"github.com/mgoltzsche/khelm/pkg/helm"
"github.com/mgoltzsche/khelm/v2/internal/output"
"github.com/mgoltzsche/khelm/v2/pkg/helm"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/fn/framework"
Expand Down
4 changes: 2 additions & 2 deletions cmd/khelm/fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"path/filepath"
"testing"

"github.com/mgoltzsche/khelm/internal/output"
"github.com/mgoltzsche/khelm/pkg/helm"
"github.com/mgoltzsche/khelm/v2/internal/output"
"github.com/mgoltzsche/khelm/v2/pkg/helm"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/kyaml/yaml"
Expand Down
4 changes: 2 additions & 2 deletions cmd/khelm/kustomize_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"io"
"strings"

"github.com/mgoltzsche/khelm/internal/output"
"github.com/mgoltzsche/khelm/pkg/helm"
"github.com/mgoltzsche/khelm/v2/internal/output"
"github.com/mgoltzsche/khelm/v2/pkg/helm"
)

func runAsKustomizePlugin(h *helm.Helm, generatorYAML string, writer io.Writer) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/khelm/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"
"strings"

"github.com/mgoltzsche/khelm/pkg/helm"
"github.com/mgoltzsche/khelm/v2/pkg/helm"
"github.com/spf13/cobra"
)

Expand Down
7 changes: 4 additions & 3 deletions cmd/khelm/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"io"

"github.com/mgoltzsche/khelm/internal/output"
"github.com/mgoltzsche/khelm/pkg/helm"
"github.com/mgoltzsche/khelm/v2/internal/output"
"github.com/mgoltzsche/khelm/v2/pkg/helm"
"github.com/spf13/cobra"
"k8s.io/helm/pkg/strvals"
"helm.sh/helm/v3/pkg/strvals"
)

func templateCommand(h *helm.Helm, writer io.Writer) *cobra.Command {
Expand Down Expand Up @@ -66,6 +66,7 @@ func templateCommand(h *helm.Helm, writer io.Writer) *cobra.Command {
f.StringSliceVarP(&req.ValueFiles, "values", "f", nil, "Specify values in a YAML file or a URL (can specify multiple)")
f.StringSliceVar(&req.APIVersions, "api-versions", nil, "Kubernetes api versions used for Capabilities.APIVersions")
f.StringVar(&req.KubeVersion, "kube-version", req.KubeVersion, "Kubernetes version used as Capabilities.KubeVersion.Major/Minor")
f.BoolVar(&req.ExcludeCRDs, "skip-crds", false, "excludes CRDs from the chart output if enabled")
f.StringVarP(&outOpts.FileOrDir, "output", "o", "-", "Write rendered output to given file or directory (as kustomization)")
f.BoolVar(&outOpts.Replace, "output-replace", false, "Delete and recreate the whole output directory or file")
return cmd
Expand Down
4 changes: 2 additions & 2 deletions cmd/khelm/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"k8s.io/helm/pkg/repo"
"helm.sh/helm/v3/pkg/repo"
)

func TestTemplateCommand(t *testing.T) {
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestTemplateCommandError(t *testing.T) {
defer os.Unsetenv("HELM_HOME")
err = os.Mkdir(repoDir, 0755)
require.NoError(t, err)
err = repo.NewRepoFile().WriteFile(filepath.Join(repoDir, "repositories.yaml"), 0644)
err = repo.NewFile().WriteFile(filepath.Join(repoDir, "repositories.yaml"), 0644)
require.NoError(t, err)
for _, c := range []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion e2e/kustomize-plugin-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ echo
TMP_DIR="$(mktemp -d)"
STATUS=0
(
PLUGIN_DIR=$TMP_DIR/kustomize/plugin/khelm.mgoltzsche.github.com/v1/chartrenderer
PLUGIN_DIR=$TMP_DIR/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer
set -ex
mkdir -p $PLUGIN_DIR
cp build/bin/khelm $PLUGIN_DIR/ChartRenderer
Expand Down
2 changes: 1 addition & 1 deletion example/apiversions-condition/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
apiVersion: v2
description: example chart using an apiversion condition
name: apiversions-condition
version: 0.1.0
3 changes: 1 addition & 2 deletions example/apiversions-condition/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: apiversions-condition
namespace: apiversions-condition-env
chart: ./chart
apiVersions:
- myfancyapi/v1
kubeVersion: 1.17
2 changes: 1 addition & 1 deletion example/cert-manager/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: cert-manager
Expand Down
2 changes: 1 addition & 1 deletion example/cluster-scoped-forbidden/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: mychart
Expand Down
2 changes: 1 addition & 1 deletion example/cluster-scoped/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: mychart
Expand Down
2 changes: 1 addition & 1 deletion example/exclude-nomatch/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: mychart
Expand Down
2 changes: 1 addition & 1 deletion example/exclude/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: mychart
Expand Down
2 changes: 1 addition & 1 deletion example/force-namespace/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: force-namespace
Expand Down
2 changes: 1 addition & 1 deletion example/invalid-requirements-lock/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: invalid-requirements-example
Expand Down
2 changes: 1 addition & 1 deletion example/jenkins/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: myjenkins
Expand Down
4 changes: 2 additions & 2 deletions example/localref/elk/requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ dependencies:
- name: elastic-stack
repository: https://kubernetes-charts.storage.googleapis.com
version: 1.6.0
digest: sha256:4d8edf7b9e1f7f7fccfb58b62632ad500f790bf5be6d2a861fd7c9c7109c88e6
generated: "2020-09-30T19:01:25.236657086Z"
digest: sha256:f6c12b6ec018fdb17bb14d2ee8495e763fb386166fe6d23b0baa4ff86bc94071
generated: "2020-10-18T16:27:26.090444945Z"
2 changes: 1 addition & 1 deletion example/localref/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: mychart
Expand Down
6 changes: 6 additions & 0 deletions example/localrefref/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: efk
repository: file://../localref/elk
version: 0.1.1
digest: sha256:d92f768c1b07b1a3d9308e9fc2ea94a0523cf8e4f422661e59da4659ee307076
generated: "2020-10-18T16:23:27.935558963Z"
7 changes: 6 additions & 1 deletion example/localrefref/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
apiVersion: v1
apiVersion: v2
descriptionx: Elasticsearch, Fluentd, Kibana (EFK)
name: efk-wrapper
version: 0.2.0
dependencies:
- name: efk
version: "~0.1.0"
repository: "file://../localref/elk"
alias: efk-custom
2 changes: 1 addition & 1 deletion example/localrefref/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: mychart
Expand Down
6 changes: 0 additions & 6 deletions example/localrefref/requirements.lock

This file was deleted.

4 changes: 0 additions & 4 deletions example/localrefref/requirements.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion example/namespace/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
apiVersion: v2
description: example chart with resources with and without namespace
name: namespace
version: 0.1.0
2 changes: 1 addition & 1 deletion example/namespace/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: namespace-test
Expand Down
3 changes: 2 additions & 1 deletion example/release-name/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: my-release-name
chart: .
kubeVersion: 1.17
2 changes: 1 addition & 1 deletion example/rook-ceph/operator/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: rook-ceph
Expand Down
2 changes: 1 addition & 1 deletion example/sonatype-nexus/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: sonatype-nexus
Expand Down
2 changes: 1 addition & 1 deletion example/unsupported-field-fail/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: mychart
Expand Down
2 changes: 1 addition & 1 deletion example/values-inheritance/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
apiVersion: v2
description: example chart to test values inheritance
name: values-inheritance-example
version: 0.1.0
2 changes: 1 addition & 1 deletion example/values-inheritance/generator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: khelm.mgoltzsche.github.com/v1
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: values-inheritance-example
Expand Down
24 changes: 8 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
module github.com/mgoltzsche/khelm
module github.com/mgoltzsche/khelm/v2

go 1.14

require (
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.1.1
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
github.com/Masterminds/semver/v3 v3.1.0
github.com/ghodss/yaml v1.0.0
github.com/gobwas/glob v0.2.3 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.1.1
github.com/stretchr/testify v1.4.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
k8s.io/apimachinery v0.19.4 // indirect
k8s.io/client-go v11.0.0+incompatible
k8s.io/helm v2.17.0+incompatible
github.com/spf13/cobra v1.0.0
github.com/stretchr/testify v1.6.1
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // must include https://github.com/go-yaml/yaml/issues/578
helm.sh/helm/v3 v3.4.1
k8s.io/client-go v0.19.3
rsc.io/letsencrypt v0.0.3 // indirect
sigs.k8s.io/kustomize/kyaml v0.10.1
)
Loading

0 comments on commit b455984

Please sign in to comment.