Skip to content

Commit 23feb82

Browse files
authored
CLOUDP-349631: Autogen pipeline (#2858)
1 parent d033a4d commit 23feb82

File tree

10 files changed

+165
-7024
lines changed

10 files changed

+165
-7024
lines changed

.github/workflows/autogen.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Autogenerate AKO
2+
on:
3+
workflow_dispatch:
4+
jobs:
5+
autogen:
6+
runs-on: ubuntu-latest
7+
outputs:
8+
version: ${{ steps.build-version.outputs.version }}
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v5
12+
- name: Set up Go
13+
uses: actions/setup-go@v5
14+
with:
15+
go-version-file: "./go.mod"
16+
cache: true
17+
- name: Install controller-gen and kustomize
18+
run: |
19+
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.17.2
20+
go install sigs.k8s.io/kustomize/kustomize/v5@v5.7.1
21+
go get go.mongodb.org/atlas-sdk/v20250312008@v20250312008.0.0
22+
go get github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go
23+
24+
controller-gen --version
25+
kustomize version
26+
- name: Generate CRDs
27+
run: |
28+
make gen-crds
29+
- name: Generate Go types
30+
run: |
31+
make gen-go-types
32+
- name: Run Operator Scaffolder
33+
run: |
34+
make run-scaffolder
35+
- name: Build Version
36+
id: build-version
37+
run: |
38+
GITCOMMIT=$(git rev-parse --short HEAD)
39+
VERSION=$(jq -r .next version.json)-EXPERIMENTAL-${GITCOMMIT}
40+
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
41+
- name: Log in to the Container Registry
42+
uses: docker/login-action@v3
43+
with:
44+
registry: ghcr.io
45+
username: ${{ github.actor }}
46+
password: ${{ secrets.GITHUB_TOKEN }}
47+
- name: Build Operator
48+
env:
49+
EXPERIMENTAL: true
50+
OPERATOR_IMAGE: "ghcr.io/${{ github.repository_owner }}/mongodb-atlas-kubernetes-operator-prerelease:${{ steps.build-version.outputs.version }}"
51+
run: |
52+
make image
53+
- name: (Auto)Generated manifests
54+
env:
55+
OPERATOR_IMAGE: "ghcr.io/${{ github.repository_owner }}/mongodb-atlas-kubernetes-operator-prerelease:${{ steps.build-version.outputs.version }}"
56+
run: |
57+
make deploy/generated/all-in-one.yaml
58+
- name: Upload All-in-One (autogenerated) manifest
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: all-in-one-autogen-manifest
62+
path: ./deploy/generated/all-in-one.yaml
63+
retention-days: 1

Makefile

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ RELEASE_ALLINONE := config/release/$(ENV)/allinone
170170
RELEASE_CLUSTERWIDE := config/release/$(ENV)/clusterwide
171171
RELEASE_OPENSHIFT := config/release/$(ENV)/openshift
172172
RELEASE_NAMESPACED := config/release/$(ENV)/namespaced
173+
RELEASE_AUTOGENERATED := config/generated
173174

174175
# --- File Targets ---
175176
ALL_IN_ONE_CONFIG := $(TARGET_DIR)/all-in-one.yaml
@@ -179,6 +180,7 @@ NAMESPACED_CONFIG := $(NAMESPACED_DIR)/namespaced-config.yaml
179180
NAMESPACED_CRDS := $(NAMESPACED_DIR)/crds.yaml
180181
OPENSHIFT_CONFIG := $(OPENSHIFT_DIR)/openshift.yaml
181182
OPENSHIFT_CRDS := $(OPENSHIFT_DIR)/crds.yaml
183+
ALL_IN_ONE_AUTOGENERATED_CONFIG := $(TARGET_DIR)/generated/all-in-one.yaml
182184
CSV_FILE := $(BUNDLE_MANIFESTS_DIR)/mongodb-atlas-kubernetes.clusterserviceversion.yaml
183185
BUNDLE_DOCKERFILE := bundle.Dockerfile
184186

@@ -816,14 +818,28 @@ clean-bundle:
816818
@rm -f $(BUNDLE_DOCKERFILE)
817819
@echo "✅ Cleanup complete."
818820

819-
autogenerated-manifests: manifests update-manager-kustomization
821+
rbac-autogen:
822+
$(CONTROLLER_GEN) rbac:roleName=generated-manager-role paths="./internal/generated/controller/..." output:rbac:artifacts:config=config/generated/rbac
823+
@$(AWK) '/---/{f="xx0"int(++i);} {if(NF!=0)print > f};' config/generated/rbac/role.yaml # Keeping only ClusterRole part while building only all-in-one config
824+
@rm config/generated/rbac/role.yaml
825+
@mv xx01 config/generated/rbac/role.yaml
826+
827+
$(ALL_IN_ONE_AUTOGENERATED_CONFIG): manifests update-manager-kustomization rbac-autogen
820828
@echo "Creating directory..."
821829
@mkdir -p $(TARGET_DIR)/generated
822-
@$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/generated > $(TARGET_DIR)/generated/allinone.yaml
823-
824-
.PHONY: gen-all
825-
gen-all:
826-
$(MAKE) -C tools/openapi2crd crds-force
827-
$(MAKE) -C tools/crd2go build
828-
cd tools/crd2go && ./crd2go -input ../openapi2crd/crds.yaml -output ../../internal/nextapi/v1
829-
$(MAKE) -C tools/scaffolder generate-all
830+
@$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone $(RELEASE_AUTOGENERATED) > $@
831+
@echo "Created $@"
832+
833+
gen-crds:
834+
BINARY_DIR=$(realpath .)/bin CRD_FILE=$(realpath .)/config/generated/crd/bases/crds.yaml $(MAKE) -C tools/openapi2crd crds
835+
836+
gen-go-types:
837+
BINARY_DIR=$(realpath .)/bin CRD_FILE=$(realpath .)/config/generated/crd/bases/crds.yaml OUTPUT_DIR=$(realpath .)/internal/nextapi/generated/v1 $(MAKE) -C tools/crd2go generate
838+
839+
run-scaffolder:
840+
BINARY_DIR=$(realpath .)/bin CRD_FILE=$(realpath .)/config/generated/crd/bases/crds.yaml $(MAKE) -C tools/scaffolder generate-all
841+
842+
gen-all: gen-crds gen-go-types run-scaffolder
843+
844+
build-autogen: gen-all $(ALL_IN_ONE_AUTOGENERATED_CONFIG)
845+
EXPERIMENTAL=1 VERSION=$(shell $(JQ) -r .next $(VERSION_FILE))-EXPERIMENTAL-${GITCOMMIT} $(MAKE) image

config/generated/kustomization.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ labels:
1212
includeSelectors: true
1313

1414
resources:
15+
- ../manager
1516
- crd
1617
- ../crd
17-
- ../manager
1818
- rbac # -> autogenerated RBAC
1919
- ../rbac/clusterwide
20+
21+
patches:
22+
- path: ../release/dev/dev_patch.json
23+
target:
24+
group: apps
25+
version: v1
26+
kind: Deployment
27+
name: operator
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
resources:
22
- role.yaml
3+
- role_binding.yaml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRoleBinding
3+
metadata:
4+
name: generated-manager-rolebinding
5+
roleRef:
6+
apiGroup: rbac.authorization.k8s.io
7+
kind: ClusterRole
8+
name: generated-manager-role
9+
subjects:
10+
- kind: ServiceAccount
11+
name: operator

test/helper/e2e2/yml/yml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"sigs.k8s.io/controller-runtime/pkg/client"
3636

3737
akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1"
38-
akov2next "github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/nextapi/v1"
38+
akov2next "github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/nextapi/generated/v1"
3939
)
4040

4141
var (

tools/crd2go/Makefile

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
.PHONY: crds
2-
crds:
3-
@echo "Making crds..."
1+
# Define the output binary location
2+
BINARY_DIR ?= bin
3+
BINARY_NAME := crd2go
4+
BINARY_PATH := $(BINARY_DIR)/$(BINARY_NAME)
45

5-
.PHONY: build
6-
build:
7-
go build -o crd2go cmd/crd2go/main.go
6+
# Define the generated CRD file
7+
CRD_FILE ?= pkg/crd2go/samples/crds.yaml
8+
# Define the output directory for generated Go models
9+
OUTPUT_DIR ?= pkg/crd2go/samples/v1
10+
11+
build: clean $(BINARY_PATH) ## Build the binary
12+
13+
$(BINARY_PATH): $(GO_FILES) ## File-based build target.
14+
@echo "==> Building $(BINARY_PATH)..."
15+
@mkdir -p $(BINARY_DIR)
16+
@go build -o $(BINARY_PATH) cmd/crd2go/main.go
17+
18+
clean:
19+
@echo "==> Cleaning..."
20+
@rm -f $(BINARY_PATH)
21+
22+
generate: build
23+
@echo "==> Generating Go models from CRDs..."
24+
@$(BINARY_PATH) --input $(CRD_FILE) --output $(OUTPUT_DIR)

tools/openapi2crd/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# Define the output binary location
2-
BINARY_DIR := bin
2+
BINARY_DIR ?= bin
33
BINARY_NAME := openapi2crd
44
BINARY_PATH := $(BINARY_DIR)/$(BINARY_NAME)
55
# Define the generated CRD file
6-
CRD_FILE := crds.yaml
6+
CRD_FILE ?= crds.yaml
77
# Go source files (excluding vendor)
88
GO_FILES := $(shell find . -name '*.go' -not -path './vendor/*')
99
# Go packages for testing
1010
PACKAGES := $(shell go list ./...)
1111

12-
crds: ## Generate CRDs from config file
12+
crds: build ## Generate CRDs from config file
1313
@echo "==> Generating CRDs..."
14-
@go run main.go --config config.yaml --output $(CRD_FILE)
14+
$(BINARY_PATH) --config config.yaml --output $(CRD_FILE)
1515

1616
crds-force: ## Generate CRDs from config file
1717
@echo "==> Generating CRDs..."
1818
@go run main.go --config config.yaml --force --output $(CRD_FILE)
1919

20-
build: $(BINARY_PATH) ## Build the binary
20+
build: clean $(BINARY_PATH) ## Build the binary
2121

2222
$(BINARY_PATH): $(GO_FILES) ## File-based build target.
2323
@echo "==> Building $(BINARY_PATH)..."

0 commit comments

Comments
 (0)