Skip to content

Commit cb5f429

Browse files
Protect well know registry from accidental push during tilt up
1 parent 9a6b99b commit cb5f429

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Tiltfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ os_arch = str(local("go env GOARCH")).rstrip("\n")
4242
if settings.get("trigger_mode") == "manual":
4343
trigger_mode(TRIGGER_MODE_MANUAL)
4444

45-
if settings.get("default_registry") != "":
45+
usingLocalRegistry = str(local(kubectl_cmd + " get cm -n kube-public local-registry-hosting || true", quiet = True))
46+
if not usingLocalRegistry:
47+
if settings.get("default_registry", "") == "":
48+
fail("default_registry is required when not using a local registry, please add it to your tilt-settings.yaml/json")
49+
50+
protectedRegistries = ["gcr.io/k8s-staging-cluster-api"]
51+
if settings.get("default_registry") in protectedRegistries:
52+
fail("current default_registry '{}' is protected, tilt cannot push images to it. Please select another default_registry in your tilt-settings.yaml/json".format(settings.get("default_registry")))
53+
54+
if settings.get("default_registry", "") != "":
4655
default_registry(settings.get("default_registry"))
4756

4857
always_enable_providers = ["core"]

docs/book/src/developer/tilt.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ If you prefer JSON, you can create a `tilt-settings.json` file instead. YAML wil
6969
**allowed_contexts** (Array, default=[]): A list of kubeconfig contexts Tilt is allowed to use. See the Tilt documentation on
7070
[allow_k8s_contexts](https://docs.tilt.dev/api.html#api.allow_k8s_contexts) for more details.
7171

72-
**default_registry** (String, default=""): The image registry to use if you need to push images. See the [Tilt
72+
**default_registry** (String, default=[]): The image registry to use if you need to push images. See the [Tilt
7373
documentation](https://docs.tilt.dev/api.html#api.default_registry) for more details.
74+
Please note that, in case you are not using a local registry, this value is required; additionally, the Cluster API
75+
Tiltfile protects you from accidental push on `gcr.io/k8s-staging-cluster-api`.
7476

7577
**build_engine** (String, default="docker"): The engine used to build images. Can either be `docker` or `podman`.
7678
NB: the default is dynamic and will be "podman" if the string "Podman Engine" is found in `docker version` (or in `podman version` if the command fails).

0 commit comments

Comments
 (0)