|
| 1 | +# -*- mode: Python -*- |
| 2 | + |
| 3 | +tilt_settings_file = "./tilt-settings.yaml" |
| 4 | +settings = read_yaml(tilt_settings_file) |
| 5 | + |
| 6 | +kubectl_cmd = "kubectl" |
| 7 | + |
| 8 | +# verify kubectl command exists |
| 9 | +if str(local("command -v " + kubectl_cmd + " || true", quiet = True)) == "": |
| 10 | + fail("Required command '" + kubectl_cmd + "' not found in PATH") |
| 11 | + |
| 12 | +# Create the kwasm namespace |
| 13 | +# This is required since the helm() function doesn't support the create_namespace flag |
| 14 | +load('ext://namespace', 'namespace_create') |
| 15 | +namespace_create('kwasm') |
| 16 | + |
| 17 | +# Install kwasm-operator helm chart |
| 18 | +install = helm( |
| 19 | + './charts/kwasm-operator/', |
| 20 | + name='kwasm-operator', |
| 21 | + namespace='kwasm', |
| 22 | + set=['image.repository=' + settings.get('registry')] |
| 23 | +) |
| 24 | + |
| 25 | +objects = decode_yaml_stream(install) |
| 26 | +for o in objects: |
| 27 | + # Update the root security group. Tilt requires root access to update the |
| 28 | + # running process. |
| 29 | + if o.get('kind') == 'Deployment' and o.get('metadata').get('name') == 'kwasm-operator': |
| 30 | + o['spec']['template']['spec']['securityContext']['runAsNonRoot'] = False |
| 31 | + # Disable the leader election to speed up the startup time. |
| 32 | + o['spec']['template']['spec']['containers'][0]['args'].remove('--leader-elect') |
| 33 | + break |
| 34 | +updated_install = encode_yaml_stream(objects) |
| 35 | +k8s_yaml(updated_install) |
| 36 | + |
| 37 | +# enable hot reloading by doing the following: |
| 38 | +# - locally build the whole project |
| 39 | +# - create a docker imagine using tilt's hot-swap wrapper |
| 40 | +# - push that container to the local tilt registry |
| 41 | +# Once done, rebuilding now should be a lot faster since only the relevant |
| 42 | +# binary is rebuilt and the hot swat wrapper takes care of the rest. |
| 43 | +local_resource( |
| 44 | + 'manager', |
| 45 | + "CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/manager ./", |
| 46 | + deps = [ |
| 47 | + "main.go", |
| 48 | + "go.mod", |
| 49 | + "go.sum", |
| 50 | + "controllers", |
| 51 | + ], |
| 52 | +) |
| 53 | + |
| 54 | +# Build the docker image for our controller. We use a specific Dockerfile |
| 55 | +# since tilt can't run on a scratch container. |
| 56 | +entrypoint = ['/manager', '-zap-devel'] |
| 57 | +dockerfile = 'tilt.dockerfile' |
| 58 | + |
| 59 | +load('ext://restart_process', 'docker_build_with_restart') |
| 60 | +docker_build_with_restart( |
| 61 | + settings.get('registry'), |
| 62 | + '.', |
| 63 | + dockerfile = dockerfile, |
| 64 | + entrypoint = entrypoint, |
| 65 | + # `only` here is important, otherwise, the container will get updated |
| 66 | + # on _any_ file change. |
| 67 | + only=[ |
| 68 | + './bin', |
| 69 | + ], |
| 70 | + live_update = [ |
| 71 | + sync('./bin/manager', '/manager'), |
| 72 | + ], |
| 73 | +) |
| 74 | + |
0 commit comments