-
Notifications
You must be signed in to change notification settings - Fork 165
/
Tiltfile
111 lines (93 loc) · 3.85 KB
/
Tiltfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- mode: Python -*-
version_settings(constraint='>=0.23.0')
# knative-serving namespace takes around 4 minutes finish terminating
update_settings(k8s_upsert_timeout_secs=300)
# Configuration for all knative CRDs.
k8s_kind('Service', api_version='serving.knative.dev/v1',
image_json_path='{.spec.template.spec.containers[*].image}')
def knative_install(version="v1.0.0"):
"""
Installs the knative operators into your cluster.
Auto-configures knative to use any local dev registries.
"""
delete_crds_cmd = [
"kubectl", "delete", "--ignore-not-found",
"-f", "https://github.com/knative/serving/releases/download/knative-%s/serving-crds.yaml" % version
]
k8s_custom_deploy(
'knative-crds',
deps=[],
apply_cmd="""
set -e
kubectl apply -f https://github.com/knative/serving/releases/download/knative-%s/serving-crds.yaml -o yaml
kubectl wait --for=condition=Established crd -l=knative.dev/crd-install=true 1>&2
""" % version,
delete_cmd=delete_crds_cmd
)
k8s_resource(
'knative-crds',
labels=['knative'],
pod_readiness='ignore')
# TODO(nick): Once the registry is in the Tilt API,
# we should read that here and use it to set knative configuration.
patch_registry_cmd="""
REGISTRY=$(kubectl get configmap -n kube-public local-registry-hosting -o=jsonpath='{.data.localRegistryHosting\\.v1}' | grep "host:" | sed 's/ *host: *//' | tr -d '"')
if [ "$REGISTRY" != "" ]; then
kubectl patch configmap/config-deployment \
--namespace knative-serving \
--type merge \
--patch "{\\"data\\":{\\"registries-skipping-tag-resolving\\": \\"kind.local,ko.local,dev.local,$REGISTRY\\"}}" 1>&2
fi
"""
# knative installs a webhook. If you try to create resources in the cluster
# while the webhook is being installed, everything will explode.
webhook_wait_cmd="""
kubectl wait --for=condition=Ready pods -n knative-serving -l=app.kubernetes.io/name=webhook 1>&2
"""
delete_core_cmd = [
"kubectl", "delete", "--ignore-not-found",
# Kubernetes is prone to deadlocks when you delete CRDs and namespaces at the same time:
# - The Namespace controller thinks it's responsible for deleting all resources in its namespace.
# - The CRD controller deletes the API routes for deleting resources.
# So the namespace controller blocks and eventually times out.
#
# To prevent this from slowing down 'tilt down', we do a --wait=false when deleting
# CRDs+Namespaces together.
"--wait=false",
"-f", "https://github.com/knative/serving/releases/download/knative-%s/serving-core.yaml" % version
]
k8s_custom_deploy(
'knative-core',
deps=[],
apply_cmd="""
set -ex
kubectl apply -f https://github.com/knative/serving/releases/download/knative-%s/serving-core.yaml -o yaml
set +e
""" % version + webhook_wait_cmd + patch_registry_cmd,
delete_cmd=delete_core_cmd)
k8s_resource(
'knative-core',
labels=['knative'],
resource_deps=['knative-crds'])
def knative_yaml(file_name):
"""Registers a Knative Serving resource for development.
Auto-configures the resource with min availability=1,
so that it will always be available for live updates.
"""
# Inject minScale annotation and add dependency on knative-core.
# Also adds dependencies on knative-core.
stream = read_yaml_stream(file_name)
for o in stream:
if o.get('apiVersion', '').startswith('serving.knative.dev') and o.get('kind', '') == "Service":
spec = o.get('spec', {})
tmpl = spec.get('template', {})
if 'metadata' not in tmpl:
tmpl['metadata'] = {}
metadata = tmpl['metadata']
if 'annotations' not in metadata:
metadata['annotations'] = {}
metadata['annotations']['autoscaling.knative.dev/minScale'] = "1"
name = o.get('metadata', {}).get('name', '')
if name:
k8s_resource(name, resource_deps=['knative-core'])
k8s_yaml(encode_yaml_stream(stream))