Storage

The storage trait mounts different types of storages and entities such as configmaps or secret into a component.

Attaching a persistent volume

A persistent volume enables the component to store information that survives container reboot operations. To attach a persistent volume to a component use:

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: my-app
spec:
  components:
    - name: my-comp
      type: worker
      properties:
        image: my-app-image:v1.0.0
      traits:
        - type: storage # Set to storage
          properties:
            pvc: # PVC type storage
              - name: pvc-name # (Required) the name of the pvc
                mountOnly: false # (Optional) Flag to indicate if the PVC has to be mounted or also created. False by default
                mountPath: /mount/pvc # (Required) mount path
                subPath: subPath # (Optional) sub path
                resources:
                  requests: 
                    storage: 500Mi    

Attaching an ephemeral volume

An ephmeral volume is typically used to store temporal files that are generated by the component and which do not require any type of persistency. To attach an ephemeral volume use:

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: my-app
spec:
  components:
    - name: my-comp
      type: worker
      properties:
        image: my-app-image:v1.0.0
      traits:
        - type: storage # Set to storage
          properties:         
            emptyDir: # EmptyDir type storage
              - name: empty-name # (Required) the name of the volume
                mountPath: /mount/emptydir # (Required) mount path
                subPath: subPath # (Optional) sub path    

Mounting a Config Map

Config Maps are the usual method to define application and component configuration in Kubernetes. To mount the contents of a Config Map use:

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: my-app
spec:
  components:
    - name: my-comp
      type: worker
      properties:
        image: my-app-image:v1.0.0
      traits:
        - type: storage # Set to storage
          properties:            
            configMap: # ConfigMap type storage
              - name: cm-name
                mountOnly: false # (Optional) Flag to indicate if the PVC has to be mounted or also created. False by default
                mountPath: /mount/cm
                subPath: subPath # (Optional) sub path                
                mountToEnv: # mount to Environment variables (inly one variable, uses mountToEnvs it there is more than one)
                  envName: ENV_VAR1 # environment variable
                  configMapKey: key1 # cm key
                data: # (Optional) if the cm is going to be created, data field contains the cm data
                  key1: value1 # key - value data      

Mounting a Secret

Secrets are the usual method to store sensitive information in Kubernetes. Uses cases for mounting secrets in a component include setting environment variables with passwords and/or usernames, mounting certificates, etc. To mount a secret use:

apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  name: my-app
spec:
  components:
    - name: my-comp
      type: worker
      properties:
        image: my-app-image:v1.0.0
      traits:
        - type: storage # Set to storage
          properties:          
            secret: # Secret type storage
              - name: secret-name
                mountPath: mount/secret1 # (Optional) mount path
                subPath: subPath # (Optional) sub path     
                mountOnly: false # (Optional) Flag to indicate if the PVC has to be mounted or also created. False by default
                mountToEnv: # mount to Environment variables
                  envName: TEST_SECRET_1 # environment variable
                  secretKey: key1 # secret key
                data: # (Optional) if the secret is going to be created, data field contains the secret data
                  key1: value  # key - value data
              - name: mysecret # secret name
                mountOnly: true # (Optional) Flag to indicate if the PVC has to be mounted or also created. In this case, uses an existing secret
                mountPath: /mount/secret2 # (Optional) mount path  
                subPath: subPath # (Optional) sub path   
                # Mount Secret to Env
                mountToEnvs:  # mount to Environment variables 
                - envName: TEST_SECRET_2 
                  secretKey: key1
                - envName: TEST_SECRET_3
                  secretKey: key2