Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Ordered Container Start in Score #104

Open
chrishumanitec opened this issue Sep 6, 2024 · 1 comment
Open

[FEATURE] Ordered Container Start in Score #104

chrishumanitec opened this issue Sep 6, 2024 · 1 comment
Labels
help wanted Extra attention is needed new feature/idea New feature or request

Comments

@chrishumanitec
Copy link

Detailed description

Developers should be able to express rules that can be used to require some containers to be started and run before others within a single workload.

Context

Many workloads require some form of setup before the main container can run. For example, schema migration needs to be completed, static site data needs to be generated or shared state should be initiated. This set up can involve containers running to completion before another container starts, being ready/healthy before another container starts, or just have started before another container starts. This allows for patterns such as “Sidecars” or “Init Containers” to be implemented.

Many container orchestration platforms provide for ordered container start (Init Containers in Kubernetes, depends_on with service_started, service_healthy, or service_completed_successfully in Docker Compose, run.googleapis.com/container-dependencies in Google Cloud Run.) All of them allow for specifying the start order with various levels of support for conditions on when the next container should start.

Possible implementation

Proposal

Add a new before property to the container object. It would have the following schema:

description: Defines before which other containers this container should be started
title: Before
type: object
properties:
  containers:
    description: List of containers that should start after this container.
    type: array
    items:
      description: A container ID in this workload
      type: string
        minLength: 2
        maxLength: 63
        pattern: "^[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$"
  ready:
    description: The status of the container before the next container are started.
    title: Ready
    type: string
    enum:
    - started
    - healthy
    - complete

Why not use after like compose depends_on ?

This is not a dependency relationship - more a preparatory relationship

Startup order of containers is not strictly speaking a dependency graph like in compose. In the usecase of init containers, the main container is not even run at the same time as the init container. Instead, some kind of state is managed before the main container runs.

In a well factored system, the main container should not have to worry about what init containers were run - rather just that the state is correct. Only the init containers themselves “know” that they need to leave the system is a certain state.

Default state is unaffected

By specifying using before rather than after, the default behavior in score is unaffected. Adding an init container only affects the init container and not the main container.

Example Score Files

Init containers

Score

containers:
  init-one:
    ...
    before:
      containers:
      - init-two
  init-two:
    ...
    before:
      containers:
      - main
  main:
    ...

Kubernetes Pod

apiVersion: core/v1
kind: Pod
metadata:
  name: test
spec:
  containers:
  - name: main
    ...
  initContainers:
  - name: init-one
    ...
  - name: init-two
    ...

Sidecars

Score

containers:
  init:
    ...
    before:
      ready: complete # implicit default
      containers:
      - main
  sidecar:
    ...
    before:
      containers:
      - main
      ready: started
  main:
    ....

Kubernetes Pod (prior to 1.29)

apiVersion: core/v1
kind: Pod
metadata:
  name: test
spec:
  containers:
  - name: main
    ...
  - name: sidecar
    ...
  initContainers:
  - name: init
    ...

Kubernetes Pod (after 1.29)

apiVersion: core/v1
kind: Pod
metadata:
  name: test
spec:
  containers:
  - name: main
    ...
  initContainers:
  - name: init
    ...
  - name: sidecar
    restartPolicy: Always
    ...

Additional information

No response

@sujaya-sys sujaya-sys added new feature/idea New feature or request help wanted Extra attention is needed labels Sep 6, 2024
@astromechza
Copy link
Member

astromechza commented Sep 7, 2024

Edge cases to consider and mitigate

These should be caught when running score-xyz generate.

  • cyclic relationship container-a.before.containers = [container-b]; container-b.before.containers = [container-a]
  • unknown links container-a.before.containers = [unknown]
  • Some Score implementations may not support any kind of ready field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed new feature/idea New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants