Skip to content

Commit

Permalink
Merge branch 'master' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoltzsche committed Feb 7, 2021
2 parents b455984 + a9a9919 commit 79f6718
Show file tree
Hide file tree
Showing 151 changed files with 37,467 additions and 110 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
/example/**/tmpcharts
/example/kpt/*/output-*
/example/kpt/*/generated-*
/example/kpt/cert-manager/static/generated-manifest.yaml
/example/kpt/**/requirements.lock
example/kpt/linkerd/manifests/base/generated-manifest-without-secrets.yaml

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ARG HELM_VERSION=unknown-version
RUN go build -o khelm -ldflags "-X main.khelmVersion=$KHELM_VERSION -X main.helmVersion=$HELM_VERSION -s -w -extldflags '-static'" ./cmd/khelm && mv khelm /usr/local/bin/

FROM alpine:3.12
RUN mkdir /helm && chown root:nobody /helm && chmod 775 /helm
RUN mkdir /helm && chown root:nobody /helm && chmod 1777 /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
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ GOLINT := $(BUILD_DIR)/bin/golint
KPT := $(BUILD_DIR)/bin/kpt
KUSTOMIZE := $(BUILD_DIR)/bin/kustomize

KPT_VERSION ?= 0.37.0
KUSTOMIZE_VERSION ?= 3.8.7
KPT_VERSION ?= 0.37.1
KUSTOMIZE_VERSION ?= 3.9.3

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//')
VERSION ?= $(shell echo "$$(git describe --exact-match --tags $(git log -n1 --pretty='%h') 2> /dev/null || echo dev)-$(REV)" | sed '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 Expand Up @@ -63,6 +63,7 @@ e2e-test: image khelm-static kpt kustomize
IMAGE=$(IMAGE) ./e2e/image-cli-test.sh; \
./e2e/kpt-function-test.sh; \
./e2e/kpt-cert-manager-test.sh; \
./e2e/kpt-linkerd-test.sh; \
}

fmt:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Usage examples can be found in the [example](example) and [e2e](e2e) directories

The khelm kpt function templates a chart and returns the output as single manifest file or kustomization directory (when `outputPath` ends with `/`). The kustomization output can be used to apply further transformations by running a kustomize function afterwards.

Also, in opposite to the kustomize plugin approach, a kpt function does not depend on particular plugin binaries on the host and CD pipelines can run without dependencies to rendering technologies and chart servers since they just apply static mainfests (after changing values using `kpt cfg set`) located within a git repository to a cluster using `kpt live apply`.
In opposite to the kustomize plugin approach kpt function outputs can be audited reliably when committed to a git repository, a kpt function does not depend on particular plugin binaries on the host and CD pipelines can run without dependencies to rendering technologies and chart servers since they just apply static mainfests (and eventually change values using `kpt cfg set`) to a cluster using `kpt live apply`.

#### kpt function usage example

Expand Down Expand Up @@ -168,6 +168,7 @@ It exposes a `Helm` struct that provides a `Render()` function that returns the
| `name` | `--name` | Release name used to render the chart. |
| `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`). |
| `replaceLockFile` | `--replace-lock-file` | Remove requirements.lock and reload charts when it is out of sync. |
| `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. |
Expand Down
4 changes: 2 additions & 2 deletions cmd/khelm/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ func Execute(reader io.Reader, writer io.Writer) error {
logVersion()
}
rootCmd := &cobra.Command{
Version: versionInfo(),
PreRun: logVersionPreRun,
PreRun: logVersionPreRun,
}
errBuf := bytes.Buffer{}

Expand All @@ -72,6 +71,7 @@ func Execute(reader io.Reader, writer io.Writer) error {
}
}

rootCmd.AddCommand(versionCmd)
rootCmd.Example = usageExample
rootCmd.Use = "khelm"
rootCmd.Short = fmt.Sprintf("khelm %s chart renderer", khelmVersion)
Expand Down
3 changes: 2 additions & 1 deletion cmd/khelm/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ func templateCommand(h *helm.Helm, writer io.Writer) *cobra.Command {
f.BoolVar(&trustAnyRepo, flagTrustAnyRepo, trustAnyRepo,
fmt.Sprintf("Allow to use repositories that are not registered within repositories.yaml (default is true when repositories.yaml does not exist; %s)", envTrustAnyRepo))
f.BoolVar(&req.NamespacedOnly, "namespaced-only", false, "Fail on known cluster-scoped resources and those of unknown kinds")
f.BoolVar(&req.Verify, "verify", false, "Verify the package before using it")
f.StringVar(&req.Keyring, "keyring", req.Keyring, "Keyring used to verify the chart")
f.BoolVar(&req.Verify, "verify", false, "Verify the package before using it")
f.BoolVar(&req.ReplaceLockFile, "replace-lock-file", false, "Remove requirements.lock and reload charts when it is out of sync")
f.StringVar(&req.Name, "name", req.Name, "Release name")
f.StringVar(&req.Namespace, "namespace", req.Namespace, "Set the installation namespace used by helm templates")
f.StringVar(&req.ForceNamespace, "force-namespace", req.ForceNamespace, "Set namespace on all namespaced resources (and those of unknown kinds)")
Expand Down
15 changes: 15 additions & 0 deletions cmd/khelm/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"fmt"

"github.com/spf13/cobra"
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Prints the version info",
Run: func(_ *cobra.Command, _ []string) {
fmt.Println(versionInfo())
},
}
2 changes: 1 addition & 1 deletion e2e/kpt-cert-manager-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
cd "$(dirname "$0")/../example"

echo
echo " TEST $0: Run kpt functions of example/cert-manager"
echo " TEST $0: Run kpt functions of example/kpt/cert-manager"
echo

set -e
Expand Down
2 changes: 1 addition & 1 deletion e2e/kpt-function-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
cd "$(dirname "$0")/../example"

echo
echo " TEST $0: Run kpt functions of example/test-cases"
echo " TEST $0: Run kpt functions of example/kpt/test-cases"
echo

set -e
Expand Down
23 changes: 23 additions & 0 deletions e2e/kpt-linkerd-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

EXAMPLE_DIR="$(dirname "$0")/../example"

GENERATED_FILE="$EXAMPLE_DIR/kpt/linkerd/manifests/static/generated-manifest.yaml"

echo
echo " TEST $0: Run kpt functions of example/kpt/linkerd"
echo

set -e

rm -f "$GENERATED_FILE"

(
set -ex
make -C "$EXAMPLE_DIR/kpt/linkerd" update generate

[ -f "$GENERATED_FILE" ]
grep -Eq ' name: linkerd-config-tpl$' "$GENERATED_FILE" || (echo 'FAIL: output does not contain linkerd-config-tpl' >&2; false)
)

echo SUCCESS
2 changes: 1 addition & 1 deletion example/jenkins/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: ChartRenderer
metadata:
name: myjenkins
namespace: jenkins
repository: https://kubernetes-charts.storage.googleapis.com
repository: https://charts.helm.sh/stable
chart: jenkins
version: 0.32.4
valueFiles:
Expand Down
Loading

0 comments on commit 79f6718

Please sign in to comment.