Skip to content

Instantly share code, notes, and snippets.

@afirth
Created May 6, 2022 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afirth/81370d626da38e69fd573edce2ea2e4f to your computer and use it in GitHub Desktop.
Save afirth/81370d626da38e69fd573edce2ea2e4f to your computer and use it in GitHub Desktop.
Makefile for helm template + kustomize
#!make
include .env
MAKEFLAGS += \
--warn-undefined-variables
SHELL = /usr/bin/env bash
.SHELLFLAGS := -O globstar -eu -o pipefail -c
.SUFFIXES:
# consistent sorting on OSX/nix
export LC_ALL = C
# override these with .env or command line args:
# make <ACTION> chart=<CHART> repo=<REPO> repo_url=<REPO_URL>
chart ?= example_chart
repo ?= example_repo
repo_url ?= https://example.io
# fetches and templates charts from helm
# @afirth 2021-01
name ?= $(notdir $(CURDIR))
# validate enables setting Capabilities.KubeVersion
helm_extra_args := --namespace=$(name) --validate
.PHONY: all
all: clean generate
@printf "\nINFO: you may want to update the chart first!\n make fetch\n"
.PHONY: generate
generate:
helm template $(name) \
generated/charts/$(chart) \
--values values.yaml \
$(helm_extra_args) \
--output-dir ./generated
true > generated/kustomization.yaml
cd generated && ls -l && kustomize edit add resource $(chart)/**/*.yaml
echo "#WARNING This file is generated by make, DO NOT EDIT" >> generated/kustomization.yaml
.PHONY: repo-add
repo-add:
helm repo add $(repo) $(repo_url)
.PHONY: fetch
fetch:
-rm -r generated/charts/$(chart)
helm repo update
helm fetch $(repo)/$(chart) --untardir generated/charts --untar
.PHONY: clean
clean:
-rm -r generated/$(chart)/ generated/kustomization.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment