Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/crd2go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# CRD2Go CI
name: CRD2Go CI

on:
push:
branches: [ "main" ]
paths:
- 'tools/crd2go/**'
pull_request:
branches: [ "main" ]
paths:
- 'tools/crd2go/**'

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
ref: ${{github.event.pull_request.head.sha}}

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'

- name: Build
working-directory: ./tools/crd2go
run: go build -v ./...

- name: Test
working-directory: ./tools/crd2go
run: go test -race -cover -v ./...

- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.1
working-directory: ./tools/crd2go

gci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
ref: ${{github.event.pull_request.head.sha}}

- name: Install devbox
uses: jetify-com/devbox-install-action@v0.13.0
with:
project-path: ./tools/crd2go
enable-cache: 'true'

- name: gci
working-directory: ./tools/crd2go
run: devbox run -- 'mage gci'

addlicense:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
ref: ${{github.event.pull_request.head.sha}}

- name: Install devbox
uses: jetify-com/devbox-install-action@v0.13.0
with:
project-path: ./tools/crd2go
enable-cache: 'true'

- name: Check license headers
working-directory: ./tools/crd2go
run: devbox run -- 'mage addlicense'
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ on:
- 'main'
paths-ignore:
- 'docs/**'
- 'tools/**'
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review, converted_to_draft, labeled]
branches:
- '**'
paths-ignore:
- 'docs/**'
- 'tools/**'
merge_group:
workflow_dispatch:
inputs:
Expand All @@ -25,6 +27,9 @@ on:
options:
- "true"
- "false"
paths-ignore:
- 'docs/**'
- 'tools/**'

jobs:
run-tests:
Expand Down
3 changes: 2 additions & 1 deletion tools/crd2go/cmd/crd2go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"

"github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go/internal/checkerr"
"github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go/internal/fileinput"
"github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go/pkg/config"
"github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go/pkg/crd2go"
)
Expand All @@ -41,7 +42,7 @@ func main() {
}

func generate(input, output, config string) (*config.Config, error) {
f, err := os.Open(config)
f, err := os.Open(fileinput.MustBeSafe(config))
if err != nil {
return nil, fmt.Errorf("failed to open configuration file: %w", err)
}
Expand Down
5 changes: 4 additions & 1 deletion tools/crd2go/cmd/updateSamples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"

"github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go/internal/checkerr"
"github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go/internal/fileinput"
"github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go/internal/run"
)

Expand Down Expand Up @@ -62,14 +63,16 @@ func updateSamples() error {
}

func downloadTo(url, filename string) (int64, error) {
// #nosec G107 URL is safe as we are just adding a token, it cannot be re-pathed
//nolint:noctx
rsp, err := http.Get(url)
if err != nil {
return 0, fmt.Errorf("failed to download from %s: %w", url, err)
}
if rsp.StatusCode != http.StatusOK {
return 0, fmt.Errorf("failed to request %s with status: %q", url, rsp.Status)
}
f, err := os.Create(filename)
f, err := os.Create(fileinput.MustBeSafe(filename))
if err != nil {
return 0, fmt.Errorf("failed to create file %s: %w", filename, err)
}
Expand Down
6 changes: 4 additions & 2 deletions tools/crd2go/devbox.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.14.0/.schema/devbox.schema.json",
"packages": [
"neovim@latest",
"git@latest",
"go@latest",
"vscodium@latest",
"kubernetes-controller-tools@latest",
"gh@latest",
"gci@latest",
"golangci-lint@latest"
"golangci-lint@latest",
"addlicense@latest",
"mage@latest",
],
"shell": {
"init_hook": [
Expand Down
144 changes: 132 additions & 12 deletions tools/crd2go/devbox.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
{
"lockfile_version": "1",
"packages": {
"addlicense@latest": {
"last_modified": "2025-07-28T17:09:23Z",
"resolved": "github:NixOS/nixpkgs/648f70160c03151bc2121d179291337ad6bc564b#addlicense",
"source": "devbox-search",
"version": "1.1.1",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/r3lhc2n8xj5ns43zrfdx1d4rsk6l0zgy-addlicense-1.1.1",
"default": true
}
],
"store_path": "/nix/store/r3lhc2n8xj5ns43zrfdx1d4rsk6l0zgy-addlicense-1.1.1"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/smjx8fp2r6ikxr6fv6vd9nws8j546hs3-addlicense-1.1.1",
"default": true
}
],
"store_path": "/nix/store/smjx8fp2r6ikxr6fv6vd9nws8j546hs3-addlicense-1.1.1"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/gpfw7kfm0rm4gcpnz2cgkb3d4zxyn32s-addlicense-1.1.1",
"default": true
}
],
"store_path": "/nix/store/gpfw7kfm0rm4gcpnz2cgkb3d4zxyn32s-addlicense-1.1.1"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/mxb6kb1b7lfklzmz020m0rdf7ppn0608-addlicense-1.1.1",
"default": true
}
],
"store_path": "/nix/store/mxb6kb1b7lfklzmz020m0rdf7ppn0608-addlicense-1.1.1"
}
}
},
"gci@latest": {
"last_modified": "2025-08-05T11:35:34Z",
"resolved": "github:NixOS/nixpkgs/a683adc19ff5228af548c6539dbc3440509bfed3#gci",
Expand Down Expand Up @@ -97,6 +145,78 @@
}
}
},
"git@latest": {
"last_modified": "2025-07-28T17:09:23Z",
"resolved": "github:NixOS/nixpkgs/648f70160c03151bc2121d179291337ad6bc564b#git",
"source": "devbox-search",
"version": "2.50.1",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/jn9byxgdjndngf0d2by0djg8gcdll7xc-git-2.50.1",
"default": true
},
{
"name": "doc",
"path": "/nix/store/j8djmq64ckbah7bl6jv1y6arrjr0shmv-git-2.50.1-doc"
}
],
"store_path": "/nix/store/jn9byxgdjndngf0d2by0djg8gcdll7xc-git-2.50.1"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/h4pvvix6pvnvys9a6y1xj2442r1ajdhl-git-2.50.1",
"default": true
},
{
"name": "doc",
"path": "/nix/store/q8sicpx16gyzxnp3345a46lj4cz9wd09-git-2.50.1-doc"
},
{
"name": "debug",
"path": "/nix/store/rpxnrnsn4nbx8wm9d2vrgj0fr5xzz5lg-git-2.50.1-debug"
}
],
"store_path": "/nix/store/h4pvvix6pvnvys9a6y1xj2442r1ajdhl-git-2.50.1"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/8d1n8cvi5x1j0v61459lvhqs26vmcqbl-git-2.50.1",
"default": true
},
{
"name": "doc",
"path": "/nix/store/yn9cvbs7jz4dfdb17qralgr0ybi5rmjf-git-2.50.1-doc"
}
],
"store_path": "/nix/store/8d1n8cvi5x1j0v61459lvhqs26vmcqbl-git-2.50.1"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/5i8zvall945kypmwgqd0y47f02pldwp4-git-2.50.1",
"default": true
},
{
"name": "debug",
"path": "/nix/store/l46kpjpcwwp8l7kzzr1s2dlk646r73z2-git-2.50.1-debug"
},
{
"name": "doc",
"path": "/nix/store/d2lhlzkdziwmijik8nszfwp8srbkskb9-git-2.50.1-doc"
}
],
"store_path": "/nix/store/5i8zvall945kypmwgqd0y47f02pldwp4-git-2.50.1"
}
}
},
"github:NixOS/nixpkgs/nixpkgs-unstable": {
"last_modified": "2025-05-04T22:22:57Z",
"resolved": "github:NixOS/nixpkgs/ed30f8aba41605e3ab46421e3dcb4510ec560ff8?lastModified=1746397377&narHash=sha256-5oLdRa3vWSRbuqPIFFmQBGGUqaYZBxX%2BGGtN9f%2Fn4lU%3D"
Expand Down Expand Up @@ -245,51 +365,51 @@
}
}
},
"neovim@latest": {
"last_modified": "2025-03-29T14:41:00Z",
"resolved": "github:NixOS/nixpkgs/eb0e0f21f15c559d2ac7633dc81d079d1caf5f5f#neovim",
"mage@latest": {
"last_modified": "2025-07-28T17:09:23Z",
"resolved": "github:NixOS/nixpkgs/648f70160c03151bc2121d179291337ad6bc564b#mage",
"source": "devbox-search",
"version": "0.11.0",
"version": "1.15.0",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/4ch16nz6lwmzlxhwr2lwc3wqy7khxbks-neovim-0.11.0",
"path": "/nix/store/ckcxxf6r85zndgx4rh3x3g570sysczf2-mage-1.15.0",
"default": true
}
],
"store_path": "/nix/store/4ch16nz6lwmzlxhwr2lwc3wqy7khxbks-neovim-0.11.0"
"store_path": "/nix/store/ckcxxf6r85zndgx4rh3x3g570sysczf2-mage-1.15.0"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/8av5ivxr1x3cymnbdfvf1izbx7998iiq-neovim-0.11.0",
"path": "/nix/store/1xln1pdk907lxm25dpdvx1xmp1rh43pd-mage-1.15.0",
"default": true
}
],
"store_path": "/nix/store/8av5ivxr1x3cymnbdfvf1izbx7998iiq-neovim-0.11.0"
"store_path": "/nix/store/1xln1pdk907lxm25dpdvx1xmp1rh43pd-mage-1.15.0"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/5bd60mhl94s6gl1cqi2xjra0ad8v2cdp-neovim-0.11.0",
"path": "/nix/store/gwwj202lbp3smjdmnff18xr4fm439sn4-mage-1.15.0",
"default": true
}
],
"store_path": "/nix/store/5bd60mhl94s6gl1cqi2xjra0ad8v2cdp-neovim-0.11.0"
"store_path": "/nix/store/gwwj202lbp3smjdmnff18xr4fm439sn4-mage-1.15.0"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/97cka40y26y30mza1v4gfbvlbp5a2a42-neovim-0.11.0",
"path": "/nix/store/8jyy6nrmi505iczgi7d19gddqk00qqc9-mage-1.15.0",
"default": true
}
],
"store_path": "/nix/store/97cka40y26y30mza1v4gfbvlbp5a2a42-neovim-0.11.0"
"store_path": "/nix/store/8jyy6nrmi505iczgi7d19gddqk00qqc9-mage-1.15.0"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions tools/crd2go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.24.3

require (
github.com/dave/jennifer v1.7.1
github.com/magefile/mage v1.15.0
github.com/stretchr/testify v1.10.0
golang.org/x/text v0.24.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
2 changes: 2 additions & 0 deletions tools/crd2go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
2 changes: 1 addition & 1 deletion tools/crd2go/internal/checkerr/checkerr.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ func CheckErr(msg string, f funcErrs) {
if err := f(); err != nil {
log.Printf("%s failed: %v", msg, err)
}
}
}
Loading