Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Tiltfile: Parameterize kustomize and main.go for providers #3604

Merged
merged 2 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def load_provider_tiltfiles():
provider_config["context"] = repo + "/" + provider_config["context"]
else:
provider_config["context"] = repo
if "kustomize_config" not in provider_config:
provider_config["kustomize_config"] = True
if "go_main" not in provider_config:
provider_config["go_main"] = "main.go"
providers[provider_name] = provider_config

tilt_helper_dockerfile_header = """
Expand Down Expand Up @@ -172,6 +176,7 @@ def enable_provider(name):
p = providers.get(name)

context = p.get("context")
go_main = p.get("go_main")

# Prefix each live reload dependency with context. For example, for if the context is
# test/infra/docker and main.go is listed as a dep, the result is test/infra/docker/main.go. This adjustment is
Expand All @@ -181,10 +186,10 @@ def enable_provider(name):
live_reload_deps.append(context + "/" + d)

# Set up a local_resource build of the provider's manager binary. The provider is expected to have a main.go in
# manager_build_path. The binary is written to .tiltbuild/manager.
# manager_build_path or the main.go must be provided via go_main option. The binary is written to .tiltbuild/manager.
local_resource(
name + "_manager",
cmd = "cd " + context + ';mkdir -p .tiltbuild;CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags \'-extldflags "-static"\' -o .tiltbuild/manager',
cmd = "cd " + context + ';mkdir -p .tiltbuild;CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags \'-extldflags "-static"\' -o .tiltbuild/manager ' + go_main,
deps = live_reload_deps,
)

Expand Down Expand Up @@ -218,15 +223,16 @@ def enable_provider(name):
],
)

# Copy all the substitutions from the user's tilt-settings.json into the environment. Otherwise, the substitutions
# are not available and their placeholders will be replaced with the empty string when we call kustomize +
# envsubst below.
substitutions = settings.get("kustomize_substitutions", {})
os.environ.update(substitutions)
if p.get("kustomize_config"):
# Copy all the substitutions from the user's tilt-settings.json into the environment. Otherwise, the substitutions
# are not available and their placeholders will be replaced with the empty string when we call kustomize +
# envsubst below.
substitutions = settings.get("kustomize_substitutions", {})
os.environ.update(substitutions)

# Apply the kustomized yaml for this provider
yaml = str(kustomize_with_envsubst(context + "/config"))
k8s_yaml(blob(yaml))
# Apply the kustomized yaml for this provider
yaml = str(kustomize_with_envsubst(context + "/config"))
k8s_yaml(blob(yaml))

# Prepull all the cert-manager images to your local environment and then load them directly into kind. This speeds up
# setup if you're repeatedly destroying and recreating your kind cluster, as it doesn't have to pull the images over
Expand Down
7 changes: 6 additions & 1 deletion docs/book/src/developer/tilt.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ base64 -i ~/path/to/gcp/credentials.json
Set to `manual` to disable auto-rebuilding and require users to trigger rebuilds of individual changed components through the UI.

**extra_args** (Object, default={}): A mapping of provider to additional arguments to pass to the main binary configured
for this provider. Each item in the array will be passed in to the manager for the given provider.
for this provider. Each item in the array will be passed in to the manager for the given provider.

Example:

Expand Down Expand Up @@ -229,6 +229,11 @@ COPY --from=tilt-helper /usr/bin/docker /usr/bin/docker
COPY --from=tilt-helper /go/kubernetes/client/bin/kubectl /usr/bin/kubectl
```

**kustomize_config** (Bool, default=true): Whether or not running kustomize on the ./config folder of the provider.
Set to `false` if your provider does not have a ./config folder or you do not want it to be applied in the cluster.

**go_main** (String, default="main.go"): The go main file if not located at the root of the folder

## Customizing Tilt

If you need to customize Tilt's behavior, you can create files in cluster-api's `tilt.d` directory. This file is ignored
Expand Down