Skip to content

CLI

Users can use RCTL to automate the lifecycle of operations associated with Resource Blueprints/Templates, Environment Blueprints/Templates, Contexts, and Environments.


Context

Create Context

To create a config context, use the below command.

./rctl apply -f <demo-context.yaml>

Below is an example of a Context Config YAML file:

apiVersion: eaas.envmgmt.io/v1
kind: ConfigContext
metadata:
  name: demo-context
  project: defaultproject
  description: demo-description
spec:
  envs:
  - key: RCTL_REST_ENDPOINT
    options:
      description: demo-description
      override:
        restrictedValues:
        - qc-console.stage.rafay.dev
        - console-user1-env1.dev.rafay-edge.net
        - console.stage.rafay.dev
        - console.rafay.dev
        type: restricted
      required: true
      selectors:
        - selector1
        - selector2
    value: qc-console.stage.rafay.dev
  - key: RCTL_API_KEY
    options:
      override:
        type: allowed
      required: true
      sensitive: true
    value: rctl_api_key
  - key: RCTL_API_SECRET
    options:
      override:
        type: notallowed
      sensitive: true
    value: rctl_api_secret
  - key: DRIVER_DEBUG
    options:
      override:
        restrictedValues:
        - "true"
        - "false"
        type: restricted
    value: "false"
  files:
  - data: dmFsdWU=
    name: config.json
    options:
      description: config file
      override:
        type: allowed
      required: true
  variables:
  - name: rafay_config_file
    value: config.json
    valueType: text

Get Config Context

Use the below command to retrieve/list the Config Contexts in the current project.

./rctl get configcontext

Example

./rctl get configcontext   
+--------------------+--------------------------------+---------+
| CONFIGCONTEXT NAME | MODIFIED AT                    | SHARING |
+--------------------+--------------------------------+---------+
| config-context-1   | 2024-06-20 09:28:40.441923     | -       |
|                    | +0000 UTC                      |         |
+--------------------+--------------------------------+---------+
| demo-context-1   | 2024-06-20 08:28:40.441923       | -       |
|                    | +0000 UTC                      |         |
+--------------------+--------------------------------+---------+

Get Specific Config Context

Use this command to retrieve a specific config context detailed information.

./rctl get configcontext <context_name>

Example

./rctl get configcontext demo-context-1
+--------------------+--------------------------------+---------+
| CONFIGCONTEXT NAME | MODIFIED AT                    | SHARING |
+--------------------+--------------------------------+---------+
| demo-context-1     | 2024-06-20 08:28:40.441923     | -       |
|                    | +0000 UTC                      |         |
+--------------------+--------------------------------+---------+

Delete Config Context

Use the below command to delete a specific config context

./rctl delete configcontext <demo-context>

Resource Template

Create Resource Template

To create a resource template, use the below command.

./rctl apply -f <resource-template.yaml>

Below is an example of a Resource Template YAML file:

apiVersion: eaas.envmgmt.io/v1
kind: ResourceTemplate
metadata:
  description: This is a resource template
  name: demo-resource-temp
  project: demo-project
spec:
  agents:
  - name: sp-agent1
  contexts:
  - name: demo-context
  provider: opentofu
  providerOptions:
    driver:
      name: demo-driver
    openTofu:
      backendConfigs:
      - key=tmp3
      - bucket=demo-eaas1
      - region=us-west-2
      - encrypt=true
      backendType: custom
  repositoryOptions:
    branch: main
    directoryPath: terraform-guides/infrastructure-as-code/aws-ec2-instance
    name: demo-envmgr
  version: v1

Get Resource Templates

Use the below command to retrieve/list the resource templates in the current project.

./rctl get resourcetemplate

Example

./rctl get resourcetemplate   
+--------------------------+-----------------------+------------------+--------------------------------+---------+
| RESOURCE TEMPLATE NAME   | LATEST ACTIVE VERSION | RESOURCE TYPE    | MODIFIED AT                    | SHARING |
+--------------------------+-----------------------+------------------+--------------------------------+---------+
| sample-resource-template | version-1             | ResourceTemplate | 2024-06-20 09:33:57.615714     | -       |
|                          |                       |                  | +0000 UTC                      |         |
+--------------------------+-----------------------+------------------+--------------------------------+---------+
| demo-resource-template   | version-2             | ResourceTemplate | 2024-06-20 08:33:57.615714     | -       |
|                          |                       |                  | +0000 UTC                      |         |
+--------------------------+-----------------------+------------------+--------------------------------+---------+

Get a Specific Resource Template

Use this command to retrieve a specific resource template detailed information.

rctl get resourcetemplate <resourcetemp_name>

Example

./rctl get resourcetemplate sample-resource-template
+--------------------------+-----------------------+------------------+--------------------------------+---------+
| RESOURCE TEMPLATE NAME   | LATEST ACTIVE VERSION | RESOURCE TYPE    | MODIFIED AT                    | SHARING |
+--------------------------+-----------------------+------------------+--------------------------------+---------+
| sample-resource-template | version-1             | ResourceTemplate | 2024-06-20 09:33:57.615714     | -       |
|                          |                       |                  | +0000 UTC                      |         |
+--------------------------+-----------------------+------------------+--------------------------------+---------+

Delete Resource Template

Use the below command to delete a specific Resource Template

./rctl delete resourcetemplate <demo-resource-temp>

Environment Template

Create Environment Template

To create an environment template, use the below command.

./rctl apply -f <environment-template.yaml>

Below is an example of an Environment Template YAML file:

apiVersion: eaas.envmgmt.io/v1
kind: EnvironmentTemplate
metadata:
  name: envmgr-1
  project: defaultproject
  description: This is an environment template
  displayName: demo-environment-template
  annotations:
    eaas.envmgmt.io/category: AWS,Nvidia,AI/ML
    envmgmt.io/project-limits: "2"
  labels:
    env: qc
    release: stable
spec:
  agentOverride:
    required: true
    restrictedAgents:
    - sp-scale
    - sp-agent1
    type: restricted # Supported values are allowed, notallowed and restricted
  agents:
  - name: sp-scale
  contexts:
  - name: sp1
  - name: sp2
  hooks:
    onFailure:
    - agents:
      - name: sp-agent1
      driver:
        name: sp-art
      name: onfailure-driver
      onFailure: continue
      timeoutSeconds: 3600
      type: driver
    onInit:
    - agents:
      - name: sp-agent1
      name: oninit-approval
      onFailure: continue
      options:
        approval:
          type: internal
      timeoutSeconds: 3600
      type: approval
    - agents:
      - name: sp-agent1
      dependsOn:
      - oninit-approval
      name: oninit-container
      onFailure: continue
      options:
        container:
          arguments:
          - -refresh=false
          - --log-level=2
          commands:
          - /bin/sh
          - -c
          cpuLimitMilli: "512"
          envvars:
            DOWNLOAD_TOKEN: "token"
            DOWNLOAD_URL: "url"
          image: docker.io/demouser569/security:1.1
          memoryLimitMB: "1024"
          successCondition: |-
            if #status.http.statusCode == 200 {
              success: true
            }
            if #status.http.statusCode != 200 {
              failed: true
              reason: "url not reachable"
            }
          workingDirPath: /security/
      timeoutSeconds: 3600
      type: container
    onSuccess:
    - agents:
      - name: sp-agent1
      name: onsuccess-http
      onFailure: continue
      options:
        http:
          body: <h1>This is a heading</h1>
          endpoint: https://httpbin.org
          headers:
            Content-type: application/json
            X-TOKEN: 1234
          method: GET
          successCondition: |-
            if #status.http.statusCode == 200 {
              success: true
            }
            if #status.http.statusCode != 200 {
              failed: true
              reason: "url not reachable"
            }
      timeoutSeconds: 3600
      type: http
  iconURL: iconurl
  readme: |-
    This is an
    environment template
    with all options
  resources:
  - kind: resourcetemplate
    name: sp-rt-hcp
    resourceOptions:
      dedicated: true
      version: v1
    type: dynamic
  - kind: resource
    name: sp-stat
    type: static
  - kind: environment
    name: sp-env
    type: static
  - kind: resourcetemplate
    name: sp-tf1
    resourceOptions:
      version: v1
    type: dynamic
  - dependsOn:
    - name: tf1
    kind: resourcetemplate
    name: sp-rt-tf
    resourceOptions:
      version: v1
    type: dynamic    
  variables:
  - name: aws_cloud_provider_name
    options:
      description: Enter the cloud credential name
      override:
        type: allowed
      required: true
    value: '[sp]'
    valueType: hcl
  - name: aws_cloud_provider_access_key
    options:
      override:
        type: allowed
      sensitive: true
    value: accesskey
    valueType: text
  - name: aws_cloud_provider_secret_key
    options:
      override:
        type: notallowed
      sensitive: true
    value: secretkey
    valueType: text
  - name: eks_cluster_project
    options:
      override:
        restrictedValues:
        - sp
        - defaultproject
        - sp-git-sync
        type: restricted
    value: defaultproject
    valueType: text
  - name: eks_blueprint
    options:
      override:
        type: allowed
    value: '{"default"}'
    valueType: json
  - name: rafay_config_file
    options:
      override:
        type: notallowed
    value: config.json
    valueType: text
  - name: eks_cluster_name
    options:
      override:
        type: allowed
    value: $(environment.name)$
    valueType: expression    
  version: v1
  sharing:
    enabled: true
    projects:
    - name: a1

Get Environment Template

Use the below command to retrieve/list the Environment Templates in the current project.

./rctl get environmenttemplate

Example

./rctl get environmenttemplate
+---------------------------+-----------------------+----------------+--------------------------------+---------+
| ENVIRONMENT TEMPLATE NAME | LATEST ACTIVE VERSION | RESOURCE COUNT | MODIFIED AT                    | SHARING |
+---------------------------+-----------------------+----------------+--------------------------------+---------+
| sample-test-template      | v1                    | 1              | 2024-06-20 04:46:31.130737     | -       |
|                           |                       |                | +0000 UTC                      |         |
+---------------------------+-----------------------+----------------+--------------------------------+---------+
| demo-template             | v2                    | 1              | 2024-06-20 03:46:31.130737     | -       |
|                           |                       |                | +0000 UTC                      |         |
+---------------------------+-----------------------+----------------+--------------------------------+---------+
Get a Specific Environment Template

Use this command to retrieve a specific environment template detailed information.

./rctl get environmenttemplate <envtemp_name>

Example

./rctl get environmenttemplate demo-template
+---------------------------+-----------------------+----------------+--------------------------------+---------+
| ENVIRONMENT TEMPLATE NAME | LATEST ACTIVE VERSION | RESOURCE COUNT | MODIFIED AT                    | SHARING |
+---------------------------+-----------------------+----------------+--------------------------------+---------+
| demo-template             | v2                    | 1              | 2024-06-20 03:46:31.130737     | -       |
|                           |                       |                | +0000 UTC                      |         |
+---------------------------+-----------------------+----------------+--------------------------------+---------+

Delete Environment Template

Use the below command to delete a specific Environment Template

./rctl delete environmenttemplate <demo-env-temp>

Environment

Create Environment

To create an environment, use the below command

./rctl apply -f environment.yaml

Below is an example of an Environment YAML file:

apiVersion: eaas.envmgmt.io/v1
kind: Environment
metadata:
  description: This is an environment
  name: demo-env
  project: defaultproject
spec:
  template:
    name: demo-env1
    version: v1

Get Environment

Use the below command to retrieve/list the Environments in the current project.

./rctl get environment

Example

./rctl get environment                             
+----------------------------+----------------------+------------------+----------+
| ENVIRONMENT NAME           | ENVIRONMENT TEMPLATE | TEMPLATE VERSION | STATUS   |
+----------------------------+----------------------+------------------+----------+
| eks-em-testing             | sample-test-template | v5               | StatusOK |
+----------------------------+----------------------+------------------+----------+
| demo-env                   | demo-template        | v4               | StatusOK |
+----------------------------+----------------------+------------------+----------+

Get a Specific Environment

Use this command to retrieve an environment detailed information.

./rctl get environment <env_name>  

Example

./rctl get environment eks-em-testing                           
+----------------------------+----------------------+------------------+----------+
| ENVIRONMENT NAME           | ENVIRONMENT TEMPLATE | TEMPLATE VERSION | STATUS   |
+----------------------------+----------------------+------------------+----------+
| eks-em-testing             | sample-test-template | v5               | StatusOK |
+----------------------------+----------------------+------------------+----------+

Deploy Environment

To deploy an environment created using the template(s) and other configurations, use the command below

./rctl deploy environment <demo-env>

Destroy Environment

Use the command below to remove the environment resources; however, this will not delete the environment

./rctl destroy environment demo-env

Delete Environment

To delete an environment completely, use the command below

./rctl delete environment demo-env