Compound Promises with Waits
Compound Promises are Promises that depend on other Promises to deliver their promised service. The ability to chain Promises together allows platform teams to deliver entire stacks on demand, while keeping each sub-Promise small and focused on its own service.
In this tutorial, you will
- Encapsulate multiple Promises into a Compound Promise with waits
- Request a complete development environment Resource through a Compound Promise
For a quick overview of Workflow Controls and Waits, watch the video below:
Pre-requisites
You need an installation of Kratix for this section. Click here for instructions
The simplest way to do so is by running the quick-start script from within the Kratix directory. The script will create two KinD clusters, install, and configure Kratix.
./scripts/quick-start.sh --recreate
You can run Kratix either with a multi-cluster or a single-cluster setup. The commands on the remainder of this document assume that two environment variables are set:
PLATFORMrepresenting the platform cluster Kubernetes contextWORKERrepresenting the worker cluster Kubernetes context
If you ran the quick-start script above, do:
export PLATFORM="kind-platform"
export WORKER="kind-worker"
For single cluster setups, the two variables should be set to the same value. You can find your cluster context by running:
kubectl config get-contexts
Refer back to Installing Kratix for more details.
Register the Platform as a Destination
Compound Promises work by scheduling their workflow outputs to the Platform cluster itself. For that to work, you will need to register the Platform cluster as a Destination, and run a GitOps Agent in the Platform cluster listening to the State Store associated with the platform destination.
Create a new Destination document - platform-cluster.yaml - with the following contents:
apiVersion: platform.kratix.io/v1alpha1
kind: Destination
metadata:
name: platform-cluster
labels:
environment: platform
spec:
path: platform-cluster
strictMatchLabels: true
stateStoreRef:
name: default
kind: BucketStateStore
Register the Destination:
kubectl --context $PLATFORM apply --filename platform-cluster.yaml
Install and configure GitOps
Now that your Destination is registered, make sure to install the GitOps Agent into your Platform cluster. The quickest way to do that is to run the ./scripts/install-gitops script from the Kratix root directory:
cd /path/to/kratix
./scripts/install-gitops --context $PLATFORM --path platform-cluster
Building the Compound Promise
You can follow this guide and build the Promise along with us, or you can use it as a reference when building your own Compound Promises.
The full Promise mentioned in this guide is also available on the Kratix Marketplace.
Implementing the API
Let's create the AppStack Promise. We can use the Kratix CLI to speed up development. Create a new directory in your system and initialise a new Promise:
mkdir app-stack-example && cd app-stack-example
kratix init promise app-stack \
--group example.kratix.io \
--kind AppStack \
--version v1alpha1
The command above should produce a promise.yaml in the app-stack-example directory. We can now add the API properties we defined above:
kratix update api \
--property image:string \
--property database.driver:string
kratix update destination-selector environment=platform
The next step is to implement the workflows that will transform the user's request into the sub-promises request.
Our promise will consist of three pipelines: