Defining an API
The Operator's API will be the definition of how it is represented within a Kubernetes cluster. The API is directly translated to a generated CRD, which describes the blueprint for the custom resource object that users will consume to interact with the Operator. Therefore, creating this API is a necessary first step before writing other logic for the Operator. Without this, there will be no way for the Operator's logic code to read values from the custom resource.
Building an Operator API is done by writing a Go struct to represent the object. The basic outline of this struct can be scaffolded by the Operator SDK with the following command:
operator-sdk create api --group operator --version v1alpha1 --kind NginxOperator --resource --controller
This command does the following:
- Creates the API types in a new directory called
api/
- Defines these types as belonging to the API group
operator.example.com
(since we initialized the project under...