-
Notifications
You must be signed in to change notification settings - Fork 107
Initial commit for Controller Scaffolder #2697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| This scaffolder generates Kubernetes controllers that follow the MongoDB Atlas Kubernetes operator patterns, including: | ||
|
|
||
| - **State machine-based controllers** with proper lifecycle management | ||
| - **Translation layers** for Atlas SDK integration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: This is wired, maybe, but not generated right?
|
|
||
| - **State machine-based controllers** with proper lifecycle management | ||
| - **Translation layers** for Atlas SDK integration | ||
| - **Service interfaces** with appropriate Atlas API mappings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: With runtime translations, this is basically SDKClient management right?
| ├── atlas-controller-scaffolder/ # This tool | ||
| ├── atlas2crd/ # Config definitions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: Do these path change once integrated on the AKO repo?
| 1. **Clone dependencies:** | ||
|
|
||
| ```bash | ||
| cd ../ | ||
| git clone https://github.com/mongodb-atlas-kubernetes/atlas2crd | ||
| git clone https://github.com/mongodb/mongodb-atlas-kubernetes | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: we might not need this anymore, so long as you are working in the AKO repo, right?
| 2. **Replace the crd2go dependency** | ||
| Make sure the crd2go dependency is pointing to the local copy. In your `go.mod` file: | ||
|
|
||
| ```bash | ||
| replace github.com/josvazg/crd2go => ../crd2go | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be just be a dependency on the open source repo, once available. It can now already be used a a library, once the deps got fixed.
| 3. **Generate CRD types** | ||
| Use `crd2go` tool to generate go types for CRDs: | ||
|
|
||
| ```bash | ||
| cd ./crd2go/ | ||
| go build -o ./crd2go ./cmd/crd2go/main.go | ||
| ./crd2go -input=./pkg/crd2go/samples/crds.yaml -output=../atlas-controller-scaffolder/pkg/api/v1 | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 thanks! so do don't need to document it myself ;-p
This doc is very good I shall do a similar one for CRD2Go before it gets its own repo.
| ### List Available CRDs | ||
|
|
||
| ```bash | ||
| ./bin/ako-controller-scaffolder --config ../atlas2crd/config.yaml --list | ||
| ``` | ||
|
|
||
| ### Generate Controller | ||
|
|
||
| ```bash | ||
| ./bin/ako-controller-scaffolder --config ../atlas2crd/config.yaml --crd <CRD_KIND> | ||
| ``` | ||
|
|
||
| **Examples:** | ||
|
|
||
| ```bash | ||
| # Generate Team controller | ||
| ./bin/ako-controller-scaffolder --config ../atlas2crd/config.yaml --crd Team | ||
|
|
||
| # Generate Organization controller | ||
| ./bin/ako-controller-scaffolder --config ../atlas2crd/config.yaml --crd Organization | ||
|
|
||
| # Generate DatabaseUser controller | ||
| ./bin/ako-controller-scaffolder --config ../atlas2crd/config.yaml --crd DatabaseUser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: these refer to the config, but will they actually be the CRDs produced?
| └── service.go # Atlas SDK service interface | ||
| ``` | ||
|
|
||
| Generated controllers support all specified CRD versions. Translation layers stabs are generated per CRD version, using the Atlas SDK specified in the atlas2crd config file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo?
| Generated controllers support all specified CRD versions. Translation layers stabs are generated per CRD version, using the Atlas SDK specified in the atlas2crd config file | |
| Generated controllers support all specified CRD versions. Translation layers stubs are generated per CRD version, using the Atlas SDK specified in the atlas2crd config file |
|
|
||
| - **Dynamic API Mapping** - Automatically selects correct Atlas SDK API | ||
| - **State Machine Pattern** - Follows existing controller patterns | ||
| - **Translation Layer** - Converts between Kubernetes and Atlas types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: we were leaving this to the user and the translation lib right?
| type Config struct { | ||
| metav1.TypeMeta `yaml:",inline"` | ||
| Spec Spec `yaml:"spec"` | ||
| } | ||
|
|
||
| type Spec struct { | ||
| OpenAPI []OpenAPIConfig `yaml:"openapi,omitempty"` | ||
| CRD []CRDConfig `yaml:"crd,omitempty"` | ||
| } | ||
|
|
||
| type OpenAPIConfig struct { | ||
| Name string `yaml:"name"` | ||
| Package string `yaml:"package"` | ||
| } | ||
|
|
||
| type CRDConfig struct { | ||
| GVK metav1.GroupVersionKind `yaml:"gvk"` | ||
| Categories []string `yaml:"categories,omitempty"` | ||
| ShortNames []string `yaml:"shortNames,omitempty"` | ||
| Mappings []Mapping `yaml:"mappings,omitempty"` | ||
| } | ||
|
|
||
| type Mapping struct { | ||
| MajorVersion string `yaml:"majorVersion"` | ||
| OpenAPIRef OpenAPIRef `yaml:"openAPIRef"` | ||
| Parameters *Parameters `yaml:"parameters,omitempty"` | ||
| Entry *SchemaRef `yaml:"entry,omitempty"` | ||
| Status *SchemaRef `yaml:"status,omitempty"` | ||
| } | ||
|
|
||
| type OpenAPIRef struct { | ||
| Name string `yaml:"name"` | ||
| } | ||
|
|
||
| type Parameters struct { | ||
| Path *PathInfo `yaml:"path,omitempty"` | ||
| Query []QueryParam `yaml:"query,omitempty"` | ||
| Additional []interface{} `yaml:"additional,omitempty"` | ||
| } | ||
|
|
||
| type PathInfo struct { | ||
| Template string `yaml:"template"` | ||
| } | ||
|
|
||
| type QueryParam struct { | ||
| Name string `yaml:"name"` | ||
| Value string `yaml:"value"` | ||
| } | ||
|
|
||
| type SchemaRef struct { | ||
| Schema string `yaml:"$ref"` | ||
| } | ||
|
|
||
| // MappingWithConfig combines mapping with its OpenAPI config | ||
| type MappingWithConfig struct { | ||
| Mapping Mapping | ||
| OpenAPIConfig OpenAPIConfig | ||
| } | ||
|
|
||
| // ParsedConfig contains all parsed configuration data | ||
| type ParsedConfig struct { | ||
| Config Config | ||
| OpenAPIMap map[string]OpenAPIConfig | ||
| CRDMap map[string]CRDConfig | ||
| SelectedCRD CRDConfig | ||
| Mappings []MappingWithConfig | ||
| ResourceName string | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of these types are to be able to parse the CRD inputs right?
I was doing the same, then @s-urbaniak pointed me to the kube library that already supports all this. You can use that instead.
See:
https://github.com/mongodb/mongodb-atlas-kubernetes/blob/main/tools/crd2go/internal/crd/parse.go#L27
You want *apiextensionsv1.CustomResourceDefinition from:
import apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
josvazg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but please take the comments into account for follow up
Summary
Initial commit for Controller Scaffolder
Proof of Work
Checklist