Custom Job Stages

For users of Kubernetes or Titus, Custom Job Stages offer a native solution for enhancing Spinnaker’s functionality with the power of containers.

For users of Kubernetes or Titus, Custom Job Stages offer a native solution for enhancing Spinnaker’s functionality with the power of containers. Custom Job Stages enable operators to extend Spinnaker without having to maintain a custom build of Orca.

Note: Custom Job stages are only supported for the Kubernetes and Titus providers.

How it works

At its core, Custom Job Stages use the Run Job stage to start a Task (Titus) or Job (Kubernetes) to perform some type of work. These jobs are defined as configuration for Orca and registered when the application starts. When used in a pipeline, Orca takes this configuration, generates a Run Job stage and then executes it. To support a more native experience, we provide configuration options for things like stage name, description and parameters so that this stage feels less like a Run Job stage and more like an out of the box stage.

When should I use Custom Job Stages?

Custom Job Stages are perfect for when you need to encapsulate a common task so that all users of Spinnaker can benefit and standardize. For example, if you see a large number of users running database migrations in the same way, but manually defining jobs (via Run Job), simply define a Custom Job Stage which captures all the complexity of the job and exposes a subset of customization options.

Some example use cases for Custom Job Stages include:

  • Building Docker images with Kaniko
  • Running integration tests
  • Interacting with external systems
  • Performing database migrations

Creating a Custom Job Stage

Custom Job stages are configured as part of Orca’s configuration. To enable them, simply add configurations via the job.preconfigured.{cloudProvider} block in orca-local.yml where cloudProvider is the name of the cloud provider which will be used to run the job. For example, if you are using Kubernetes, the value will be kubernetes. The following properties are supported for all providers.

  • enabled - Determines if stage will be available in the UI.
  • label - Human readable stage name.
  • description - Human readable description of what the stage does.
  • type - Unique key used to determine stage type.
  • cloudProvider - Cloud provider to use for this stage. Valid values are titus or kubernetes.
  • credentials - Account name used when executing the job. Must be valid account for cloudProvider.
  • waitForCompletion - If true, the stage will not be marked complete until the job completes.
  • parameters - List of parameters presented to the end user.

Custom Job Stages - Kubernetes

The following properties are supported for the kubernetes cloud provider.

  • account - Account name used when executing the job. Must be valid account for cloudProvider.
  • application - Name of the application to associate the job with.
  • manifest - YAML definition for the Kubernetes Job that will be run when the stage is executed.
  • propertyFile - Use logs from this container to capture output data. Captured output will be available in the pipeline context for use in downstream stages.

Note: If you’re using the slash (/) character in any manifest annotations, you’ll need to use this special syntax to prevent the slash from being dropped when the application reads its configuration. For example, if your annotation key is iam.amazonaws.com/role you’ll need to define it like so: [iam.amazonaws.com/role].

Custom Job Stages - Titus

  • cluster - Definition of the cluster to be created when the stage is executed.
  • region - Region in which to run the underlying job.
  • propertyFile - File to download once the job completes.

Custom Job Stage parameters

Using parameters with the Custom Job Stage enables your users to customize specific fields of the job configuration at runtime. Before the stage is started, user supplied values will replace the values in the stage’s configuration. Parameters support the following properties

  • name - Name of parameter.
  • label - Human readable parameter name (shown in the UI).
  • defaultValue - default value, if not overridden by user.
  • description - Description of what parameter is used for.
  • order - Display order of the parameter in the UI.

Example Custom Job Stage

  1. job:
  2. preconfigured:
  3. kubernetes:
  4. - label: Echo
  5. type: echoPhrase
  6. description: Echo a configured phrase
  7. cloudProvider: kubernetes
  8. account: kubernetes
  9. credentials: kubernetes
  10. waitForCompletion: true
  11. application: k8s2
  12. parameters:
  13. - name: PHRASE
  14. label: Phrase to say
  15. description: Phrase to be echoed.
  16. mapping: manifest.spec.template.spec.containers[0].env[0].value
  17. defaultValue: "Hello world!"
  18. manifest:
  19. apiVersion: batch/v1
  20. kind: Job
  21. metadata:
  22. name: say-hello
  23. namespace: spinnaker
  24. spec:
  25. backoffLimit: 0
  26. template:
  27. spec:
  28. restartPolicy: Never
  29. containers:
  30. - name: hello
  31. image: alpine:latest
  32. env:
  33. - name: PHRASE
  34. value: placeholder
  35. command: ["echo", $(PHRASE)]

Using a Custom Job Stage

Custom Job Stages will appear as native stages within the Spinnaker UI. Users can add these stages to their pipelines as they would any other stage.

Custom Job Stages - 图1

If the stage defines any variables they will be rendered and presented to the user. At this point, the user is free to override the values as they need.

Custom Job Stages - 图2

Custom Job stages also take on a native look and feel while executing. The below screen shots show an example of the Echo stage running. You’ll notice that logs are presented to the user for ease of debugging.

Custom Job Stages - 图3

Custom Job Stages - 图4

Last modified May 4, 2021: more cleanup (0281411)