Krateo Operator Generator (KOG) Usage Guide
(KOG = oasgen-provider + rest-dynamic-controller)
Table of Contents​
- Prerequisites
- What to do when the OpenAPI Specification (OAS) is missing/incomplete or not at version 3.0+?
- Simple Case: External APIs Compatible with K8s Resource Management
- Extended Example: External API that requires a plugin to handle external API calls
- Best Practices
- Troubleshooting
Prerequisites​
- Kubernetes cluster with Krateo installed
kubectlconfigured to access your cluster- OpenAPI Specification (OAS) 3.0+ for your target API
What to do when the OpenAPI Specification (OAS) is missing/incomplete or not at version 3.0+?​
First Scenario: the service does not provide an OpenAPI Specification (OAS) but it exposes a REST API​
In this case, the way to go is to locate the endpoints you want to use in your generated controller from the API documentation of your service and manually create the OpenAPI Specification (OAS) 3.0+ for those endpoints. You can use tools like Swagger Editor to create and validate your OAS. This process seems tedious, but it is necessary for oasgen-provider to have a well-defined OAS to generate the CRDs and controllers correctly, and it is also useful for you to have a clear understanding of the API objects you want to manage.
Second Scenario: the service does not expose a REST API but you have another way to interact with it (e.g., gRPC, GraphQL, etc.)​
In this case, you can create a web service that acts as a bridge between the Krateo oasgen-provider and the service you want to manage. The web service should implement the necessary logic to interact with the service and expose a REST API that is compatible with Kubernetes resource management. You can then use the OAS for the web service to generate the CRDs and controllers using oasgen-provider.
About OpenAPI Specification (OAS) 3.0+​
The OAS should include the following information:
-
Servers: The
serversfield (at root level of the OAS) should define the base URL for the API endpoints you want to use. This is important for the provider to know where to send requests. Note that you can override the base URL in the OAS if you want to use a different URL for the API endpoints; refer the a following section for more information. -
API endpoints (paths): It should contain the paths for the API endpoints you want to use, including the HTTP methods (GET, POST, PUT, DELETE) and any parameters required by the endpoints. Note that it is important to specify whether the parameters are required or optional, as this will affect the generated CRDs and controllers. To learn more about how these paths are used by
rest-dynamic-controller, refer to the RestDefinition section of the README. Note that any endpoint should have consistent behavior and whenever this is not the case, there may be the need to implmenent a plugin web server to normalize and fix the behavior of the API endpoints. -
Request and response schemas: It should define the request and response schemas for each endpoint, including the data types and any validation rules.
-
Authentication: If the API requires authentication, you should define the security schemes in the
componentssection of the OAS. This is important for the provider to know how to authenticate requests to the API. You can see supported authentication methods here.
Also note that any modification to the request or response schemas made by the API provider will require you to update the OAS accordingly, as the provider will generate the CRDs and controllers based on the OAS. Also consider removing the RestDefinition and recreating it with the updated OAS to ensure that the provider generates the correct CRDs and controllers (this is not necessary if you do not make changes to the request body or path parameters, as oasgen-provider won't need to update the generated CRD).
Supported authentication methods​
Use securitySchemes in the OAS to define the authentication method used by the API.
The following authentication methods are supported:
- Bearer Token
openapi: 3.0.3
servers:
- url: https://api.github.com
paths:
...
components:
+ securitySchemes:
+ bearer: # this field name can be anything
+ type: http
+ scheme: bearer
- Basic Authentication
openapi: 3.0.3
servers:
- url: https://api.github.com
paths:
...
components:
+ securitySchemes:
+ basic: # this field name can be anything
+ type: http
+ scheme: basic