Task

A task describes jobs that run code or a script to completion. Notice that the task will be only executed once, and after it is completed it will not be restarted. To create schedulled task use crontask.

This component type supports properties to define the basic information about the image, its associated volumes, and the health probes that can be associated with it.

Basic information

Basic information includes the image that will be launched with an optional cmd property to define a command different from the one in the image entrypoint. Additionally, the container can define the requested CPU and memory to better utilize the available quota. Use count to launch several replicas of the task. The following YAML file contains a minimal example of a task with basic information.

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: my-app
spec:
  components:
    - name: my-task # Name of the component
      type: task # Set to task
      properties:
        image: my-app-image:v1.0.0 # (Required) Container image 
        count: 10 # (Optional) number of task to run in parallel
        cmd: ["cmd",  "arg1", ... ,"argN"] # (Optional) commands to run in the containter
        cpu: "0.25" # (Optional) Define the requested CPU.
        memory: 256Mi # (Optional) Define the requested memory.
        restart: Never # (Optional) Define the job restart policy, this value can be Never of Failure (by default Never)
        env: # (Optional) Definition of the environment variables for the container
          - name: ENV_VAR1 # Setting the value directly
            value: "value1"

Using volumes

The system supports different methods to attach a volume to a container. The main use cases are:

  • Attaching a persistent volume to store information that should survive container reboots.
  • Attaching a configmap to include the configuration file in a given path.
  • Attaching a secret to include files (e.g., TLS certificates) in a given path.
  • Attaching an empty dir as ephemeral storage for temporal files.

The following YAML file contains a minimal example of a task component with different volumes attached to it.

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: my-app
spec:
  components:
    - name: my-task # Name of the component
      type: task # Set to task
      properties:
        image: my-app-image:v1.0.0 # (Required) Container image 
        volumes: # (Optional) Definition of the volumes
          - name: vol1
            mountPath: /vol1/
            type: emptyDir # Using an ephemeral
          - name: vol2
            mountPath: /vol2/
            type: configMap # Using a Config Map
            cmName: game-demo
          - name: vol3
            mountPath: /vol3/
            type: secret  # Using a Secret
            secretName: mysecret
          - name: vol4
            mountPath: /vol4/
            type: pvc # Using a Persistent Volume Claim
            claimName: mypvc 

Full example of a task component

The following YAML shows a complete example of a task with all the major options.

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: my-app
spec:
  components:
    - name: my-task # Name of the component
      type: task # Set to task
      properties:
        image: my-app-image:v1.0.0 # (Required) Container image 
        count: 10 # (Optional) number of task to run in parallel
        cmd: ["cmd",  "arg1", ... ,"argN"] # (Optional) commands to run in the containter
        cpu: "0.25" # (Optional) Define the requested CPU.
        memory: 256Mi # (Optional) Define the requested memory.
        restart: Never # (Optional) Define the job restart policy, this value can be Never of Failure (by default Never)
        env: # (Optional) Definition of the environment variables for the container
          - name: ENV_VAR1 # Setting the value directly
            value: "value1"
          - name: ENV_VAR2 # Using a secret to obtain a key value
            valueFrom:
                secretKeyRef:
                name: secret-name
                key: key2
          - name: ENV_VAR3 # Using a configmap to obtain a key value
            valueFrom:
                configMapKeyRef:
                name: config-map-name
                key: key2
        volumes: # (Optional) Definition of the volumes
          - name: vol1
            mountPath: /vol1/
            type: emptyDir # Using an ephemeral
          - name: vol2
            mountPath: /vol2/
            type: configMap # Using a Config Map
            cmName: game-demo
          - name: vol3
            mountPath: /vol3/
            type: secret  # Using a Secret
            secretName: mysecret
          - name: vol4
            mountPath: /vol4/
            type: pvc # Using a Persistent Volume Claim
            claimName: mypvc