Skip to content
Development

Development

Repository layout

kornercode/
├── config/helm/                 The single `kornercode` Helm chart (operator and gateway); CRDs and RBAC are generated
├── operator/                    Operator
│   ├── api/v1alpha1/            CRD types (Workspace, WorkspaceProfile, Team, SecurityProfile)
│   ├── api/v1alpha1/validation/ Validation rules shared with the gateway
│   ├── cmd/controllers/kornercode/ Entry point
│   ├── internal/controllers/    Workspace and Team reconcilers
│   ├── internal/webhook/        Admission webhooks
│   └── test/e2e/                End-to-end tests (in a vcluster on korner-kind)
├── gateway/                     Gateway
│   ├── main.go
│   ├── internal/                Server, API, admin, proxies, auth, services
│   ├── web/                     Dashboard (embedded)
│   └── webtest/                 Dashboard unit tests (Node)
├── hack/                        Local environment, demo data, documentation tooling
└── site/                        Documentation site (Hugo, Hextra theme as a submodule)
    ├── content/docs/            The pages, in Markdown
    └── static/images/           Screenshots

Both binaries come from one Go module, gitlab.com/kornercloud.dev/kornercode.

Prerequisites

  • Go (the version in go.mod)
  • Docker, kind, kubectl and Helm for the local environment
  • Node.js 18 or later for the dashboard unit tests

Tools such as controller-gen, golangci-lint, setup-envtest and crdoc are downloaded into bin/ by the Makefile on first use.

Building and testing

CommandWhat it does
make buildBuild the operator and gateway binaries into dist/
make imagesBuild both container images
make testGenerate code and manifests, then run all Go tests (unit tests and envtest suites)
make test-webRun the dashboard unit tests (node --test gateway/webtest/*.test.js)
make lintRun golangci-lint
make test-e2e-localRun the end-to-end suite in a vcluster on korner-kind; see End-to-end tests
make helpList every target

make deploy installs the kornercode chart into the current cluster with the operator only (--set gateway.replicaCount=0 --set gateway.ingress.enabled=false): the gateway cannot run without hosts and OIDC.

The operator’s step and controller tests use envtest (a real API server, no kubelet). Gateway tests use the controller-runtime fake client and httptest. Logic in the dashboard is kept in gateway/web/js/lib/ as plain functions so it can be tested without a browser.

End-to-end tests

The suite in operator/test/e2e/ installs kornercode as an administrator would and uses it as people do: it signs in through Keycloak, creates, opens, restarts and deletes a workspace from the dashboard API, and checks expiry, home volume adoption, team network isolation and the client certificate gate, on and off.

It runs in a vcluster on the shared korner-kind cluster, never on a cluster of its own: the suite installs CRDs, webhooks, cert-manager and Keycloak, and refuses to start unless every node of the cluster it is given is a vcluster’s. korner-kind publishes the vcluster chart and its values in the ConfigMap vcluster of the gitlab-runner namespace, which hack/e2e/vcluster.sh reads.

make test-e2e-local                 # build, load the images, run, delete the vcluster
make test-e2e-local E2E_KEEP=true   # keep the vcluster to look around afterwards
KUBECONFIG=bin/e2e.kubeconfig kubectl get workspaces -A
hack/e2e/vcluster.sh down e2e-local

test-e2e-local builds both images tagged e2e-local, loads them into korner-kind with kind load, creates the vcluster e2e-local in the namespace kornercode-e2e and runs make test-e2e against it. The vcluster’s API is reached through korner-kind’s Traefik on 127.0.0.1:8443. To run part of the suite against a kept vcluster, call go test with a Ginkgo focus:

KUBECONFIG=bin/e2e.kubeconfig HELM=$PWD/bin/helm E2E_IMAGE_TAG=e2e-local \
  go test -tags e2e ./operator/test/e2e/ -v -ginkgo.v -ginkgo.focus "client-certificate gate"

The workspace image is the released common image of kornercode-images; set E2E_WORKSPACE_IMAGE for another one, such as kornercode-workspace:common-latest built by local dev. Rerunning against a kept vcluster upgrades what is already there.

The GPU case runs only with E2E_GPU=true, on a korner-kind cluster with its WSL GPU support: it mounts the driver from the node with a hostPath, which the CI namespaces refuse. The vcluster’s nodes do not show the host’s GPUs; without one, the workspace stays Pending and the case fails.

CI sets E2E_HOST_NAMESPACE_OPEN=true. korner-kind lets the pods of its CI vcluster namespace reach each other, and network policies add up, so a team’s policy cannot keep the suite’s probe pod out there. CI still checks that the policy is in the team’s namespace and selects the workspace; the connection itself is refused only in local runs.

Code generation

Generated files are never edited by hand; change the source and regenerate.

After changingRun
CRD types (operator/api/v1alpha1/*_types.go)make generate manifests docs
Kubebuilder markers (// +kubebuilder:..., including RBAC)make manifests
Operator command-line flagsmake docs
go.modmake mod

Generated outputs: operator/api/v1alpha1/zz_generated.deepcopy.go, config/helm/templates/crds/, config/helm/templates/rbac/role.yaml and the pages under site/content/docs/reference/. CI runs make docs-verify, which fails when they are out of date.

Local environment

hack/local-dev/bootstrap.sh deploys the complete stack on a local Kind cluster: Traefik, cert-manager, Keycloak with test users, the operator, the gateway and, optionally, Prometheus. The cluster itself is created by korner-kind (korner-kind up).

# once: hostnames used by the browser and by the Keycloak setup script
echo "127.0.0.1 dashboard.kornercode.local dev.kornercode.local test.kornercode.local keycloak.kornercode.local" | sudo tee -a /etc/hosts

cp hack/local-dev/.env.local-dev.example hack/local-dev/.env.local-dev   # set OIDC_CLIENT_SECRET and SESSION_SECRET
make local-dev ARGS="--prometheus"

Then open https://dashboard.kornercode.local:8443 and sign in as alice / alice123 (user) or erin / erin123 (administrator). Re-running make local-dev rebuilds the images and restarts the deployments. hack/local-dev/README.md documents every flag, the test users and troubleshooting.

To try the client-certificate gate and break-glass login, add --client-certs (on every re-run): make local-dev ARGS="--prometheus --client-certs". It generates a test company PKI under hack/local-dev/.client-certs/ with a certificate for every Keycloak test user (CN = username, password kornercode), plus stranger.p12 (no Keycloak user); dave.p12 is revoked. It serves the CRL in the cluster, issues the TLS certificate for the three hosts and maps erin and dave for break-glass. Import your user’s .p12 into the browser and sign in as that user; no extra hosts entry is needed. The local-dev README has the details, including how to simulate an identity-provider outage.

The profiles in hack/local-dev/workspace-profiles.yaml use the kornercode-workspace:<flavor>-latest images built from the sibling kornercode-images repository. They are built FROM codercom/code-server and run as its coder user under the operator’s default security context, with a single home volume at /home/coder; any other image that follows the same contract can be tried by pointing a profile at it (see Image requirements).

For demonstrations, hack/demo/seed.py creates up to 50 demo users and workspaces across teams and profiles, and hack/demo/cleanup.py removes exactly those.

Documentation screenshots

The screenshots in site/static/images are produced by hack/docs/screenshots.py against the local environment. Regenerate them after a visible change to the dashboard; see the script’s header for the steps.

Dashboard theme

Every colour of the dashboard is a token in the :root block of gateway/web/css/app.css: the kornercloud ink surfaces and indigo accent, with text and status colours that reach WCAG AA (4.5:1) on every surface. gateway/webtest/theme.test.js (in make test-web) checks the ratios and fails on a colour written outside the tokens. The logo and favicon are in gateway/web/img. The certificate refusal page cannot load them, so it carries the logo inline; a test keeps that copy identical to the file.

Documentation site

The pages are published to https://code.kornercloud.dev with Hugo (extended, 0.166.0) and the Hextra theme, a submodule pinned to a release. Link pages to each other with relative .md paths, so they also work on GitLab. The logo and favicon come from gateway/web/img, mounted at /img. To preview:

git submodule update --init
cd site && hugo server

make docs-site builds the site into public/ and checks every internal link.

Conventions

  • Commit messages follow Conventional Commits (feat(gateway): ..., fix(operator): ..., docs: ...).
  • Every Go file carries the Apache 2.0 license header.
  • New behavior comes with tests; a bug fix comes with a test that fails without it.
  • Design decisions with lasting consequences are recorded as ADRs.

See CONTRIBUTING.md for the merge request process.