Chapter 6
An adapter turns a profile into platform action.
A profile only says what an app needs. An adapter is what one platform builds to read a profile and provide those needs. This chapter follows the adapter from the demo, which runs on Kratix. Other platforms build their own, and the specification says what an adapter must do in Adapter conformance.
What an adapter does
- 1Read the profile.The adapter starts from the Conditions and the environment variable names the app reads.
- 2Check it against the platform.In the demo, API Conditions are checked against a catalog OpenAPI document.
- 3Ask the platform for what is needed.For Redis, the adapter sends a request that the Redis Promise fulfils.
- 4Fill in the values.The adapter sets each variable the profile names, such as
REDIS_URL, to the address of what was created. - 5Render the deployment.The final Deployment holds platform-specific addresses, but the profile stays the same on every platform.
An adapter calls the platform's existing provider interfaces directly. In the demo those are Kratix Promises. The adapter does not create another Runtime Conditions document between itself and a Promise. This is what each requirement leads to:
| Profile Requirement | Adapter Calls | Provider Owns |
|---|---|---|
kind: cache, engine: redis | Redis Promise interface | Redis Deployment and Service |
kind: api, interface.type: http | API catalog validation | Catalog-owned OpenAPI document and base URL |
ApplicationRelease request | Kubernetes workload renderer | Deployment and Service for the application |
1. Read the profile
The adapter does not read the application source. It receives the profile, and reads Conditions that have already been validated.
- name: request-cache
kind: cache
interface:
type: key_value
engine: redis
configuration:
alternatives:
- env:
- property: url
name: REDIS_URL
- env:
- property: hostname
name: REDIS_HOST
- property: port
name: REDIS_PORT
The demo adapter needs every Condition to have a name and a kind, so the demo's profile names its Conditions. A profile written by a profiler can leave names out, because name is optional, so add them before you give such a profile to this adapter.
2. Check it against the platform
The API Condition declares GET /todos/{id} and an expected response shape. The adapter compares that requirement with the catalog OpenAPI document before creating the workload.
api = validate_api_condition(condition, apis)
base_url = api.base_url or f"http://{api.name}.{namespace}.svc.cluster.local:{port}"
bound = bind_env(item.env, {"baseUrl": base_url})
env.extend(bound)
3. Ask the platform for what is needed
The adapter asks the platform for Redis by emitting the provider-owned resource. The profile declares kind: cache; the platform decides what Redis means in the cluster.
apiVersion: platform.demoteam.io/v1alpha1
kind: Redis
metadata:
name: request-logger-cache
namespace: demo
labels:
kratix.io/component-of-promise-name: application-release
kratix.io/component-of-resource-name: request-logger
kratix.io/component-of-resource-namespace: demo
spec:
size: small
4. Fill in the values
The Redis Promise owns Redis provisioning. The adapter requests a Redis, works out its address, and sets each variable the profile names: url, hostname, and port become the values of REDIS_URL, REDIS_HOST, and REDIS_PORT.
emitted.append(redis_request(redis_name, namespace, name))
redis_host = f"{redis_name}.{namespace}.svc.cluster.local"
bound = bind_env(
item.env,
{"url": f"redis://{redis_host}:6379", "hostname": redis_host, "port": "6379"},
)
env.extend(bound)
5. Render the deployment
This is where the profile's environment variable names meet platform-provided values. The application still reads the same env vars it declared in source.
env:
- name: TODOS_API_URL
value: http://todos-api.demo.svc.cluster.local:8080
- name: REDIS_URL
value: redis://request-logger-cache.demo.svc.cluster.local:6379
- name: REDIS_HOST
value: request-logger-cache.demo.svc.cluster.local
- name: REDIS_PORT
value: "6379"
Boundary summary
| Component | Owns | Does Not Own |
|---|---|---|
| Profiler | Source-to-profile extraction. | Provisioning, deployment, target values. |
| Adapter | Profile interpretation for one platform. | Extension vocabulary or provider internals. |
| Promise | Concrete provider implementation. | Application source analysis or profile generation. |
To run all of this yourself, see Run the demo.