-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathTiltfile
More file actions
144 lines (124 loc) · 6.66 KB
/
Copy pathTiltfile
File metadata and controls
144 lines (124 loc) · 6.66 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Based on https://github.com/tilt-dev/tilt-extensions/blob/master/kubebuilder/Tiltfile
load('ext://restart_process', 'docker_build_with_restart')
settings = {}
tilt_settings = "./tilt-settings.yaml" if os.path.exists("./tilt-settings.yaml") else "./tilt-settings.json"
settings.update(read_yaml(tilt_settings, default = {}))
if 'allowed_contexts' in settings:
allow_k8s_contexts(settings['allowed_contexts'])
if 'default_registry' in settings:
# Set the default registry for tilt to use
default_registry(settings['default_registry'].removesuffix('/'))
if 'feature_gates' in settings:
# Set the feature gates for the controller
feature_gates = settings['feature_gates']
else:
feature_gates = {
'vLLM': True,
'gatewayAPIInferenceExtension': True,
'disableNodeAutoProvisioning': False,
}
def main(IMG='controller:latest', DISABLE_SECURITY_CONTEXT=True):
DOCKERFILE = '''
FROM --platform=linux/amd64 mcr.microsoft.com/oss/go/microsoft/golang:1.24
WORKDIR /
COPY ./tilt_bin/manager /
COPY ./presets/workspace/models/supported_models.yaml /
CMD ["/manager"]
'''
def yaml():
cluster_name = k8s_context() if not settings.get('cluster_name') else settings['cluster_name']
node_provisioner = 'byo' if feature_gates.get('disableNodeAutoProvisioning', False) else 'azure-gpu-provisioner'
preset_registry = settings.get('preset_registry_name', 'mcr.microsoft.com/aks/kaito').removesuffix('/')
gfd_settings = settings.get('gpu_feature_discovery', {})
gfd_flags = ''
if 'enabled' in gfd_settings.get('nfd', {}):
gfd_flags += ' --set gpu-feature-discovery.nfd.enabled={}'.format(str(gfd_settings['nfd']['enabled']).lower())
if 'enabled' in gfd_settings.get('gfd', {}):
gfd_flags += ' --set gpu-feature-discovery.gfd.enabled={}'.format(str(gfd_settings['gfd']['enabled']).lower())
helm_template = 'helm template kaito-workspace ./charts/kaito/workspace --namespace kaito-workspace --set clusterName={} --set image.repository=controller --set image.tag=latest --set enableBaseImageAutoUpgrade={} --set featureGates.gatewayAPIInferenceExtension={} --set featureGates.disableNodeAutoProvisioning={} --set featureGates.enableInferenceSetController={} --set featureGates.enableMIG={} --set nodeProvisioner={} --set presetRegistryName={}'.format(cluster_name, feature_gates.get('enableBaseImageAutoUpgrade', False), feature_gates['gatewayAPIInferenceExtension'], feature_gates['disableNodeAutoProvisioning'], feature_gates.get('enableInferenceSetController', False), feature_gates.get('enableMIG', False), node_provisioner, preset_registry) + gfd_flags
# Set the image name and tag to controller:latest for Tilt to
# substitute later during docker_build_with_restart
data = local(helm_template, quiet=True)
# Tilt's live update conflicts with SecurityContext, until a better solution, just remove it
if DISABLE_SECURITY_CONTEXT:
decoded = decode_yaml_stream(data)
if decoded:
for d in decoded:
# Workaround: Force the namespace to "kaito-workspace" because `helm template` does not correctly render
# the subchart namespace. See: https://github.com/fluxcd-community/helm-charts/issues/239.
if "namespace" not in d["metadata"]:
d["metadata"]["namespace"] = "kaito-workspace"
if d["kind"] == "Deployment":
if "securityContext" in d['spec']['template']['spec']:
d['spec']['template']['spec'].pop('securityContext')
for c in d['spec']['template']['spec']['containers']:
if "securityContext" in c:
c.pop('securityContext')
return encode_yaml_stream(decoded)
return data
def make_manifests():
return 'make manifests'
def make_generate():
return 'make generate'
def create_namespace(name):
return 'kubectl create namespace {} || true'.format(name)
def manager():
return 'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o tilt_bin/manager cmd/workspace/*.go'
# Create the namespace if it doesn't exist
local(create_namespace('kaito-workspace'), quiet=True)
# Generate the CRD manifests and kubectl apply them. Re-generate if anything in deps changes.
local_resource(
'crd',
make_generate() + ' && ' + make_manifests() + ' && kubectl apply --server-side -f charts/kaito/workspace/crds --force-conflicts',
deps=['api'],
ignore=['*/*/zz_generated.deepcopy.go'],
labels='Workspace',
)
# Deploy the rendered helm chart
k8s_yaml(yaml())
# Labels resources from kaito-workspace
k8s_resource(
workload='kaito-workspace',
new_name='deployment',
labels='Workspace',
objects=['kaito-workspace-sa:serviceaccount',
'kaito-workspace-role:role',
'kaito-workspace-clusterrole:clusterrole',
'kaito-workspace-rolebinding:rolebinding',
'kaito-workspace-rolebinding:clusterrolebinding',
'inference-params-template:configmap',
'lora-params-template:configmap',
'qlora-params-template:configmap',
'workspace-webhook-cert:secret',
'validation.workspace.kaito.sh:validatingwebhookconfiguration',
],
)
k8s_resource(
workload='nvidia-device-plugin-daemonset',
new_name='device plugin',
labels='Dependencies',
)
# Re-compile the manager binary when anything in deps changes.
local_resource(
'manager',
manager(),
deps=['api', 'cmd', 'pkg', 'presets'],
ignore=['*/*/zz_generated.deepcopy.go'],
labels='Workspace',
)
# Build the initial controller image. When a newer manager binary is built,
# Tilt will replace the old one in the running container with the new one.
node_provisioner = 'byo' if feature_gates.get('disableNodeAutoProvisioning', False) else 'azure-gpu-provisioner'
docker_build_with_restart(IMG, '.',
dockerfile_contents=DOCKERFILE,
entrypoint='/manager --feature-gates={} --node-provisioner={}'.format(
','.join(['{}={}'.format(k, str(v).lower()) for k, v in feature_gates.items()]),
node_provisioner
),
only=['./tilt_bin/manager', './presets/workspace/models/supported_models.yaml'],
live_update=[
sync('./tilt_bin/manager', '/manager'),
sync('./presets/workspace/models/supported_models.yaml', '/supported_models.yaml'),
]
)
main()