Skip to content
naisPublic

About

Nais API

Resources

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

2,338 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nais API

Nais API is the main entrypoint when interacting with the API of the Nais platform.

Local development

mise install # Install required dependencies
cp .env.example .env # Copy example configuration file, and adjust to your needs
docker compose up -d
make setup-local # Setup local environment (seeds database and creates pubsub topic)
make local

For local development various services are faked. This is controlled by multiple WITH_* environment variables in the .env file. If WITH_INSECURE_USER_HEADER is set, you will also need to set the X-User-Email header to dev.usersen@example.com if you want to act as a regular user, or admin.usersen@example.com if you need an admin user, when interacting with the GraphQL API.

Locally, most external services are replaced with fake clients, and the Kubernetes client reads data from data/k8s.

The test suite uses testcontainers, and if you are using Colima you might need to follow the guidelines in the testcontainers documentation.

Local development of logging API

To develop the logging API with real data:

TENANT_NAME="example.com"
nais login
narc jita grant k8s-admin "$TENANT_NAME" --duration 1h --reason "port forward for loki local testing"
CONTEXT="dev" WITH_LOG_PROXY="true" mise run local|debug

Kafka environments

KAFKA_ENVIRONMENTS maps canonical Nais environment names to Kafka pools and optional legacy aliases. Temporary credentials are created in the selected canonical environment, using the existing cluster-name mapping. For example, for Nav:

{
	"dev-gcp": {
		"pool": "nav-dev",
		"aliases": ["dev"]
	},
	"prod-gcp": {
		"pool": "nav-prod",
		"aliases": ["prod"]
	}
}

The Helm value is the JSON string kafka.environments. For ordinary tenant environments, Fasit generates a mapping when both aiven_project and kafka_bootstrap_broker are configured. The pool is the configured Aiven project, and credentials are created in the same Nais environment, without aliases. Nav retains the explicit legacy mappings above.

Non-standard topologies can configure an explicit mapping. A direct Helm installation must also supply this value. An empty mapping disables Kafka credential creation, not other Kafka operations.

The canonical environment must refer to a configured Kubernetes cluster through the existing environment-name mapping. Aliases cannot collide with canonical Nais environments or other aliases. Pool names are never inferred from environment names or the tenant name. An environment without a mapping is rejected before creating any resources. Selecting a shared pool does not route credential creation to another cluster. There is no routing from FSS to GCP.

Existing clients can keep using configured aliases. The additive CreateKafkaCredentialsPayload.environmentName field returns the canonical name, allowing newer clients to warn about legacy aliases without duplicating this configuration. Activity log entries use the canonical name.

Development practices

Check practices used in this project here: docs/practices.md

Adding a product-specific relay access mutation

Follow the shared relay integration requirements and fill in the integration template in the product's design or rollout documentation. A new access must be requested through an authenticated, product-specific NAIS API mutation; document its authorization, target selection and owner-only delivery before enabling it.

Graph-API

We have defined a set of practices for the Graph-API in the docs/graphql_practices.md file.

Fake clients

We have a set of fake clients, and stubs, that can be used for local development. One of the clients is a fake Kubernetes client that read data from data/k8s. You can read more about how the fake clients works in the data/k8s/README.md file.

Integration tests

We are using tester for integration tests. These tests are written in Lua and can be found in the integration_tests directory.

A spec file is generated to support auto-completion using the Lua language server.

When running make test the integration tests will be run as part of the test suite. If you only want to run the integration tests, and get information about coverage, you can run make integration-test.

To run the integration tests in watch mode, run make integration_test_ui. This will start a web server on localhost:9876 where you can see the test results. They will be re-run every time you save a .lua file.

Architecture

graph TD
  API --> Postgres[(psql)]
  Service[Nais Service] --> |GRPC|API
  Clients[External Clients] --> |GraphQL|API
  API -.-> PubSub{PubSub}

  subgraph ext [External data]
    API --> K8s([Kubernetes])
    API --> Prom([Prometheus])
    API --> GA([Google Admin])
    API --> BQ([BigQuery])
  end
Loading
Component Description
API This service
Postgres The postgres database storing state from this application
Nais Service Services by Nais that requires special communication with API. E.g. Reconcilers and Deploy
External Clients External clients that communicates with the API. E.g. Browsers and NADA
Kubernetes The Kubernetes clusters of the tenant
PubSub The PubSub topic used for communication between the API and the Nais Service
Prometheus We collect historic data from the tenants prometheus
Google Admin We use the Google Admin API to manage a list of users
BigQuery We collect historic cost data from BigQuery

Code generated by GitHub Copilot

This repository uses GitHub Copilot to generate code.

About

Nais API

Resources

Stars

3 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages