KOP Environment Manager - Environment Template Schedules - Rafay Product Documentation

Schedules

Info

Support for configuring schedules through UI and TF provider interfaces will be available in an upcoming release.

Overview

The Schedules feature allows administrators to automate tasks around infrastructure deployment, infrastructure shut down, or custom workflow execution at the Environment Template level using cron expressions. Administrators can schedule tasks such as provisioning environments every Monday at 6:00 AM or destroying them every Friday at 10:00 PM. The default timezone is UTC unless a specific timezone is provided. Users have the flexibility to opt out of predefined schedules based on configurable rules and approval workflows.

Did you know ?

Schedule Jobs can be managed through various methods:

Limitations

API Configuration for Scheduling Tasks

Below are a few examples of an API configuration spec with three (3) schedule types - deploy / destroy / workflow execution:

destroy - For destroying VM instances

{
  "apiVersion": "eaas.envmgmt.io/v1",
  "kind": "EnvironmentTemplate",
  "metadata": {
    "name": "default-envtemplate",
    "description": "Default Environment Template",
    "createdBy": {
      "id": "user-id",
      "username": "user@example.com"
    },
    "modifiedBy": {
      "id": "user-id",
      "username": "user@example.com"
    }
  },
  "spec": {
    "version": "v1",
    "resources": [
      {
        "type": "dynamic",
        "kind": "resourcetemplate",
        "name": "default-resource",
        "resourceOptions": {
          "version": "v1"
        }
      }
    ],
    "schedules": [
      {
        "name": "remove-instance",
        "description": "Remove the specified virtual machine instance.",
        "type": "destroy",
        "cadence": {
          "cronExpression": "45 07 * * *"
        },
        "optOutOptions": {
          "allowOptOut": true,
          "maxAllowedDuration": "24h",
          "maxAllowedTimes": 3,
          "approval": {
            "tasks": [
              {
                "name": "approval-task",
                "type": "approval",
                "agents": [
                  {
                    "name": "default-agent"
                  }
                ],
                "options": {
                  "approval": {
                    "type": "internal"
                  }
                }
              }
            ]
          }
        }
      }
    ],
    "versionState": "draft"
  }
}

workflows - For executing HTTP requests

{
  "apiVersion": "eaas.envmgmt.io/v1",
  "kind": "EnvironmentTemplate",
  "metadata": {
    "name": "default-envtemplate",
    "description": "Default Environment Template",
    "createdBy": {
      "id": "user-id",
      "username": "user@example.com"
    },
    "modifiedBy": {
      "id": "user-id",
      "username": "user@example.com"
    }
  },
  "spec": {
    "version": "v1",
    "resources": [
      {
        "type": "dynamic",
        "kind": "resourcetemplate",
        "name": "default-resource",
        "resourceOptions": {
          "version": "v1"
        }
      }
    ],
    "schedules": [
      {
        "name": "http-request-job",
        "description": "Executes an HTTP request to a specified endpoint.",
        "type": "workflows",
        "cadence": {
          "cronExpression": "40 07 * * *"
        },
        "workflows": {
          "tasks": [
            {
              "name": "http-request-task",
              "type": "driver",
              "driver": {
                "data": {
                  "config": {
                    "type": "http",
                    "http": {
                      "endpoint": "https://example.com/endpoint",
                      "method": "GET"
                    }
                  }
                }
              }
            }
          ]
        }
      }
    ],
    "versionState": "draft"
  }
}

deploy - For Managing Node Pools

{
  "apiVersion": "eaas.envmgmt.io/v1",
  "kind": "EnvironmentTemplate",
  "metadata": {
    "name": "gke-np-envtemplate",
    "description": "GKE with node pool environment template",
    "projectID": "1ky4gkz"
  },
  "spec": {
    "version": "v1",
    "resources": [
      {
        "type": "dynamic",
        "kind": "resourcetemplate",
        "name": "gke-np-template",
        "resourceOptions": {
          "version": "v1"
        }
      }
    ],
    "schedules": [
      {
        "name": "deploy-nodepools",
        "description": "Deploy or update node pools except the default one.",
        "type": "deploy",
        "cadence": {
          "cronExpression": "55 11 18 7 *"
        },
        "optOutOptions": {
          "allowOptOut": true,
          "maxAllowedDuration": "24h",
          "maxAllowedTimes": 3
        },
        "context": {
          "data": {
            "variables": [
              {
                "name": "node_pools",
                "valueType": "json",
                "value": "[{\"disk_size_gb\":100,\"disk_type\":\"pd-standard\",\"image_type\":\"COS_CONTAINERD\",\"initial_node_count\":1,\"max_count\":100,\"min_count\":1,\"name\":\"inception-node-pool\",\"node_count\":3,\"node_locations\":\"us-central1-a,us-central1-b\"}]"
              }
            ]
          }
        }
      }
    ],
    "versionState": "draft"
  }
}

Config Specification

The following Environment Template spec configures GCP resource management with scheduled tasks, such as destroying VM instances and executing HTTP requests. It includes cron-based scheduling, approval workflows, and opt-out options for flexible automation.

apiVersion: eaas.envmgmt.io/v1
kind: EnvironmentTemplate
metadata:
  name: gcp-envtemplate
  description: Environment Template for GCP Resources
spec:
  version: v1
  resources:
  - type: dynamic
    kind: resourcetemplate
    name: gcp-vpc-instance
    resourceOptions:
      version: v1
  schedules:
  - name: destroy-vm-instance
    description: Destroy the virtual machine instance
    type: destroy
    cadence:
      cronExpression: 45 11 * * *
      cronTimezone: IST
    optOutOptions:
      allowOptOut: true
      maxAllowedDuration: 24h
      maxAllowedTimes: 3
      approval:
        tasks:
        - name: mock-approval
          type: approval
          agents:
          - name: envmgr-agent-feb
          options:
            approval:
              type: internal
  - name: force-destroy-vm-instance
    description: Destroy the virtual machine instance
    type: destroy
    cadence:
      cronExpression: 0 0 * * 5
  - name: execute-http-request
    description: Execute Http Request
    type: workflows
    cadence:
      cronExpression: 40 07 * * *
    workflows:
      tasks:
      - name: mock-get-clientip
        type: driver
        driver:
          data:
            config:
              type: http
              http:
                endpoint: https://mocktarget.apigee.net/ip
                method: GET
  versionState: draft

Staggered Cadence

The staggered field allows a scheduled job to be executed in a staggered manner across multiple targets instead of triggering all at once. This helps distribute the load and avoid spikes in resource consumption.

cadence:
  cronExpression: "*/5 * * * *"
  cronTimezone: "Europe/London"
  staggered:
    enabled: true
    maxInterval: "7m"