Skip to content

krateoplatformops/rest-dynamic-controller

Repository files navigation

Rest Dynamic Controller

The rest-dynamic-controller is an operator instantiated by the oasgen-provider to manage Custom Resources whose Custom Resource Definitions (CRDs) are generated by the oasgen-provider.

Table of Contents

Overview

The rest-dynamic-controller is a dynamic controller that manages Remote Resources through REST APIs. It's considered "dynamic" because it can manage any type of remote resource represented by a Custom Resource Definition and its related Custom Resource. The controller is configured at startup through environment variables (or CLI parameters) to manage a specific Group Version Resource.

How It Works

When a Custom Resource (CR) is created and its Custom Resource Definition (CRD) has been generated by a RestDefinition from the oasgen-provider, the following process occurs:

  1. The rest-dynamic-controller instance checks if the remote resource exists by following the instructions defined in the RestDefinition.
  2. If the resource doesn't exist, the controller performs the action described in the verbsDescription field of the RestDefinition CR.
  3. For deletion requests, a similar process is followed.
  4. During resource observation, the controller verifies if the remote resource is synchronized with the CR and performs updates if necessary.

Usage Examples

Here's an example of a Custom Resource manifest:

kind: Repo
apiVersion: gen.github.com/v1alpha1
metadata:
  name: gh-repo1
  namespace: default
  annotations:
    krateo.io/connector-verbose: "true"
spec:
  org: krateoplatformops
  name: test-generatore
  authenticationRefs:
    bearerAuthRef: bearer-gh-ref

This manifest represents a CR of kind Repo with apiVersion gen.github.com/v1alpha1. The CRD was generated by the oasgen-provider based on the specifications in the RestDefinition shown below.

GitHub Repo RestDefinition
kind: RestDefinition
apiVersion: swaggergen.krateo.io/v1alpha1
metadata:
  name: def-github
  namespace: default
spec:
  oasPath: https://github.com/krateoplatformops/github-oas3/raw/1-oas-specification-fixes/openapi.yaml
  resourceGroup: gen.github.com
  resource:
    kind: Repo
    identifiers:
      - id
      - name
      - html_url
    verbsDescription:
    - action: create
      method: POST
      path: /orgs/{org}/repos
    - action: delete
      method: DELETE
      path: /repos/{owner}/{repo}
      altFieldMapping:
        org: owner
        name: repo
    - action: get
      method: GET
      path: /repos/{owner}/{repo}
      altFieldMapping:
        org: owner
        name: repo

Configuration

Environment Variables

The following environment variables can be configured in the rest-dynamic-controller's Deployment:

Name Description Default Value
REST_CONTROLLER_DEBUG Enable verbose output false
REST_CONTROLLER_WORKERS Number of worker threads 1
REST_CONTROLLER_RESYNC_INTERVAL Interval between resyncs 3m
REST_CONTROLLER_GROUP Resource API group -
REST_CONTROLLER_VERSION Resource API version -
REST_CONTROLLER_RESOURCE Resource plural name -
URL_PLURALS BFF plurals endpoint http://bff.krateo-system.svc.cluster.local:8081/api-info/names