Skip to content

Part 1

In this section, you will develop a container based "workflow handler" that will perform the action of installing your custom application. In this example, the container will execute a shell script that will install a simple Helm chart. The workflow handler will be used by a resource template that will then be part of an environment template. The following components will be used in this example:

  • A system resource template which will pull the kubeconfig for the kubernetes cluster and pass the kubeconfig to subsequent resource templates
  • A container based workflow handler which will deploy a helm chart
  • A resource template which will use the workflow handler
  • An inline config context storing Rafay Credentials
  • A environment template which will deploy the resource template

You will implement the steps described below

  1. You will first build a container workflow handler using docker and push it to a repository
  2. You will use the RCTL CLI to build an environment template from provided specification files
  3. You will deploy an environment using the previously created template

Step 1: Download Files

In this step, you will download and extract a ZIP archive which contains the the Docker container files and the specification files of the EM resources for this part of the guide.

Download

  • Download the archive sample_app.zip
  • Extract this archive on your local machine

You will use these files in the subsequent steps.


Step 2: Build Container

In this step, you will build a container workflow handler. The workflow handler will execute a shell script that will install a helm chart onto a kubernetes cluster.

  • Navigate to the container directory in your extracted download

You will see the following files and folders:

  • Dockerfile - The dockerfile for building the container
  • run.sh - The shell script for installing the helm chart
  • values.yaml - The helm chart's custom values file with variables to be updated by the shell script
  • httpbin - The folder containing the helm chart

  • Execute the following docker command from the container directory to build and push the image to Docker Hub. Be sure to update the command with your Docker Username

docker buildx build --no-cache --platform=linux/amd64 -f .\Dockerfile -t <DOCKER_USERNAME>/sample_app:1.00 . --push

Step 3: Create Workflow Handler

In this step, we will update and create the workflow handler using a specification file and RCTL.

Important

Be sure to update any resource names with a unique name to prevent conflicts within the organization

  • In your extracted archive from step 1, view the file sample-app/wfh.yaml
  • Update the DOCKER_USERNAME and any other fields to match your environment
apiVersion: eaas.envmgmt.io/v1
kind: WorkflowHandler
metadata:
  name: sample-app
  project: system-catalog
spec:
  config:
    container:
      image: <DOCKER_USERNAME>/sample_app:1.00
      imagePullCredentials: {}
      kubeOptions:
        securityContext:
          readOnlyRootFileSystem: false
    timeoutSeconds: 3600
    type: container
  inputs:
  - data:
      envs:
      - key: REPLICA_COUNT
        value: $(current.input.replica_count)$
      - key: VAR_kubeconfig
        value: $(resource.\"res-gen-kubeconfig-user\".output.kubeconfig.value)$
      - key: NAMESPACE
        value: $(environment.name)$
      - key: ACTION
        options:
          override:
            type: notallowed
        value: $(trigger.payload.action)$
    name: wfh-context
status: {}
  • Save the updated file
  • Run the following RCTL command to create the Workflow Handler within the controller
rctl apply -f wfh.yaml

You will see the workflow handler created in the controller under Infrastructure -> Environments -> Workflow Handlers


Step 4: Create Resource Template

In this step, we will update and create the resource template using a specification file and RCTL.

Important

Be sure to update any resource names with a unique name to prevent conflicts within the organization

  • In your extracted archive from step 1, view the file sample-app/rt.yaml
  • Update any fields to match your environment
apiVersion: eaas.envmgmt.io/v1
kind: ResourceTemplate
metadata:
  name: sample-app
  project: system-catalog
spec:
  provider: custom
  providerOptions:
    custom:
      tasks:
      - name: sample-app
        onFailure: unspecified
        options: {}
        type: workflowHandler
        workflowHandler:
          name: sample-app
  version: v1
  versionState: active
  • Save the updated file
  • Run the following RCTL command to create the Resource Template within the controller
rctl apply -f rt.yaml

You will see the resource template created in the controller under Infrastructure -> Environments -> Resource Templates


Step 5: Create Environment Template

In this step, we will update and create the environment template using a specification file and RCTL. Note that this references the resource template from the prior step as well as a built in system template.

Important

Be sure to update any resource names with a unique name to prevent conflicts within the organization

  • In your extracted archive from step 1, view the file sample-app/et.yaml
  • Update the AGENT_NAME and any other fields to match your environment
apiVersion: eaas.envmgmt.io/v1
kind: EnvironmentTemplate
metadata:
  name: sample-app
  project: system-catalog
spec:
  agents:
  - name: <AGENT_NAME>
  contexts:
  - data:
      envs:
      - key: Host Cluster API Key
        options:
          description: Host Cluster API Key
          override:
            selectors:
            - resource.*.RCTL_API_KEY
            type: notallowed
          sensitive: true
      - key: Controller Endpoint
        options:
          description: Enter the endpoint of the controller
          override:
            selectors:
            - resource.*.RCTL_REST_ENDPOINT
            type: allowed
      - key: API Key
        options:
          description: Enter the API key of the controller
          override:
            selectors:
            - resource.*.PAAS_API_KEY
            type: allowed
          sensitive: true
    name: rafay-auth-config
  resources:
  - dependsOn:
    - name: res-gen-kubeconfig-user
    kind: resourcetemplate
    name: sample-app
    resourceOptions:
      version: v1
    type: dynamic
  - kind: resourcetemplate
    name: res-gen-kubeconfig-user
    resourceOptions:
      version: v1.0
    type: dynamic
  variables:
  - name: Host Cluster Name
    options:
      displayMetadata:
        disabled: false
        section: ""
        sectionDescription: ""
        tooltip: ""
        weight: ""
      override:
        selectors:
        - resource.res-gen-kubeconfig-user.cluster_name
        type: allowed
    value: acme-host-cluster
    valueType: text
  - name: Replica Count
    options:
      displayMetadata:
        disabled: false
        section: ""
        sectionDescription: ""
        tooltip: ""
        weight: ""
      override:
        selectors:
        - resource.sample-app.replica_count
        type: allowed
    value: "1"
    valueType: text
  version: v1
  versionState: Draft
  • Save the updated file
  • Run the following RCTL command to create the Environment Template within the controller
rctl apply -f et.yaml

You will see the environment template created in the controller under Infrastructure -> Environments -> Environment Templates


Step 6: Update Config Context

Now, you will go into the Rafay Console and update that the inline Config Context. You will then update the sensitive variable value from the console. This will then encrypt the sensitive values. The values required to populate the config context can be found in the CLI Config file which can be downloaded from Home -> My Tools -> Download CLI Config.

  • In your project, navigate to Environments -> Environment Templates
  • Click on the newly created environment template named sample-app and edit the version v1
  • Navigate to Config Contexts and edit the context named rafay-auth-config
  • Navigate to the section named Environment Variables
  • Edit the variable named Host Cluster API Key
  • Populate the Value field with the API Key
  • Edit the variable named API Key
  • Populate the Value field with the API Key
  • Click Save
  • Edit the variable named Controller Endpoint
  • Populate the Value field with the controller endpoint
  • Click Save
  • Click Save again

Config Context


Recap

In this part, you created an environment template that will use a resource template that will deploy a helm char using a container based workflow handler.