Skip to content

Commit 16000f7

Browse files
authored
CLOUDP-358677: Fix tools imports and CI (#2895)
* Add tools CI checks * Fix S1033 - Unnecessary guard around call to delete * Fix CI workflows * Refer to scaffolder go.mod * Draft fix for scaffolder unit-test * Make openapi2crd use its own devbox * Fix OpenAPI2CRD CI * Actually run OpenAPI2CRD within devbox * Properly fix scaffolder unit test
1 parent 269a6f5 commit 16000f7

File tree

9 files changed

+153
-10
lines changed

9 files changed

+153
-10
lines changed

.github/workflows/openapi2crd.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: OpenAPI2CRD tool CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- 'tools/openapi2crd/**'
8+
pull_request:
9+
branches: [ "main" ]
10+
paths:
11+
- 'tools/openapi2crd/**'
12+
13+
jobs:
14+
15+
openapi2crd:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v5
19+
20+
- name: Install devbox
21+
uses: jetify-com/[email protected]
22+
with:
23+
enable-cache: 'true'
24+
25+
- name: Update Devbox
26+
working-directory: ./tools/openapi2crd
27+
run: devbox update
28+
29+
- name: CI checks
30+
working-directory: ./tools/openapi2crd
31+
run: devbox run -- make ci

.github/workflows/scaffolder.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Scaffolder tool CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- 'tools/scaffolder/**'
8+
pull_request:
9+
branches: [ "main" ]
10+
paths:
11+
- 'tools/scaffolder/**'
12+
13+
jobs:
14+
15+
scaffolder:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v5
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v6
22+
with:
23+
go-version-file: "./tools/scaffolder/go.mod"
24+
25+
- name: CI checks
26+
working-directory: ./tools/scaffolder
27+
run: make ci

tools/openapi2crd/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ GO_FILES := $(shell find . -name '*.go' -not -path './vendor/*')
99
# Go packages for testing
1010
PACKAGES := $(shell go list ./...)
1111

12+
# GO TOOLS
13+
GCI := go tool -modfile=../toolbox/go.mod gci
14+
1215
crds: build ## Generate CRDs from config file
1316
@echo "==> Generating CRDs..."
1417
$(BINARY_PATH) --config config.yaml --output $(CRD_FILE)
@@ -26,7 +29,7 @@ $(BINARY_PATH): $(GO_FILES) ## File-based build target.
2629

2730
fmt: ## Format all Go code
2831
@echo "==> Formatting code..."
29-
@gci write -s standard -s default -s localmodule .
32+
$(GCI) write -s standard -s default -s localmodule .
3033

3134
unit-test: ## Run unit tests with race detection and coverage
3235
@echo "==> Running unit tests..."
@@ -41,4 +44,7 @@ all: gen-mock fmt unit-test build
4144
clean: ## Clean up built artifacts
4245
@echo "==> Cleaning..."
4346
@rm -f $(BINARY_PATH)
44-
@rm -f $(CRD_FILE)
47+
@rm -f $(CRD_FILE)
48+
49+
.PHONY: ci
50+
ci: all ## Standard CI tests

tools/openapi2crd/devbox.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.16.0/.schema/devbox.schema.json",
3+
"packages": [
4+
"path:../../flakes/go",
5+
"go-mockery@latest"
6+
],
7+
"shell": {
8+
"init_hook": [
9+
"echo 'Welcome to devbox!' > /dev/null"
10+
],
11+
"scripts": {
12+
"test": [
13+
"echo \"Error: no test specified\" && exit 1"
14+
]
15+
}
16+
}
17+
}

tools/openapi2crd/devbox.lock

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"lockfile_version": "1",
3+
"packages": {
4+
"github:NixOS/nixpkgs/nixpkgs-unstable": {
5+
"last_modified": "2025-11-08T12:28:21Z",
6+
"resolved": "github:NixOS/nixpkgs/f6b44b2401525650256b977063dbcf830f762369?lastModified=1762604901&narHash=sha256-Pr2jpryIaQr9Yx8p6QssS03wqB6UifnnLr3HJw9veDw%3D"
7+
},
8+
"go-mockery@latest": {
9+
"last_modified": "2025-10-22T20:59:19Z",
10+
"resolved": "github:NixOS/nixpkgs/01b6809f7f9d1183a2b3e081f0a1e6f8f415cb09#go-mockery",
11+
"source": "devbox-search",
12+
"version": "3.5.5",
13+
"systems": {
14+
"aarch64-darwin": {
15+
"outputs": [
16+
{
17+
"name": "out",
18+
"path": "/nix/store/qzzbjxgk4ai311ibriyyj91bn5z75520-go-mockery-3.5.5",
19+
"default": true
20+
}
21+
],
22+
"store_path": "/nix/store/qzzbjxgk4ai311ibriyyj91bn5z75520-go-mockery-3.5.5"
23+
},
24+
"aarch64-linux": {
25+
"outputs": [
26+
{
27+
"name": "out",
28+
"path": "/nix/store/3vg4ak5zdpdm46ny0q8x0f1275358n14-go-mockery-3.5.5",
29+
"default": true
30+
}
31+
],
32+
"store_path": "/nix/store/3vg4ak5zdpdm46ny0q8x0f1275358n14-go-mockery-3.5.5"
33+
},
34+
"x86_64-darwin": {
35+
"outputs": [
36+
{
37+
"name": "out",
38+
"path": "/nix/store/jvvan3ans4x2w1vkj46mnwma0y24i2xz-go-mockery-3.5.5",
39+
"default": true
40+
}
41+
],
42+
"store_path": "/nix/store/jvvan3ans4x2w1vkj46mnwma0y24i2xz-go-mockery-3.5.5"
43+
},
44+
"x86_64-linux": {
45+
"outputs": [
46+
{
47+
"name": "out",
48+
"path": "/nix/store/r9s8r5h3g448bp2qi20ym2h0plxgixbn-go-mockery-3.5.5",
49+
"default": true
50+
}
51+
],
52+
"store_path": "/nix/store/r9s8r5h3g448bp2qi20ym2h0plxgixbn-go-mockery-3.5.5"
53+
}
54+
}
55+
}
56+
}
57+
}

tools/openapi2crd/pkg/plugins/parameters.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ package plugins
1818
import (
1919
"fmt"
2020

21-
"github.com/mongodb/mongodb-atlas-kubernetes/tools/openapi2crd/pkg/converter"
22-
2321
"github.com/getkin/kin-openapi/openapi3"
2422
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
23+
24+
"github.com/mongodb/mongodb-atlas-kubernetes/tools/openapi2crd/pkg/converter"
2525
)
2626

2727
// Parameters adds parameters from the OpenAPI spec to the CRD schema.

tools/openapi2crd/pkg/plugins/skipped_properties.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package plugins
1818
import (
1919
"slices"
2020

21-
configv1alpha1 "github.com/mongodb/mongodb-atlas-kubernetestools/openapi2crd/pkg/apis/config/v1alpha1"
21+
configv1alpha1 "github.com/mongodb/mongodb-atlas-kubernetes/tools/openapi2crd/pkg/apis/config/v1alpha1"
2222
)
2323

2424
type SkippedProperties struct{}
@@ -40,9 +40,7 @@ func (p *SkippedProperties) Process(req *PropertyProcessorRequest) error {
4040
}
4141

4242
for _, s := range req.PropertyConfig.Filters.SkipProperties {
43-
if _, ok := requiredPaths[s]; ok {
44-
delete(requiredPaths, s)
45-
}
43+
delete(requiredPaths, s)
4644
}
4745

4846
req.Property.Required = make([]string, 0, len(req.Property.Required))

tools/scaffolder/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,11 @@ generate-all: build
3939
generate-all-override:
4040
$(BINARY_PATH) --input $(CRD_FILE) --all --override \
4141
--indexer-out $(INDEXER_OUT) \
42-
--controller-out $(CONTROLLER_OUT) \
42+
--controller-out $(CONTROLLER_OUT)
43+
44+
.PHONY: unit-test
45+
unit-test:
46+
go test -race -cover ./...
47+
48+
.PHONY: ci
49+
ci: build unit-test ## Standard CI tests

tools/scaffolder/internal/generate/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ spec:
464464
// Verify package-level getTranslationRequest function
465465
assert.Contains(t, contentStr, "func getTranslationRequest(")
466466
assert.Contains(t, contentStr, "ctx context.Context")
467-
assert.Contains(t, contentStr, "client client.Client")
467+
assert.Contains(t, contentStr, "k8sClient client.Client")
468468
assert.Contains(t, contentStr, "crdName string")
469469
assert.Contains(t, contentStr, "storageVersion string")
470470
assert.Contains(t, contentStr, "targetVersion string")

0 commit comments

Comments
 (0)