# How the modules split the work

Know which module or chart does each part of the installation, and what must exist before it runs.

The installation of Platforma in a Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) cluster is split by rights. A person with cluster admin rights prepares the cluster one time. Then the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) installs and updates with rights in its namespace only. The modules and the charts do not build the infrastructure: they expect it, and the company builds it with its own tools and standards.

The modules are infrastructure-agnostic: they work in each Kubernetes cluster that meets the contract, in a cloud or in the infrastructure of your company.

## The packages

MiLaboratories gives the Backend for Kubernetes in four packages that do not depend on the infrastructure, and you take a published version of each:

- **`platforma-tf-services-cluster`** (Terraform module): the part of Platforma that is common to the whole cluster. It creates the namespaces of Platforma, installs Kueue (A Kubernetes add-on that holds jobs in a queue until the cluster has free CPU, memory and GPU for them.) and AppWrapper (A Kubernetes add-on that wraps the pods of one job into a single unit, so that Kueue admits and starts them together.), and creates the job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.) queues with their quotas and priorities. It needs cluster admin rights.
- **`platforma-tf-services`** (Terraform module): the Backend in one namespace. The role `admin` in that namespace is enough.
- **`platforma-backend`** (Helm chart): the Backend itself.
- **`appwrapper`** (Helm chart): the AppWrapper controller and its CRD, in a build of MiLaboratories.

One version of `platforma-tf-services-cluster` pins the versions of Kueue and AppWrapper, and one version of `platforma-tf-services` pins the version of the chart `platforma-backend`. For mirrors of these versions, see [Registries and mirrors](/infrastructure-contract-identity/#registries-and-mirrors). For how to change a version, see [Upgrade Platforma](/maintain-upgrading/).

## The contract: inputs and outputs of the modules

For the modules, the contract is their inputs and outputs: what one step gives to the next one. The values describe the infrastructure that exists. They do not create it.

| Value                             | Module                                                                      | What it holds                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Where it comes from                                                                                                                                                                                   |
| --------------------------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Input `cluster_config`            | `platforma-tf-services-cluster`                                             | The contract version, the namespaces of Platforma, the node pools (`backend`, `ui`, `batch`, optional `gpu`), the autoscaling, and `cloud_values`: the ServiceAccounts, the entry points (The way in to the Backend from outside the cluster, a load balancer or an Ingress with a DNS name. It usually ends TLS and sends the traffic to the Backend pod.), the volumes, the primary storage (The bucket (Amazon S3 or Google Cloud Storage) or folder where Platforma keeps all results and uploaded files.), the registries, the CA bundle (One PEM file with the certificate authorities that a program trusts. In Kubernetes, Platforma can give the Backend and all jobs one bundle with the public and the corporate certificate authorities.) and the user of the pods | The operator (The person who installs and runs Platforma in your company, for example an IT engineer or a bioinformatician.) writes it by hand as JSON, or a cloud module of MiLaboratories writes it |
| Input `components` (optional)     | `platforma-tf-services-cluster`                                             | What the module installs (Kueue, AppWrapper, the queues), and the sources of the charts and images                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | The operator                                                                                                                                                                                          |
| Output and input `infrastructure` | Output of `platforma-tf-services-cluster`, input of `platforma-tf-services` | All that the Backend must know about the cluster (see [The hand-off file](#the-hand-off-file))                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | `terraform output -json infrastructure`, or the operator writes it by hand                                                                                                                            |
| Input `backend_service`           | `platforma-tf-services`                                                     | The values of the administrator, such as the sign-in (To show the Backend who you are, with a sign-in provider or a single-user token. The verb is "sign in"; the noun and the adjective are "sign-in".) and the references to the Secrets. They are not part of the infrastructure                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | The operator                                                                                                                                                                                          |

The types, the defaults and the checks of each input are in `inputs/variables.tf` of each module. The source repository of the modules has a sample `cluster_config` for a cluster that exists already, with a sample root that applies it. For the full list of inputs, see [Terraform modules](/reference-terraform-modules/).

## The roots

The roots are not a required structure. They are the reference setup: how MiLaboratories shapes the installation when it builds the infrastructure in a cloud. Any setup that gives the modules the same inputs is correct: one root, a pipeline of the company, or values written by hand.

In the reference setup, Terraform applies the modules in three roots, each with its own state, from left to right.

```mermaid
flowchart LR
  subgraph company["Built by the company (in a cloud or in its own data center), or by the cloud-specific modules"]
    parts["Cluster, node pools, StorageClasses,<br/>entry point, identities"]
  end
  cfg[/"cluster_config<br/>(hand-off file: JSON by hand,<br/>or from a cloud module)"/]
  subgraph cluster["Reference root cluster: cluster admin rights"]
    sc["platforma-tf-services-cluster"]
    kueue["Kueue"]
    aw["AppWrapper chart"]
    ns["Namespace and queues"]
  end
  infra[/"infrastructure<br/>(hand-off file)"/]
  hand["infrastructure written by hand,<br/>without platforma-tf-services-cluster"]
  secrets["Secrets: license,<br/>master secret, sign-in"]
  subgraph services["Reference root services: rights in one namespace"]
    svc["platforma-tf-services"]
    be["Chart platforma-backend"]
  end
  parts --> cfg --> sc
  sc --> kueue
  sc --> aw
  sc --> ns
  sc --> infra --> svc
  hand -.-> infra
  secrets --> svc
  svc --> be
  classDef handoff stroke-width:2px
  class cfg,infra handoff
  classDef optional stroke-dasharray: 5 5
  class hand optional
```

**Diagram:** The company builds the cluster with its node pools, StorageClasses, entry point and identities, in a cloud or in its own data center, or the cloud-specific Terraform modules build them. The hand-off file cluster_config goes from this part to the cluster root. It describes the parts of the cluster. The operator writes it by hand as JSON, or a cloud module writes it. The module platforma-tf-services-cluster reads cluster_config. With cluster admin rights, this module installs Kueue and the AppWrapper chart, and creates the namespace and the job queues. It writes the hand-off file infrastructure, which goes from the cluster root to the services root. The operator can also write infrastructure by hand, without platforma-tf-services-cluster. The module platforma-tf-services reads infrastructure and the references to the Secrets that the operator made, and installs the chart platforma-backend with rights in one namespace only. The roots cluster and services are the reference setup of MiLaboratories, not a required structure: the contract is the inputs and outputs of the modules.

- **Root `cloud`** makes the network, the cluster, the node pools, the storage and the entry point. For AWS and Google Cloud, MiLaboratories publishes reference cloud-specific Terraform modules (The Terraform modules platforma-tf-cloud-base and platforma-tf-cloud-cluster. There is one pair for each cloud, AWS and Google Cloud. The roots cloud and cluster apply them. They make the network, the Kubernetes cluster, the storage, the cloud identities and the registry caches. They give the hand-off file cluster_config to the cloud-agnostic Terraform modules.) for it. For a cluster that exists already, in a cloud or in the infrastructure of your company, the company does this part with its own tools.
- **Root `cluster`** runs `platforma-tf-services-cluster`. In AWS and Google Cloud, the cloud module `platforma-tf-cloud-cluster` runs first and writes `cluster_config`. For any other cluster, the operator writes `cluster_config` by hand as JSON. The root writes the output `infrastructure` to the hand-off file `infrastructure.json`.
- **Root `services`** reads `infrastructure.json` and runs `platforma-tf-services`, which installs the Backend.

Platforma also supports an installation without Terraform: the company installs the Helm charts with `helm`, and gives the chart `platforma-backend` the values that `infrastructure` would give.

## The Helm charts

The modules install these charts:

- **`kueue`** (Kueue) comes from the OCI repository `registry.k8s.io/kueue/charts`.
- **`appwrapper`** (AppWrapper) comes from MiLaboratories, as a patched build.
- **`platforma-backend`** (the Backend) comes from MiLaboratories.

**`platforma-backend`** creates objects only in the namespace of its release: the Backend, its volume claims, ServiceAccounts and Role, the job queues of the namespace, and the routes or Ingresses. The chart expects all objects of the whole cluster to exist already. The chart does not create Secrets: at install time, it checks that each Secret that the values name exists.

**`appwrapper`** installs AppWrapper 1.2.3 or later, in the build that MiLaboratories patches and updates from time to time (for the reason, see [Kueue and AppWrapper](/infrastructure-contract-jobs/#kueue-and-appwrapper)). The chart goes one time into each cluster, after Kueue. Its admission webhooks are off by default (value `webhooks.enabled`): turn them on only when other users or tools also create AppWrappers in the cluster.

For the order in which to remove the packages, see [Uninstall Platforma](/maintain-uninstalling/).

Kubernetes hides the real infrastructure (machines, networks, load balancers, disks and autoscaling) behind its own resources, such as node pools, StorageClasses and Gateway classes, and gives guarantees for them. Platforma expects some of this infrastructure below Kubernetes, and some objects inside it.

## Below Kubernetes: the infrastructure

Before `platforma-tf-services-cluster` runs, it expects these parts of the infrastructure:

- Kubernetes 1.35 or later, and cluster admin rights for the person or the pipeline that applies the module.
- The node pools (required). An autoscaler is optional: add it, with the ProvisioningRequest CRD when you set a class, only when the cluster adds nodes for jobs. A static cluster with a fixed list of nodes works without it: the quotas of the job queues follow these nodes. See [Nodes, job queues and GPU](/infrastructure-contract-jobs/).
- The StorageClasses: see [Storage](/infrastructure-contract-storage/).
- The Gateway or the Ingress controller: see [Entry point and TLS](/infrastructure-contract-entry-point/).
- The identities of the Backend and the jobs: see [Identity, Secrets and outbound access](/infrastructure-contract-identity/).
- Kueue and AppWrapper, only when the module does not install them.

## Inside Kubernetes: the objects

Before `platforma-tf-services` runs, it expects these objects:

- The namespace of the instance. `platforma-tf-services-cluster` creates it.
- The value `infrastructure`: the output of `platforma-tf-services-cluster`, or a file that the operator wrote by hand.
- The Secrets in the namespace: the license, the master secret and the sign-in, and the TLS Secret when an Ingress uses one. None of the modules creates Secrets, so that a secret value never goes through Terraform.
- The DNS records of the hosts of the entry points, when a controller in the cluster does not make them.
- The role `admin` in the namespace. The built-in role `admin` does not have rights on the objects of Kueue and AppWrapper. `platforma-tf-services-cluster` therefore adds these rights to it, so that the role in the namespace is enough.

## The hand-off file

`platforma-tf-services` takes one object as input: `infrastructure`, all that the Backend must know about the cluster. The owner of `infrastructure` is one of two:

- the output `infrastructure` of `platforma-tf-services-cluster`, or
- the operator, who writes it by hand.

Its main parts are `contract_version`, `namespaces`, `run_as`, `jobs` (the queues, the largest job and the ServiceAccount of the jobs), `registries`, `backend` (the placement and the ServiceAccount of the Backend), `network`, `ca_bundle`, `volumes` and `primary_storage`.

It is plain data without credentials. `terraform output -json infrastructure` writes it to a JSON file, and `platforma-tf-services` reads the file unchanged, so one step never reads the Terraform state of another. The operator can also write the file by hand, without `platforma-tf-services-cluster`: a value that is not set gets the default of `platforma-tf-services`. The cluster must then already have all that `platforma-tf-services-cluster` would make.

## The contract version

The contract version is one number in `cluster_config` and in `infrastructure`. It names one set of agreements between the infrastructure and the Backend: the minimum versions of Kubernetes, Kueue, AppWrapper and the Gateway API, and the shape of the values. The current version is `1`.

Each release of a module accepts a fixed list of contract versions, and a plan with another version stops. For what a new contract version means for an upgrade, see [Upgrade Platforma](/maintain-upgrading/).

## Checks before a change

The modules check their inputs at plan time, before they change the cluster. The error names the value: unknown keys, wrong types, missing required values, secret values in place of references, and components that are not in the cluster. For the full list of inputs and their checks, see [Terraform modules](/reference-terraform-modules/) and [Chart values](/reference-chart-values/).

## Next

- [Entry point and TLS](/infrastructure-contract-entry-point/)
- [Terraform modules](/reference-terraform-modules/)

Source: https://docs.platforma.bio/infrastructure-contract-modules/
