From e386cd034333236831eceea9d505b6826fe12820 Mon Sep 17 00:00:00 2001 From: Justin Nauman Date: Tue, 3 Oct 2017 17:35:46 -0500 Subject: [PATCH] Adding in examples for readme --- .gitignore | 1 + PATHS.md | 58 +++++++++++++++++++ README.md | 22 ++++++- examples/charts/paths-example/.helmignore | 21 +++++++ examples/charts/paths-example/Chart.yaml | 4 ++ .../paths-example/templates/_helpers.tpl | 16 +++++ .../paths-example/templates/deployment.yaml | 37 ++++++++++++ .../paths-example/templates/service.yaml | 19 ++++++ examples/charts/paths-example/values.yaml | 13 +++++ examples/deployments/dev/charts.yaml | 6 ++ examples/deployments/local/charts.yaml | 6 ++ examples/deployments/local/values.yaml | 2 + examples/deployments/prod/charts.yaml | 6 ++ examples/deployments/published/charts.yaml | 5 ++ examples/values/dev/paths-example/values.yaml | 2 + .../values/prod/paths-example/values.yaml | 2 + examples/values/replica-values.yaml | 2 + state/state.go | 3 +- 18 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 PATHS.md create mode 100644 examples/charts/paths-example/.helmignore create mode 100644 examples/charts/paths-example/Chart.yaml create mode 100644 examples/charts/paths-example/templates/_helpers.tpl create mode 100644 examples/charts/paths-example/templates/deployment.yaml create mode 100644 examples/charts/paths-example/templates/service.yaml create mode 100644 examples/charts/paths-example/values.yaml create mode 100644 examples/deployments/dev/charts.yaml create mode 100644 examples/deployments/local/charts.yaml create mode 100644 examples/deployments/local/values.yaml create mode 100644 examples/deployments/prod/charts.yaml create mode 100644 examples/deployments/published/charts.yaml create mode 100644 examples/values/dev/paths-example/values.yaml create mode 100644 examples/values/prod/paths-example/values.yaml create mode 100644 examples/values/replica-values.yaml diff --git a/.gitignore b/.gitignore index 849ddff3..5cb6357e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ dist/ +.idea/ diff --git a/PATHS.md b/PATHS.md new file mode 100644 index 00000000..cbb93383 --- /dev/null +++ b/PATHS.md @@ -0,0 +1,58 @@ +# Paths Overivew +Using manifest files in conjunction with command line argument can be a bit confusing. + +A few rules to clear up this ambiguity: + +- Absolute paths are always resolved as absolute paths +- Relative paths referenced *in* the helmfile manifest itself are relative to that manifest +- Relative paths referenced on the command line are relative to the current working directory the user is in + +### Examples +There are several examples that we can go through in the `/examples` folder which demonstrate this. + +**Local Execution** + +This is an example of a Helmfile manifest referencing a local value directly. + +Indirect: +``` +helmfile -f examples/deployments/local/charts.yaml sync +``` + +Direct: +``` +cd examples/deployments/local/ +helmfile sync +``` + +**Relative Paths in Helmfile** + +This is an example of a Helmfile manifest using relative paths for values. + +Indirect: +``` +helmfile -f examples/deployments/dev/charts.yaml sync +``` + +Direct: +``` +cd examples/deployments/dev/ +helmfile sync +``` + +**Relative Paths in Helmfile w/ --values overrides** + +This is an example of a Helmfile manifest using relative paths for values including an additional `--values` from the command line. + +NOTE: The `--values` is resolved relative to the CWD of the terminal *not* the Helmfile manifest. You can see this with the `replicas` being adjusted to 3 now for the deployment. + +Indirect: +``` +helmfile -f examples/deployments/dev/charts.yaml sync --values values/replica-values.yaml +``` + +Direct: +``` +cd examples/deployments/dev/ +helmfile sync --values ../../values/replica-values.yaml +``` diff --git a/README.md b/README.md index cc8f0b18..4f8081a4 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,10 @@ repositories: url: http://roboll.io/charts charts: + # Published chart example - name: vault # helm deployment name namespace: vault # target namespace - chart: roboll/vault-secret-manager # chart reference + chart: roboll/vault-secret-manager # chart reference (repository) values: [ vault.yaml ] # value files (--values) set: # values (--set) - name: address @@ -33,6 +34,13 @@ charts: - name: db.password value: DB_PASSWORD # $DB_PASSOWRD needs to be set in the calling environment ex: export DB_PASSWORD='password1' + # Local chart example + - name: grafana # helm deployment name + namespace: another # target namespace + chart: ../my-charts/grafana # chart reference (relative path to manifest) + values: + - ../../my-values/grafana/values.yaml # Values file (relative path to manifest) + ``` ## install @@ -72,3 +80,15 @@ the charts/releases defined in the manifest. Under the covers Helmfile is simply using the `helm diff` plugin, so that needs to be installed prior. For Helm 2.3+ you should be able to simply execute `helm plugin install https://github.com/databus23/helm-diff`. For more details please look at their [documentation](https://github.com/databus23/helm-diff#helm-diff-plugin). + + +## Paths Overview +Using manifest files in conjunction with command line argument can be a bit confusing. + +A few rules to clear up this ambiguity: + +- Absolute paths are always resolved as absolute paths +- Relative paths referenced *in* the helmfile manifest itself are relative to that manifest +- Relative paths referenced on the command line are relative to the current working directory the user is in + +For additional context, take a look at [paths examples](PATHS.md) diff --git a/examples/charts/paths-example/.helmignore b/examples/charts/paths-example/.helmignore new file mode 100644 index 00000000..f0c13194 --- /dev/null +++ b/examples/charts/paths-example/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/examples/charts/paths-example/Chart.yaml b/examples/charts/paths-example/Chart.yaml new file mode 100644 index 00000000..801712f7 --- /dev/null +++ b/examples/charts/paths-example/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: demonstration of local file path references in Helmfile +name: paths-example +version: 0.1.0 diff --git a/examples/charts/paths-example/templates/_helpers.tpl b/examples/charts/paths-example/templates/_helpers.tpl new file mode 100644 index 00000000..f0d83d2e --- /dev/null +++ b/examples/charts/paths-example/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/examples/charts/paths-example/templates/deployment.yaml b/examples/charts/paths-example/templates/deployment.yaml new file mode 100644 index 00000000..d15e0f34 --- /dev/null +++ b/examples/charts/paths-example/templates/deployment.yaml @@ -0,0 +1,37 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ template "fullname" . }} + labels: + app: {{ template "name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + template: + metadata: + labels: + app: {{ template "name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.internalPort }} + livenessProbe: + httpGet: + path: / + port: {{ .Values.service.internalPort }} + readinessProbe: + httpGet: + path: / + port: {{ .Values.service.internalPort }} + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} + {{- end }} diff --git a/examples/charts/paths-example/templates/service.yaml b/examples/charts/paths-example/templates/service.yaml new file mode 100644 index 00000000..f311d10a --- /dev/null +++ b/examples/charts/paths-example/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "fullname" . }} + labels: + app: {{ template "name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: {{ .Values.service.name }} + selector: + app: {{ template "name" . }} + release: {{ .Release.Name }} diff --git a/examples/charts/paths-example/values.yaml b/examples/charts/paths-example/values.yaml new file mode 100644 index 00000000..3c28e36f --- /dev/null +++ b/examples/charts/paths-example/values.yaml @@ -0,0 +1,13 @@ +# Default values for paths-example. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +image: + repository: nginx + tag: stable + pullPolicy: IfNotPresent +service: + name: nginx + type: ClusterIP + externalPort: 80 + internalPort: 80 diff --git a/examples/deployments/dev/charts.yaml b/examples/deployments/dev/charts.yaml new file mode 100644 index 00000000..74380fa4 --- /dev/null +++ b/examples/deployments/dev/charts.yaml @@ -0,0 +1,6 @@ +charts: + - name: dev-paths-example + namespace: dev + chart: ../../charts/paths-example/ + values: + - ../../values/dev/paths-example/values.yaml # Values file (relative path to manifest) \ No newline at end of file diff --git a/examples/deployments/local/charts.yaml b/examples/deployments/local/charts.yaml new file mode 100644 index 00000000..1860204c --- /dev/null +++ b/examples/deployments/local/charts.yaml @@ -0,0 +1,6 @@ +charts: + - name: local-paths-example + namespace: local + chart: ../../charts/paths-example/ + values: + - values.yaml # Values file (relative path to manifest) diff --git a/examples/deployments/local/values.yaml b/examples/deployments/local/values.yaml new file mode 100644 index 00000000..82143eed --- /dev/null +++ b/examples/deployments/local/values.yaml @@ -0,0 +1,2 @@ +# Dev specific overrides +nameOverride: local-nginx diff --git a/examples/deployments/prod/charts.yaml b/examples/deployments/prod/charts.yaml new file mode 100644 index 00000000..adde1c65 --- /dev/null +++ b/examples/deployments/prod/charts.yaml @@ -0,0 +1,6 @@ +charts: + - name: prod-paths-example + namespace: prod + chart: ../../charts/paths-example/ + values: + - ../../values/prod/paths-example/values.yaml # Values file (relative path to manifest) \ No newline at end of file diff --git a/examples/deployments/published/charts.yaml b/examples/deployments/published/charts.yaml new file mode 100644 index 00000000..0b4a56c4 --- /dev/null +++ b/examples/deployments/published/charts.yaml @@ -0,0 +1,5 @@ +charts: + # Published chart example + - name: grafana # helm deployment name + namespace: grafana # target namespace + chart: stable/grafana # chart reference (repository) diff --git a/examples/values/dev/paths-example/values.yaml b/examples/values/dev/paths-example/values.yaml new file mode 100644 index 00000000..2a84fa75 --- /dev/null +++ b/examples/values/dev/paths-example/values.yaml @@ -0,0 +1,2 @@ +# Dev specific overrides +nameOverride: dev-nginx diff --git a/examples/values/prod/paths-example/values.yaml b/examples/values/prod/paths-example/values.yaml new file mode 100644 index 00000000..b02bd583 --- /dev/null +++ b/examples/values/prod/paths-example/values.yaml @@ -0,0 +1,2 @@ +# Prod specific overrides +nameOverride: prod-nginx \ No newline at end of file diff --git a/examples/values/replica-values.yaml b/examples/values/replica-values.yaml new file mode 100644 index 00000000..980c46b7 --- /dev/null +++ b/examples/values/replica-values.yaml @@ -0,0 +1,2 @@ +# Example used to override value explicitly via CLI +replicaCount: 3 \ No newline at end of file diff --git a/state/state.go b/state/state.go index a5dd0d35..bcf586f1 100644 --- a/state/state.go +++ b/state/state.go @@ -51,7 +51,8 @@ func ReadFromFile(file string) (*HelmState, error) { } var state HelmState - state.BaseChartPath = path.Dir(file) + + state.BaseChartPath, _ = filepath.Abs(path.Dir(file)) if err := yaml.Unmarshal(content, &state); err != nil { return nil, err }