-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from flavio/tilt
Introduce Tilt to simplify the development process
- Loading branch information
Showing
7 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
tilt-settings.yaml | ||
|
||
# Binaries for programs and plugins | ||
*.exe | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Contributing | ||
|
||
## Building | ||
|
||
Pre-requisites: | ||
|
||
- make | ||
- Go compiler | ||
|
||
To build the controller use the following command: | ||
|
||
```console | ||
make all | ||
``` | ||
|
||
To run the unit tests: | ||
|
||
```console | ||
make test | ||
``` | ||
|
||
## Development | ||
|
||
To run the controller for development purposes, you can use [Tilt](https://tilt.dev/). | ||
|
||
### Pre-requisites | ||
|
||
Please follow the [Tilt installation documentation](https://docs.tilt.dev/install.html) to install the command line tool. | ||
|
||
A development Kubernetes cluster is needed to run the controller. | ||
You can use [k3d](https://k3d.io/) to create a local cluster for development purposes. | ||
|
||
### Settings | ||
|
||
The `tilt-settings.yaml.example` acts as a template for the `tilt-settings.yaml` file that you need to create in the root of this repository. | ||
Copy the example file and edit it to match your environment. | ||
The `tilt-settings.yaml` file is ignored by git, so you can safely edit it without worrying about committing it by mistake. | ||
|
||
The following settings can be configured: | ||
|
||
- `registry`: the container registry where the controller image will be pushed. | ||
If you don't have a private registry, you can use `ghcr.io` as long as your | ||
cluster has access to it. | ||
|
||
Example: | ||
|
||
```yaml | ||
registry: ghcr.io/your-gh-username/kwasm-operator | ||
``` | ||
### Running the controller | ||
The `Tiltfile` included in this repository will take care of the following: | ||
|
||
- Create the `kwasm` namespace and install the controller helm-chart in it. | ||
- Inject the development image in the deployment. | ||
- Automatically reload the controller when you make changes to the code. | ||
|
||
To run the controller, you just need to run the following command against an empty cluster: | ||
|
||
```console | ||
$ tilt up --stream | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- mode: Python -*- | ||
|
||
tilt_settings_file = "./tilt-settings.yaml" | ||
settings = read_yaml(tilt_settings_file) | ||
|
||
kubectl_cmd = "kubectl" | ||
|
||
# verify kubectl command exists | ||
if str(local("command -v " + kubectl_cmd + " || true", quiet = True)) == "": | ||
fail("Required command '" + kubectl_cmd + "' not found in PATH") | ||
|
||
# Create the kwasm namespace | ||
# This is required since the helm() function doesn't support the create_namespace flag | ||
load('ext://namespace', 'namespace_create') | ||
namespace_create('kwasm') | ||
|
||
# Install kwasm-operator helm chart | ||
install = helm( | ||
'./charts/kwasm-operator/', | ||
name='kwasm-operator', | ||
namespace='kwasm', | ||
set=['image.repository=' + settings.get('registry')] | ||
) | ||
|
||
objects = decode_yaml_stream(install) | ||
for o in objects: | ||
# Update the root security group. Tilt requires root access to update the | ||
# running process. | ||
if o.get('kind') == 'Deployment' and o.get('metadata').get('name') == 'kwasm-operator': | ||
o['spec']['template']['spec']['securityContext']['runAsNonRoot'] = False | ||
# Disable the leader election to speed up the startup time. | ||
o['spec']['template']['spec']['containers'][0]['args'].remove('--leader-elect') | ||
break | ||
updated_install = encode_yaml_stream(objects) | ||
k8s_yaml(updated_install) | ||
|
||
# enable hot reloading by doing the following: | ||
# - locally build the whole project | ||
# - create a docker imagine using tilt's hot-swap wrapper | ||
# - push that container to the local tilt registry | ||
# Once done, rebuilding now should be a lot faster since only the relevant | ||
# binary is rebuilt and the hot swat wrapper takes care of the rest. | ||
local_resource( | ||
'manager', | ||
"CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/manager ./", | ||
deps = [ | ||
"main.go", | ||
"go.mod", | ||
"go.sum", | ||
"controllers", | ||
], | ||
) | ||
|
||
# Build the docker image for our controller. We use a specific Dockerfile | ||
# since tilt can't run on a scratch container. | ||
entrypoint = ['/manager', '-zap-devel'] | ||
dockerfile = 'tilt.dockerfile' | ||
|
||
load('ext://restart_process', 'docker_build_with_restart') | ||
docker_build_with_restart( | ||
settings.get('registry'), | ||
'.', | ||
dockerfile = dockerfile, | ||
entrypoint = entrypoint, | ||
# `only` here is important, otherwise, the container will get updated | ||
# on _any_ file change. | ||
only=[ | ||
'./bin', | ||
], | ||
live_update = [ | ||
sync('./bin/manager', '/manager'), | ||
], | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Replace with a development registry that offers pull & push access | ||
registry: ghcr.io/<your github handle>/kwasm-operator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM alpine | ||
WORKDIR / | ||
COPY ./bin/manager /manager | ||
|
||
ENTRYPOINT ["/manager"] |