Autopilot SDK Structure
The source code for the Autopilot SDK is composed of 3 core directories:
cli: contains source code for theapCLI.codegen: contains the source code for generating code, Kubernetes manifests, and other project files necessary to build and deploy the operator.codegenis invoked by theap generatecommand, but can be invoked manually (seedebuggable_generate.gofor an example).pkg: libraries used for running Autopilot Operators.
CLI Design
The ap CLI is designed to manage the full lifecycle of the Operator, from code generation, build, and deployment.
Autopilot Operators can be built and deployed via standard means (e.g. go build, docker, kubectl apply). The ap CLI is designed to simplify this process, without being a required component.
Codegen Design
The codegen package contains the root Run, Load and Generate functions which are used to generate code and other project files from the autopilot.yaml file.
It contains subpackages model, templates, and util.
model- contains the internal model of project data parsed from theautopilot.yamlas well as utility functions which are used to render templates for generated files.templates- contains the templates used to render generated code, deployment, and project files. Templates are organized by type, withcodecontaining all templates for generated.gofiles, anddeploycontaining templates for generated Kubernetes manifests.
For the full list of files generated by Autopilot, see generate.go#projectFiles and generate.go#phaseFiles.
Pkg Design
pkg contains the core libraries for running Autopilot Operators. It is broken up into the following subpackages:
config: defaults and helper functions for loading the Autopilot Operator config. Read more about the Autopilot Operator config in the reference documentation.defaults: defaults core to the system. Default file location ofautopilot.yamlas well as other variables (which can be overridden ininit()functions).ezkube:ezkubecontains a client which is a convenience wrapper for the dynamicclient.Clientof the controller-runtime library. It adds convenience functions for operators such as theEnsurefunction which applies resources to Kubernetes, setting owner references and retrying on resource conflicts.metrics: defines the basemetrics.Clienton which generated metrics code is based. The implemented metrics client is designed primarily for querying Prometheus.run: contains the main entrypoint for Autopilot Operators. The Operator’s generatedmain.gocalls therun.Runfunction which runs the user’s schedulerScheduler.scheduler: contains utilities and shared code for the generatedscheduler.go, which is responsible for calling the user-defined workers.utils: utilities used in various places in generated code.version: small package containing the current version of Autopilot itself. This version is stored as a variable which is set at compile-time by Autopilot’sMakefile.