Skip to content

Commit 2143e6a

Browse files
Adds explanation of crate2nix and tilt based development workflow to the docs (#360)
* Adds explanation of crate2nix and tilt based development workflow to the docs. For implementation, see: - stackabletech/operator-templating#212 - stackabletech/hdfs-operator#312 Co-authored-by: Natalie <[email protected]>
1 parent 372ce56 commit 2143e6a

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

antora-playbook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ content:
1919
sources:
2020
- url: https://github.com/stackabletech/documentation.git
2121
tags: []
22-
branches: [main, release/*]
22+
branches: [HEAD, release/*]
2323
# stackablectl
2424
- url: https://github.com/stackabletech/stackablectl.git
2525
start_path: docs

modules/contributor/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* xref:index.adoc[]
22
33
** xref:steps.adoc[]
4+
** xref:testing_on_kubernetes.adoc[]
45
** xref:development_dashboard.adoc[]
56
** xref:style_guide.adoc[]
67
** Implementation guidelines
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
= Testing your Code on Kubernetes
2+
3+
== Description
4+
It can sometimes be a bit cumbersome to actually test your code on Kubernetes proper, as there are many moving parts involved.
5+
You need to compile the code, build helm charts, build and push the container images, etc.
6+
7+
While we do have CI actions for this, those actions also run some tests and other checks that can take a fair bit of time and are not readily available to developers outside of the Stackable organization.
8+
Also, if you need to make changes to an operator and the framework at the same time, compiling the operator with your local version of the framework becomes very difficult in CI actions.
9+
10+
For these reasons we have created a developer focused deployment mechanism that allows for easy local development, while still enabling full-scale testing in an actual Kubernetes cluster.
11+
12+
The main tool that is used for enabling these short feedback loops is called https://tilt.dev/[Tilt].
13+
Tilt is a tool that continuously monitors your local codebase and automatically deploys any changes you make to the Kubernetes cluster defined by your current kubeconfig.
14+
15+
Effectively this means, that when you have reached a state in your code that you would like to deploy to Kubernetes to look at more in depth, all you need to do is .. nothing - it has already been built, packaged and deployed in the background.
16+
17+
A very important prerequisite for this of course is short build times!
18+
19+
To shorten these, we have settled on a tool called https://github.com/kolloch/crate2nix[crate2nix].
20+
This tool uses the https://nixos.org/[Nix package manager] to cache intermediate build steps and only recompile what has actually changed, thus significantly shortening build times.
21+
22+
== Installation
23+
Due to the nature of how Nix works, all the setup steps are defined in the operator repositories and automatically applied when you start using this workflow.
24+
25+
The only prerequisite you need to install is the actual Nix package manager - you can find installation instructions and additional documentation on the https://nixos.org/download.html[Nix website].
26+
27+
**TL/DR**
28+
[source,bash]
29+
----
30+
sh <(curl -L https://nixos.org/nix/install) --daemon
31+
----
32+
33+
After this is done you also need to add a setting to your Nix config in `/etc/nix/nix.conf`:
34+
----
35+
experimental-features = nix-command
36+
----
37+
38+
Just installing Nix does not affect your system much, as it keeps all its configuration and installed packages separate from other package managers and you won't even notice it is there, unless you actually start using it.
39+
40+
== Using
41+
42+
The build and deploy steps for installing and running the operator are defined in the `Tiltfile` in the operators repository.
43+
We do encourage you to check out this file if you are interested in how things work under the hood, but you can also just use the command provided below and everything should _just work_.
44+
For more context on how to read this file please have a look at the https://docs.tilt.dev/api.html[Tiltfile API Reference], which is based on https://github.com/bazelbuild/starlark/blob/32993fa0d1f1e4f3af167d249be95885ba5014ad/spec.md[Starlark].
45+
46+
We provide a target in the Makefile to start everything up:
47+
48+
[source,bash]
49+
----
50+
make run-dev
51+
----
52+
53+
After running this, Tilt should be up and doing its thing, in the console you'll see something similar to the following:
54+
55+
----
56+
➜ hdfs-operator git:(main) ✗ make run-dev
57+
nix run -f. tilt -- up --port 5430
58+
Tilt started on http://localhost:5430/
59+
v0.30.13, built
60+
61+
(space) to open the browser
62+
(s) to stream logs (--stream=true)
63+
(t) to open legacy terminal mode (--legacy=true)
64+
(ctrl-c) to exit
65+
----
66+
67+
You can now either hit the spacebar to open the Tilt user interface, or manually navigate to the url shown.
68+
69+
NOTE: The port used will be different for every repository from the Stackable organisation, in order to allow running multiple deployment workflows at the same time without getting port conflicts.
70+
71+
=== Configuring the Registry Used
72+
If you are using a local Kubernetes like Kind, K3s or similar for your development Tilt will work right out of the box for you, as it will directly push the images to your local Kubernetes cluster (see https://docs.tilt.dev/personal_registry.html for more information).
73+
74+
If you are using a remote cluster, Tilt will push the generated container images to a remote registry, in order for your Kubernetes to be able to access them.
75+
We have configured `docker.stackable.tech/sandbox` as the default registry, as this is what all our developers use.
76+
External contributors will not have access to this registry and need to override this to a registry of their choice.
77+
78+
Overriding the default registry can be done by providing a file called `tilt_options.json` in the same directory as the Tiltfile.
79+
80+
[source, json]
81+
----
82+
{
83+
"default_registry": "docker.stackable.tech/soenkeliebau",
84+
}
85+
----

0 commit comments

Comments
 (0)