Skip to main content

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:

NameDescriptionDefault Value
REST_CONTROLLER_DEBUGEnable verbose outputfalse
REST_CONTROLLER_WORKERSNumber of worker threads1
REST_CONTROLLER_RESYNC_INTERVALInterval between resyncs3m
REST_CONTROLLER_GROUPResource API group-
REST_CONTROLLER_VERSIONResource API version-
REST_CONTROLLER_RESOURCEResource plural name-
URL_PLURALSBFF plurals endpointhttp://bff.krateo-system.svc.cluster.local:8081/api-info/names