Skip to content

FromStack

Igor Lysak edited this page Sep 28, 2022 · 4 revisions

Stack developer has an option to compose stacks by including existing stack into a new stack as a base, by specifying fromStack: <filesystem directory> under top-level meta in the manifest:

meta:
    name: dev
    brief: Development version of infra
    fromStack: ../infra

Hub CLI elaborate command process the declaration by searching local filesystem for directory of the specified name.

The content of the parent stack directory must contain hub.yaml, and, optionally, params.yaml and params-<ENV>.yaml where ENV is a content of ENV OS environment variable. Parent stack's hub.yaml may in turn refer to another grandparent stack via fromStack declaration, and so on.

hub.yaml manifests are merged by hub elaborate as follows:

  1. meta is taken from the last stack in order - the child stack. If there are multiple source declarations, then the last one wins.
  2. components are merged - component with the same name gets source set to the last stack in order.
  3. Children requires are short-circuited to parent provides and provides are merged.
  4. lifecycle.order are appended. In case child stack overrides parent stack component (by name) then the final lifecycle.order of the stack could be modified - child's order may insert it's components into the original order, see below.
  5. lifecycle.verbs are merged.

Parameters are merged in order as usual - params.yaml files are processed from left to right, child stack parameters are merged into parent parameters with child settings taking precedence over parent settings if both are supplied.

For example:

k8s-aws stack with

  • hub.yaml
  • params.yaml
  • fine-tuning.yaml

k8s-aws-with-monitoring stack with fromStack: ../k8s-aws under directory monitoring/

  • hub.yaml
  • params.yaml
  • params-prod.yaml
  • params-dev.yaml

dev-stack stack with fromStack: ../monitoring

  • hub.yaml
  • params.yaml
  • params-prod.yaml
  • params-dev.yaml

After performing elaborate:

cd dev-stack
hub elaborate hub.yaml params.yaml params-$ENV.yaml

the result is a flat hub.yaml.elaborate that could be deployed with deploy. Parameters files merge order for ENV=dev:

  1. k8s-aws/params.yaml
  2. monitoring/params.yaml
  3. monitoring/params-dev.yaml
  4. dev-stack/params.yaml
  5. dev-stack/params-dev.yaml

Lifecycle order

If there is a parent stack A and a child stack B, with corresponding orders - for stack A:

  • eks
  • traefik
  • dex

and for stack B:

  • cert-manager
  • traefik
  • tls-host-controller

then the final deployment order is:

  • eks
  • cert-manager
  • traefik
  • dex
  • tls-host-controller

Ie. traefik is anchoring to the order position in the parent stack and insert every component in order prior to the anchor. Everything else goes after. There could be multiple anchors. You must also repeat anchor component (traefik) declaration under components in the child stack. This is a safety measure.

Clone this wiki locally