Skip to content

Conversation

@igor-karpukhin
Copy link
Collaborator

Summary

Initial commit for Controller Scaffolder

Proof of Work

Checklist

  • Have you linked a jira ticket and/or is the ticket in the title?
  • Have you checked whether your jira ticket required DOCSP changes?
  • Have you checked for release_note changes?
  • Have you signed our CLA?

@igor-karpukhin igor-karpukhin requested a review from a team as a code owner September 16, 2025 15:05
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
Copy link
Collaborator

@josvazg josvazg Sep 16, 2025

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
Copy link
Collaborator

@josvazg josvazg Sep 16, 2025

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?

Comment on lines +25 to +26
├── atlas-controller-scaffolder/ # This tool
├── atlas2crd/ # Config definitions
Copy link
Collaborator

@josvazg josvazg Sep 16, 2025

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?

Comment on lines +32 to +38
1. **Clone dependencies:**

```bash
cd ../
git clone https://github.com/mongodb-atlas-kubernetes/atlas2crd
git clone https://github.com/mongodb/mongodb-atlas-kubernetes
```
Copy link
Collaborator

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?

Comment on lines +40 to +45
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
```
Copy link
Collaborator

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.

Comment on lines +47 to +54
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
```
Copy link
Collaborator

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.

Comment on lines +65 to +87
### 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
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

Suggested change
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
Copy link
Collaborator

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?

Comment on lines +26 to +93
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
}
Copy link
Collaborator

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"

Copy link
Collaborator

@josvazg josvazg left a 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

@igor-karpukhin igor-karpukhin merged commit c835b7f into main Sep 16, 2025
21 of 22 checks passed
@igor-karpukhin igor-karpukhin deleted the feature/controller-scaffolder branch September 16, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants