Skip to main content

Backend

Headlamp's backend is written in Go. It is in charge of redirecting client requests to the right clusters and returning any available plugins for the client to use.

The backend's most essential function is to read the cluster information from the given configuration and set up proxies to the defined clusters as well as endpoints to them. This means that instead of having a set of endpoints related to the functionality available to the client, it simply redirects the requests to the defined proxies.

Building and running

The backend (Headlamp's server) can be quickly built using:

npm run backend:build

Once built, it can be run in development mode (insecure / don't use in production) using:

npm run backend:start

Lint

To lint the backend/ code.

npm run backend:lint

This command can fix some lint issues.

npm run backend:lint:fix

Format

To format the backend code.

npm run backend:format

Test

npm run backend:test

Test coverage with a html report in the browser.

npm run backend:coverage:html

To just print a simpler coverage report to the console.

npm run backend:coverage

Fuzz Testing

Some backend functions include fuzz tests using Go's native fuzzing support. For example, the SanitizeClusterName function in backend/pkg/auth has a fuzz test.

To run fuzz tests:

npm run backend:fuzz

This will run fuzz tests in the backend/pkg/auth package for 30 seconds. The fuzz corpus (interesting test cases discovered during fuzzing) is stored in testdata/fuzz/ directories and committed to the repository for regression testing.

For more information about Go fuzzing, see the official Go fuzzing documentation.