Skip to content

Commit

Permalink
🌱 fix tilt with envsubst
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Eldeib <[email protected]>
  • Loading branch information
alexeldeib committed Jul 17, 2020
1 parent 19afe6c commit 27dea82
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ LINK_CHECKER_BIN := bin/liche
LINK_CHECKER := $(TOOLS_DIR)/$(LINK_CHECKER_BIN)
GO_APIDIFF_BIN := bin/go-apidiff
GO_APIDIFF := $(TOOLS_DIR)/$(GO_APIDIFF_BIN)
ENVSUBST_BIN := bin/envsubst
ENVSUBST := $(TOOLS_DIR)/$(ENVSUBST_BIN)

# Binaries.
# Need to use abspath so we can invoke these from subdirectories
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/kustomize)
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen)
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/golangci-lint)
CONVERSION_GEN := $(abspath $(TOOLS_BIN_DIR)/conversion-gen)
ENVSUBST := $(abspath $(TOOLS_BIN_DIR)/envsubst)

# Bindata.
GOBINDATA := $(abspath $(TOOLS_BIN_DIR)/go-bindata)
Expand Down Expand Up @@ -173,6 +176,11 @@ $(LINK_CHECKER): $(TOOLS_DIR)/go.mod
$(GO_APIDIFF): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && go build -tags=tools -o $(GO_APIDIFF_BIN) github.com/joelanford/go-apidiff

$(ENVSUBST): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && go build -tags=tools -o $(ENVSUBST_BIN) github.com/drone/envsubst/cmd/envsubst

envsubst: $(ENVSUBST)

.PHONY: e2e-framework
e2e-framework: ## Builds the CAPI e2e framework
cd $(E2E_FRAMEWORK_DIR); go build ./...
Expand Down
9 changes: 8 additions & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# set defaults

envsubst_cmd = "./hack/tools/bin/envsubst"

settings = {
"deploy_cert_manager": True,
"preload_images_for_kind": True,
Expand Down Expand Up @@ -189,11 +191,12 @@ def enable_provider(name):
)

# Apply the kustomized yaml for this provider
yaml = str(kustomize(context + "/config"))
yaml = str(kustomize_with_envsubst(context + "/config"))
substitutions = settings.get("kustomize_substitutions", {})
for substitution in substitutions:
value = substitutions[substitution]
yaml = yaml.replace("${" + substitution + "}", value)

if yaml.count("${") == 0:
k8s_yaml(blob(yaml))
else:
Expand Down Expand Up @@ -226,11 +229,15 @@ def include_user_tilt_files():

# Enable core cluster-api plus everything listed in 'enable_providers' in tilt-settings.json
def enable_providers():
local("make envsubst")
user_enable_providers = settings.get("enable_providers", [])
union_enable_providers = {k: "" for k in user_enable_providers + always_enable_providers}.keys()
for name in union_enable_providers:
enable_provider(name)

def kustomize_with_envsubst(path):
return str(local("kustomize build {} | {}".format(path, envsubst_cmd), quiet = True))

##############################
# Actual work happens here
##############################
Expand Down
10 changes: 10 additions & 0 deletions docs/book/src/developer/tilt.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ workflow that offers easy deployments and rapid iterative builds.
1. [kustomize](https://github.com/kubernetes-sigs/kustomize/blob/master/docs/INSTALL.md) standalone
(`kubectl kustomize` does not work because it is missing some features of kustomize v3)
1. [Tilt](https://docs.tilt.dev/install.html) v0.12.0 or newer
1. [envsubst](https://github.com/drone/envsubst) v1.0.2 or similar to handle clusterctl var replacement.
1. Clone the [Cluster API](https://github.com/kubernetes-sigs/cluster-api) repository locally
1. Clone the provider(s) you want to deploy locally as well

We provider a make target to generate the envsubst binary if desired.
See the [provider contract](./../clusterctl/provider-contract.md) for
more details about how clusterctl uses variables.


```
make envsubst
```

## Getting started

### Create a kind cluster
Expand Down
1 change: 1 addition & 0 deletions hack/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.13

require (
github.com/blang/semver v3.5.1+incompatible
github.com/drone/envsubst v1.0.3-0.20200709231038-aa43e1c1a629
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/golangci/golangci-lint v1.27.0
github.com/joelanford/go-apidiff v0.0.0-20191206194835-106bcff5f060
Expand Down
2 changes: 2 additions & 0 deletions hack/tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 h1:cenwrSVm+Z7QL
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/drone/envsubst v1.0.3-0.20200709231038-aa43e1c1a629 h1:rIaZZalMGGPb2cU/+ypuggZ8aMlpa17RUlJUtsMv8pw=
github.com/drone/envsubst v1.0.3-0.20200709231038-aa43e1c1a629/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e h1:p1yVGRW3nmb85p1Sh1ZJSDm4A4iKLS5QNbvUHMgGu/M=
Expand Down
1 change: 1 addition & 0 deletions hack/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.
package tools

import (
_ "github.com/drone/envsubst/cmd/envsubst"
_ "github.com/go-bindata/go-bindata"
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "github.com/joelanford/go-apidiff"
Expand Down
1 change: 1 addition & 0 deletions test/infrastructure/docker/hack/tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/drone/envsubst v1.0.3-0.20200709231038-aa43e1c1a629/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
Expand Down

0 comments on commit 27dea82

Please sign in to comment.