├── .github ├── PULL_REQUEST_TEMPLATE │ ├── breaking_change.md │ ├── bug_fix.md │ ├── compat_feature.md │ ├── docs.md │ └── other.md ├── dependabot.yml ├── pull_request_template.md └── workflows │ ├── golangci-lint.yml │ ├── pr-dependabot.yaml │ ├── pr-gh-workflow-approve.yaml │ ├── release.yaml │ ├── tools-releases.yml │ └── verify.yml ├── .gitignore ├── .golangci.yml ├── .run-controller-gen.sh ├── .run-in.sh ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── OWNERS ├── OWNERS_ALIASES ├── README.md ├── RELEASE.md ├── SECURITY_CONTACTS ├── VERSIONING.md ├── boilerplate.go.txt ├── cmd ├── controller-gen │ └── main.go ├── helpgen │ └── main.go └── type-scaffold │ └── main.go ├── code-of-conduct.md ├── envtest-releases.yaml ├── go.mod ├── go.sum ├── hack ├── envtest │ ├── _matrix │ │ ├── v1.23.5.yaml │ │ ├── v1.24.1.yaml │ │ ├── v1.24.2.yaml │ │ ├── v1.25.0.yaml │ │ ├── v1.26.0.yaml │ │ ├── v1.26.1.yaml │ │ ├── v1.27.1.yaml │ │ ├── v1.28.0.yaml │ │ ├── v1.28.3.yaml │ │ ├── v1.29.0.yaml │ │ ├── v1.29.1.yaml │ │ ├── v1.29.3.yaml │ │ ├── v1.29.4.yaml │ │ ├── v1.29.5.yaml │ │ ├── v1.30.0.yaml │ │ ├── v1.30.2.yaml │ │ ├── v1.30.3.yaml │ │ ├── v1.31.0-beta.0.yaml │ │ ├── v1.31.0.yaml │ │ ├── v1.32.0.yaml │ │ ├── v1.33.0-alpha.2.yaml │ │ └── v1.33.0.yaml │ ├── darwin │ │ └── Dockerfile │ ├── linux │ │ └── Dockerfile │ ├── update-releases.sh │ └── windows │ │ └── Dockerfile ├── go-install.sh ├── tools │ └── .keep └── verify-pr-title.sh ├── pkg ├── applyconfiguration │ ├── applyconfiguration_integration_test.go │ ├── applyconfiguration_suite_test.go │ ├── doc.go │ ├── gen.go │ ├── testdata │ │ └── cronjob │ │ │ ├── api │ │ │ └── v1 │ │ │ │ ├── applyconfiguration │ │ │ │ ├── api │ │ │ │ │ └── v1 │ │ │ │ │ │ ├── associativetype.go │ │ │ │ │ │ ├── containsnestedmap.go │ │ │ │ │ │ ├── cronjob.go │ │ │ │ │ │ ├── cronjobspec.go │ │ │ │ │ │ ├── cronjobstatus.go │ │ │ │ │ │ ├── duration.go │ │ │ │ │ │ ├── embeddedstruct.go │ │ │ │ │ │ ├── empiableobject.go │ │ │ │ │ │ ├── exportedstruct.go │ │ │ │ │ │ ├── justnestedobject.go │ │ │ │ │ │ ├── minmaxobject.go │ │ │ │ │ │ ├── nestedobject.go │ │ │ │ │ │ ├── nestedstructwithseveralfields.go │ │ │ │ │ │ ├── preserved.go │ │ │ │ │ │ ├── rootobject.go │ │ │ │ │ │ └── unexportedstruct.go │ │ │ │ ├── internal │ │ │ │ │ └── internal.go │ │ │ │ └── utils.go │ │ │ │ ├── cronjob_types.go │ │ │ │ └── groupversion_info.go │ │ │ ├── go.mod │ │ │ └── go.sum │ └── zz_generated.markerhelp.go ├── crd │ ├── conv.go │ ├── crd_spec_test.go │ ├── crd_suite_test.go │ ├── desc_visitor.go │ ├── desc_visitor_test.go │ ├── doc.go │ ├── flatten.go │ ├── flatten_all_of_test.go │ ├── flatten_type_test.go │ ├── gen.go │ ├── gen_integration_test.go │ ├── known_types.go │ ├── markers │ │ ├── crd.go │ │ ├── doc.go │ │ ├── package.go │ │ ├── priority.go │ │ ├── register.go │ │ ├── topology.go │ │ ├── validation.go │ │ └── zz_generated.markerhelp.go │ ├── parser.go │ ├── parser_integration_test.go │ ├── schema.go │ ├── schema_test.go │ ├── schema_visitor.go │ ├── spec.go │ ├── testdata │ │ ├── README.md │ │ ├── cronjob_types.go │ │ ├── deprecated │ │ │ └── types.go │ │ ├── gen │ │ │ ├── bar.example.com_foos.v1beta1.yaml │ │ │ ├── bar.example.com_foos.yaml │ │ │ ├── bar.example.com_foos_maxdesclen.yaml │ │ │ ├── foo_types.go │ │ │ └── zoo │ │ │ │ ├── bar.example.com_zoos.v1beta1.yaml │ │ │ │ ├── bar.example.com_zoos.yaml │ │ │ │ └── zoo_types.go │ │ ├── go.mod │ │ ├── go.sum │ │ ├── internal_version │ │ │ └── internal_types.go │ │ ├── job │ │ │ └── types.go │ │ ├── multiple_versions │ │ │ ├── common.go │ │ │ ├── testdata.kubebuilder.io_versionedresources.yaml │ │ │ ├── v1beta1 │ │ │ │ └── types.go │ │ │ └── v1beta2 │ │ │ │ └── types.go │ │ ├── nogroup │ │ │ └── types.go │ │ ├── plural │ │ │ ├── plural.example.com_testquotas.yaml │ │ │ └── types.go │ │ ├── testdata._cronjobs.yaml │ │ ├── testdata.kubebuilder.io_cronjobs.yaml │ │ ├── testdata.kubebuilder.io_jobs.yaml │ │ ├── unserved │ │ │ └── types.go │ │ ├── wrong_annotation_format │ │ │ └── cronjob_types.go │ │ └── wrong_title_format │ │ │ └── types.go │ └── zz_generated.markerhelp.go ├── deepcopy │ ├── deepcopy_integration_test.go │ ├── deepcopy_suite_test.go │ ├── doc.go │ ├── gen.go │ ├── testdata │ │ ├── README.md │ │ ├── cronjob_types.go │ │ ├── go.mod │ │ ├── go.sum │ │ ├── legacy_deepcopy_cases.go │ │ └── zz_generated.deepcopy.go │ ├── traverse.go │ └── zz_generated.markerhelp.go ├── genall │ ├── doc.go │ ├── genall.go │ ├── help │ │ ├── doc.go │ │ ├── pretty │ │ │ ├── doc.go │ │ │ ├── help.go │ │ │ ├── print.go │ │ │ └── table.go │ │ ├── sort.go │ │ └── types.go │ ├── input.go │ ├── options.go │ ├── output.go │ └── zz_generated.markerhelp.go ├── loader │ ├── doc.go │ ├── errors.go │ ├── loader.go │ ├── loader_suite_test.go │ ├── loader_test.go │ ├── paths.go │ ├── refs.go │ ├── testmod │ │ ├── dummy.go │ │ ├── go.mod │ │ ├── subdir1 │ │ │ ├── dummy.go │ │ │ ├── subdir1 │ │ │ │ └── dummy.go │ │ │ ├── subdir2 │ │ │ │ └── dummy.go │ │ │ └── submod1 │ │ │ │ ├── dummy.go │ │ │ │ └── go.mod │ │ └── submod1 │ │ │ ├── dummy.go │ │ │ ├── go.mod │ │ │ └── subdir1 │ │ │ └── dummy.go │ ├── testutils │ │ └── helpers.go │ └── visit.go ├── markers │ ├── collect.go │ ├── collect_test.go │ ├── doc.go │ ├── help.go │ ├── markers_suite_test.go │ ├── parse.go │ ├── parse_test.go │ ├── reg.go │ ├── regutil.go │ └── zip.go ├── rbac │ ├── parser.go │ ├── parser_integration_test.go │ ├── rbac_suite_test.go │ ├── testdata │ │ ├── README.md │ │ ├── controller.go │ │ └── role.yaml │ └── zz_generated.markerhelp.go ├── schemapatcher │ ├── crdschema_suite_test.go │ ├── gen.go │ ├── gen_integration_test.go │ ├── internal │ │ └── yaml │ │ │ ├── convert.go │ │ │ ├── delete_test.go │ │ │ ├── nested.go │ │ │ ├── nested_test.go │ │ │ ├── set.go │ │ │ ├── set_test.go │ │ │ └── yaml_suite_test.go │ ├── testdata │ │ ├── Makefile │ │ ├── README.md │ │ ├── apis │ │ │ ├── kubebuilder │ │ │ │ └── v1 │ │ │ │ │ ├── doc.go │ │ │ │ │ ├── types_example.go │ │ │ │ │ └── types_unchanged.go │ │ │ └── legacy │ │ │ │ └── v1 │ │ │ │ ├── doc.go │ │ │ │ ├── types_example.go │ │ │ │ └── types_unchanged.go │ │ ├── expected │ │ │ ├── kubebuilder-example-crd.v1.yaml │ │ │ └── kubebuilder-unchanged-crd.yaml │ │ ├── go.mod │ │ ├── go.sum │ │ ├── invalid │ │ │ ├── kubebuilder-example-crd.v1.yaml │ │ │ └── kubebuilder-example-crd.yaml │ │ └── valid │ │ │ ├── example.cr.yaml │ │ │ ├── kubebuilder-example-crd.v1.yaml │ │ │ ├── kubebuilder-unchanged-crd.yaml │ │ │ └── random.yaml │ └── zz_generated.markerhelp.go ├── typescaffold │ ├── resource.go │ ├── scaffold.go │ └── scaffold_test.go ├── version │ ├── version.go │ ├── version_suite_test.go │ └── version_test.go └── webhook │ ├── parser.go │ ├── parser_integration_test.go │ ├── testdata │ ├── README.md │ ├── cronjob_types.go │ ├── go.mod │ ├── go.sum │ ├── invalid-admissionReviewVersionsRequired │ │ ├── cronjob_types.go │ │ ├── manifests.yaml │ │ └── webhook.go │ ├── invalid-multiple-webhookconfigurations │ │ ├── cronjob_types.go │ │ └── webhook.go │ ├── invalid-path-and-url │ │ ├── cronjob_types.go │ │ └── webhook.go │ ├── invalid-sideEffects │ │ ├── cronjob_types.go │ │ ├── manifests.yaml │ │ └── webhook.go │ ├── invalid-timeoutSeconds │ │ ├── cronjob_types.go │ │ ├── manifests.yaml │ │ └── webhook.go │ ├── invalid-v1beta1NotSupported │ │ ├── cronjob_types.go │ │ ├── manifests.yaml │ │ └── webhook.go │ ├── manifests.yaml │ ├── valid-custom-name │ │ ├── cronjob_types.go │ │ ├── manifests.yaml │ │ └── webhook.go │ ├── valid-custom-service │ │ ├── cronjob_types.go │ │ ├── manifests.yaml │ │ └── webhook.go │ ├── valid-ordered │ │ ├── cronjob_types.go │ │ ├── manifests.yaml │ │ └── webhook.go │ ├── valid-url │ │ ├── cronjob_types.go │ │ ├── manifests.yaml │ │ └── webhook.go │ ├── valid │ │ ├── cronjob_types.go │ │ ├── manifests.yaml │ │ └── webhook.go │ └── webhook.go │ ├── webhook_suite_test.go │ └── zz_generated.markerhelp.go └── test.sh /.github/PULL_REQUEST_TEMPLATE/breaking_change.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/bug_fix.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/compat_feature.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/docs.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/other.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Please see the documentation for all configuration options: 2 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 3 | version: 2 4 | updates: 5 | # GitHub Actions 6 | - package-ecosystem: "github-actions" 7 | # Workflow files stored in the 8 | # default location of `.github/workflows` 9 | directory: "/" 10 | schedule: 11 | interval: "weekly" 12 | groups: 13 | all-github-actions: 14 | patterns: [ "*" ] 15 | commit-message: 16 | prefix: ":seedling:" 17 | labels: 18 | - "ok-to-test" 19 | 20 | # Go modules 21 | - package-ecosystem: "gomod" 22 | directory: "/" 23 | schedule: 24 | interval: "weekly" 25 | # group all dependencies with a k8s.io prefix into a single PR. 26 | groups: 27 | all-go-mod-patch-and-minor: 28 | patterns: [ "*" ] 29 | update-types: [ "patch", "minor" ] 30 | ignore: 31 | # Ignore k8s and its transitives modules as they are upgraded manually. 32 | - dependency-name: "k8s.io/*" 33 | update-types: [ "version-update:semver-major", "version-update:semver-minor" ] 34 | commit-message: 35 | prefix: ":seedling:" 36 | labels: 37 | - "ok-to-test" 38 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.github/workflows/golangci-lint.yml: -------------------------------------------------------------------------------- 1 | name: golangci-lint 2 | on: 3 | pull_request: 4 | types: [opened, edited, synchronize, reopened] 5 | branches: 6 | - main 7 | 8 | permissions: 9 | # Required: allow read access to the content for analysis. 10 | contents: read 11 | # Optional: allow read access to pull request. Use with `only-new-issues` option. 12 | pull-requests: read 13 | # Optional: Allow write access to checks to allow the action to annotate code in the PR. 14 | checks: write 15 | 16 | jobs: 17 | golangci: 18 | name: lint 19 | runs-on: ubuntu-latest 20 | strategy: 21 | matrix: 22 | working-directory: 23 | - "" 24 | steps: 25 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v4.2.2 26 | - name: Calculate go version 27 | id: vars 28 | run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT 29 | - name: Set up Go 30 | uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # tag=v5.5.0 31 | with: 32 | go-version: ${{ steps.vars.outputs.go_version }} 33 | - name: golangci-lint 34 | uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # tag=v8.0.0 35 | with: 36 | version: v2.1.6 37 | args: --output.text.print-linter-name=true --output.text.colors=true --timeout 10m 38 | working-directory: ${{matrix.working-directory}} 39 | -------------------------------------------------------------------------------- /.github/workflows/pr-dependabot.yaml: -------------------------------------------------------------------------------- 1 | name: PR dependabot go modules fix 2 | 3 | # This action runs on PRs opened by dependabot and updates modules. 4 | on: 5 | pull_request: 6 | branches: 7 | - dependabot/** 8 | push: 9 | branches: 10 | - dependabot/** 11 | workflow_dispatch: 12 | 13 | permissions: 14 | contents: write # Allow to update the PR. 15 | 16 | jobs: 17 | build: 18 | name: Build 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Check out code 22 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v4.2.2 23 | - name: Calculate go version 24 | id: vars 25 | run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT 26 | - name: Set up Go 27 | uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # tag=v5.5.0 28 | with: 29 | go-version: ${{ steps.vars.outputs.go_version }} 30 | - name: Update all modules 31 | run: make modules 32 | - uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # tag=v9.1.4 33 | name: Commit changes 34 | with: 35 | author_name: dependabot[bot] 36 | author_email: 49699333+dependabot[bot]@users.noreply.github.com 37 | default_author: github_actor 38 | message: 'Update generated code' 39 | -------------------------------------------------------------------------------- /.github/workflows/pr-gh-workflow-approve.yaml: -------------------------------------------------------------------------------- 1 | name: PR approve GH Workflows 2 | 3 | on: 4 | pull_request_target: 5 | types: 6 | - edited 7 | - labeled 8 | - reopened 9 | - synchronize 10 | 11 | permissions: {} 12 | 13 | jobs: 14 | approve: 15 | name: Approve ok-to-test 16 | if: contains(github.event.pull_request.labels.*.name, 'ok-to-test') 17 | runs-on: ubuntu-latest 18 | permissions: 19 | actions: write 20 | steps: 21 | - name: Update PR 22 | uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 23 | continue-on-error: true 24 | with: 25 | github-token: ${{ secrets.GITHUB_TOKEN }} 26 | script: | 27 | const result = await github.rest.actions.listWorkflowRunsForRepo({ 28 | owner: context.repo.owner, 29 | repo: context.repo.repo, 30 | event: "pull_request", 31 | status: "action_required", 32 | head_sha: context.payload.pull_request.head.sha, 33 | per_page: 100 34 | }); 35 | 36 | for (var run of result.data.workflow_runs) { 37 | await github.rest.actions.approveWorkflowRun({ 38 | owner: context.repo.owner, 39 | repo: context.repo.repo, 40 | run_id: run.id 41 | }); 42 | } 43 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Upload binaries to release 2 | 3 | on: 4 | push: 5 | # Sequence of patterns matched against refs/tags 6 | tags: 7 | - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 (not envtest-*) 8 | 9 | permissions: 10 | contents: write 11 | 12 | jobs: 13 | build: 14 | name: Upload binaries to release 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Set env 18 | run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV 19 | - name: Check out code 20 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v4.2.2 21 | - name: Calculate go version 22 | id: vars 23 | run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT 24 | - name: Set up Go 25 | uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # tag=v5.5.0 26 | with: 27 | go-version: ${{ steps.vars.outputs.go_version }} 28 | - name: Generate release binaries 29 | run: | 30 | make release-controller-gen 31 | - name: Release 32 | uses: softprops/action-gh-release@da05d552573ad5aba039eaac05058a918a7bf631 # tag=v2.2.2 33 | with: 34 | draft: false 35 | files: out/* 36 | -------------------------------------------------------------------------------- /.github/workflows/verify.yml: -------------------------------------------------------------------------------- 1 | name: PR title verifier 2 | 3 | on: 4 | pull_request_target: 5 | types: [opened, edited, synchronize, reopened] 6 | 7 | jobs: 8 | verify: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v4.2.2 13 | 14 | - name: Check if PR title is valid 15 | env: 16 | PR_TITLE: ${{ github.event.pull_request.title }} 17 | run: | 18 | ./hack/verify-pr-title.sh "${PR_TITLE}" 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # editor stuff 15 | .idea 16 | *.swp 17 | *.swo 18 | *~ 19 | 20 | # Tools binaries. 21 | out 22 | hack/tools/bin 23 | 24 | junit-report.xml 25 | /artifacts 26 | -------------------------------------------------------------------------------- /.run-controller-gen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This builds and runs controller-gen in a particular context 4 | # it's the equivalent of `go run sigs.k8s.io/controller-tools/cmd/controller-gen` 5 | # if you could somehow do that without modifying your go.mod. 6 | 7 | set -o errexit 8 | set -o nounset 9 | set -o pipefail 10 | 11 | readlink=$(command -v readlink) 12 | 13 | check_readlink() { 14 | local test_file="$(mktemp)" 15 | trap "rm -f $test_file" EXIT 16 | if ! ${readlink} -f "$test_file" &>/dev/null; then 17 | if [[ "${OSTYPE}" == "darwin"* ]]; then 18 | if command -v greadlink; then 19 | readlink=$(command -v greadlink) 20 | return 21 | fi 22 | fi 23 | echo "you're probably on OSX. Please install gnu readlink -- otherwise you're missing the most useful readlink flag." 24 | exit 1 25 | fi 26 | } 27 | current_dir=$(pwd) 28 | check_readlink 29 | cd $(dirname $(${readlink} -f ${BASH_SOURCE[0]})) 30 | go run -v -exec "./.run-in.sh ${current_dir} " ./cmd/controller-gen $@ 31 | -------------------------------------------------------------------------------- /.run-in.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # run something in a directory 4 | # goes hand-in .run-controller-gen.sh 5 | 6 | cd $1 7 | shift 8 | $@ 9 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing guidelines 2 | 3 | ## Sign the CLA 4 | 5 | Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests. Please see https://git.k8s.io/community/CLA.md for more info 6 | 7 | ### Contributing A Patch 8 | 9 | 1. Submit an issue describing your proposed change to the repo in question. 10 | 1. The [repo owners](OWNERS) will respond to your issue promptly. 11 | 1. If your proposed change is accepted, and you haven't already done so, sign a Contributor License Agreement (see details above). 12 | 1. Fork the desired repo, develop and test your code changes. 13 | 1. Submit a pull request. 14 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md 2 | 3 | approvers: 4 | - controller-tools-admins 5 | - controller-tools-approvers 6 | - controller-tools-maintainers 7 | reviewers: 8 | - controller-tools-reviewers 9 | - controller-tools-admins 10 | - controller-tools-approvers 11 | -------------------------------------------------------------------------------- /OWNERS_ALIASES: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md 2 | 3 | aliases: 4 | # active folks who can be contacted to perform admin-related 5 | # tasks on the repo, or otherwise approve any PRS. 6 | controller-tools-admins: 7 | - vincepri 8 | - joelanford 9 | 10 | # non-admin folks who can approve any PRs in the repo 11 | controller-tools-maintainers: 12 | - alvaroaleman 13 | - sbueringer 14 | 15 | # non-admin folks who can approve any PRs in the repo 16 | controller-tools-approvers: [] 17 | 18 | # folks who can review and LGTM any PRs in the repo (doesn't 19 | # include approvers & admins -- those count too via the OWNERS 20 | # file) 21 | controller-tools-reviewers: 22 | - chrischdi 23 | - JoelSpeed 24 | 25 | # folks who may have context on ancient history, 26 | # but are no longer directly involved 27 | controller-tools-emeritus-maintainers: 28 | - directxman12 29 | - droot 30 | - mengqiy 31 | - pwittrock 32 | -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | # Release Process 2 | 3 | The Kubernetes controller-tools Project is released on an as-needed basis. The process is as follows: 4 | 5 | 1. An issue is proposing a new release with a changelog since the last release 6 | 1. 2 [OWNERS](OWNERS) must LGTM this release 7 | 1. An OWNER runs `git tag -s $VERSION` and inserts the changelog and pushes the tag with `git push $VERSION` 8 | 1. The release issue is closed 9 | -------------------------------------------------------------------------------- /SECURITY_CONTACTS: -------------------------------------------------------------------------------- 1 | # Defined below are the security contacts for this repo. 2 | # 3 | # They are the contact point for the Product Security Team to reach out 4 | # to for triaging and handling of incoming issues. 5 | # 6 | # The below names agree to abide by the 7 | # [Embargo Policy](https://github.com/kubernetes/sig-release/blob/master/security-release-process-documentation/security-release-process.md#embargo-policy) 8 | # and will be removed and replaced if they violate that agreement. 9 | # 10 | # DO NOT REPORT SECURITY VULNERABILITIES DIRECTLY TO THESE NAMES, FOLLOW THE 11 | # INSTRUCTIONS AT https://kubernetes.io/security/ 12 | 13 | pwittrock 14 | droot 15 | -------------------------------------------------------------------------------- /VERSIONING.md: -------------------------------------------------------------------------------- 1 | # Versioning and Releasing in controller-tools 2 | 3 | We follow the [common KubeBuilder versioning guidelines][guidelines], and 4 | use the corresponding tooling. 5 | 6 | For the purposes of the aforementioned guidelines, controller-tools counts 7 | as a "library project", but otherwise follows the guidelines closely. 8 | 9 | [guidelines]: https://sigs.k8s.io/kubebuilder-release-tools/VERSIONING.md 10 | 11 | ## Compatibility and Release Support 12 | 13 | For release branches, we generally do not support older branches. This 14 | may change in the future. 15 | 16 | Compatibility-wise, remember that changes to generation defaults are 17 | breaking changes. 18 | 19 | ## Updates to Other Projects on Release 20 | 21 | When you release, you'll need to perform updates in other KubeBuilder 22 | projects: 23 | 24 | - Update the controller-tools version used to generate the KubeBuilder 25 | book at [docs/book/install-and-build.sh][book-script] 26 | 27 | [book-script]: https://sigs.k8s.io/kubebuilder/docs/book/install-and-build.sh 28 | -------------------------------------------------------------------------------- /boilerplate.go.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright YEAR The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Community Code of Conduct 2 | 3 | Please refer to our [Kubernetes Community Code of Conduct](https://git.k8s.io/community/code-of-conduct.md) 4 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module sigs.k8s.io/controller-tools 2 | 3 | go 1.24.0 4 | 5 | require ( 6 | github.com/fatih/color v1.18.0 7 | github.com/gobuffalo/flect v1.0.3 8 | github.com/google/go-cmp v0.7.0 9 | github.com/onsi/ginkgo v1.16.5 10 | github.com/onsi/gomega v1.37.0 11 | github.com/spf13/cobra v1.9.1 12 | github.com/spf13/pflag v1.0.6 13 | golang.org/x/tools v0.33.0 14 | gopkg.in/yaml.v2 v2.4.0 15 | gopkg.in/yaml.v3 v3.0.1 16 | k8s.io/api v0.33.1 17 | k8s.io/apiextensions-apiserver v0.33.1 18 | k8s.io/apimachinery v0.33.1 19 | k8s.io/code-generator v0.33.1 20 | k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 21 | k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 22 | sigs.k8s.io/yaml v1.4.0 23 | ) 24 | 25 | require ( 26 | github.com/fsnotify/fsnotify v1.7.0 // indirect 27 | github.com/fxamacker/cbor/v2 v2.7.0 // indirect 28 | github.com/go-logr/logr v1.4.2 // indirect 29 | github.com/go-openapi/jsonpointer v0.21.0 // indirect 30 | github.com/go-openapi/jsonreference v0.20.2 // indirect 31 | github.com/go-openapi/swag v0.23.0 // indirect 32 | github.com/gogo/protobuf v1.3.2 // indirect 33 | github.com/google/gnostic-models v0.6.9 // indirect 34 | github.com/inconshreveable/mousetrap v1.1.0 // indirect 35 | github.com/josharian/intern v1.0.0 // indirect 36 | github.com/json-iterator/go v1.1.12 // indirect 37 | github.com/mailru/easyjson v0.7.7 // indirect 38 | github.com/mattn/go-colorable v0.1.13 // indirect 39 | github.com/mattn/go-isatty v0.0.20 // indirect 40 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 41 | github.com/modern-go/reflect2 v1.0.2 // indirect 42 | github.com/nxadm/tail v1.4.8 // indirect 43 | github.com/x448/float16 v0.8.4 // indirect 44 | golang.org/x/mod v0.24.0 // indirect 45 | golang.org/x/net v0.40.0 // indirect 46 | golang.org/x/sync v0.14.0 // indirect 47 | golang.org/x/sys v0.33.0 // indirect 48 | golang.org/x/text v0.25.0 // indirect 49 | google.golang.org/protobuf v1.36.5 // indirect 50 | gopkg.in/inf.v0 v0.9.1 // indirect 51 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect 52 | k8s.io/klog/v2 v2.130.1 // indirect 53 | k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect 54 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect 55 | sigs.k8s.io/randfill v1.0.0 // indirect 56 | sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect 57 | ) 58 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.23.5.yaml: -------------------------------------------------------------------------------- 1 | go: 1.17 2 | etcd: v3.5.5 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.24.1.yaml: -------------------------------------------------------------------------------- 1 | go: 1.18 2 | etcd: v3.5.5 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.24.2.yaml: -------------------------------------------------------------------------------- 1 | go: 1.18 2 | etcd: v3.5.5 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.25.0.yaml: -------------------------------------------------------------------------------- 1 | go: 1.19 2 | etcd: v3.5.5 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.26.0.yaml: -------------------------------------------------------------------------------- 1 | go: 1.19 2 | etcd: v3.5.6 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.26.1.yaml: -------------------------------------------------------------------------------- 1 | go: 1.19 2 | etcd: v3.5.6 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.27.1.yaml: -------------------------------------------------------------------------------- 1 | go: 1.20 2 | etcd: v3.5.7 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.28.0.yaml: -------------------------------------------------------------------------------- 1 | go: 1.21 2 | etcd: v3.5.9 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.28.3.yaml: -------------------------------------------------------------------------------- 1 | go: 1.21 2 | etcd: v3.5.9 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.29.0.yaml: -------------------------------------------------------------------------------- 1 | go: 1.21 2 | etcd: v3.5.10 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.29.1.yaml: -------------------------------------------------------------------------------- 1 | go: 1.21 2 | etcd: v3.5.10 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.29.3.yaml: -------------------------------------------------------------------------------- 1 | go: 1.21 2 | etcd: v3.5.12 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.29.4.yaml: -------------------------------------------------------------------------------- 1 | go: 1.21 2 | etcd: v3.5.12 3 | 4 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.29.5.yaml: -------------------------------------------------------------------------------- 1 | go: 1.21 2 | etcd: v3.5.12 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.30.0.yaml: -------------------------------------------------------------------------------- 1 | go: 1.22 2 | etcd: v3.5.12 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.30.2.yaml: -------------------------------------------------------------------------------- 1 | go: 1.22 2 | etcd: v3.5.12 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.30.3.yaml: -------------------------------------------------------------------------------- 1 | go: 1.22 2 | etcd: v3.5.12 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.31.0-beta.0.yaml: -------------------------------------------------------------------------------- 1 | go: 1.22 2 | etcd: v3.5.14 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.31.0.yaml: -------------------------------------------------------------------------------- 1 | go: 1.22 2 | etcd: v3.5.15 3 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.32.0.yaml: -------------------------------------------------------------------------------- 1 | go: 1.23 2 | etcd: v3.5.16 3 | 4 | -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.33.0-alpha.2.yaml: -------------------------------------------------------------------------------- 1 | go: 1.23 2 | etcd: v3.5.17 -------------------------------------------------------------------------------- /hack/envtest/_matrix/v1.33.0.yaml: -------------------------------------------------------------------------------- 1 | go: 1.24.2 2 | etcd: v3.5.21 3 | 4 | -------------------------------------------------------------------------------- /hack/envtest/darwin/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Kubernetes Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | ARG GO_VERSION 16 | FROM golang:${GO_VERSION} as builder 17 | 18 | # Version and platform args. 19 | ARG KUBERNETES_VERSION 20 | ARG ETCD_VERSION 21 | ARG OS=darwin 22 | ARG ARCH 23 | 24 | # Tools path. 25 | ENV DEST=/controller-tools/envtest 26 | 27 | # Install dependencies. 28 | RUN apt update && \ 29 | apt install unzip rsync -y && \ 30 | mkdir -p $DEST 31 | 32 | # kube-apiserver 33 | WORKDIR /kubernetes 34 | RUN git clone https://github.com/kubernetes/kubernetes . --depth=1 -b ${KUBERNETES_VERSION} 35 | ENV CGO_ENABLED=0 36 | ENV KUBE_BUILD_PLATFORMS=${OS}/${ARCH} 37 | RUN make WHAT=cmd/kube-apiserver && \ 38 | cp _output/local/bin/${KUBE_BUILD_PLATFORMS}/kube-apiserver $DEST 39 | 40 | # kubectl 41 | RUN /bin/bash -x -c ' \ 42 | { curl -sfLO https://dl.k8s.io/${KUBERNETES_VERSION}/bin/${OS}/${ARCH}/kubectl && \ 43 | chmod +x kubectl && \ 44 | cp kubectl $DEST; } || \ 45 | { make WHAT=cmd/kubectl && \ 46 | cp _output/local/bin/${KUBE_BUILD_PLATFORMS}/kubectl $DEST; }' 47 | 48 | # etcd 49 | ENV ETCD_BASE_NAME=etcd-${ETCD_VERSION}-${OS}-${ARCH} 50 | RUN curl -sfLO https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/${ETCD_BASE_NAME}.zip && \ 51 | unzip -o ${ETCD_BASE_NAME}.zip && \ 52 | cp ${ETCD_BASE_NAME}/etcd $DEST 53 | 54 | # Package into tarball. 55 | RUN tar -czvf /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz $DEST 56 | RUN sha512sum /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz > /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz.sha512 57 | 58 | # Build the final image with the binaries. 59 | FROM scratch 60 | ARG OS 61 | ARG ARCH 62 | ARG KUBERNETES_VERSION 63 | COPY --from=builder /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz / 64 | COPY --from=builder /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz.sha512 / 65 | -------------------------------------------------------------------------------- /hack/envtest/linux/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Kubernetes Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | ARG GO_VERSION 16 | FROM golang:${GO_VERSION} as builder 17 | 18 | # Version and platform args. 19 | ARG KUBERNETES_VERSION 20 | ARG ETCD_VERSION 21 | ARG OS=linux 22 | ARG ARCH 23 | 24 | # Tools path. 25 | ENV DEST=/controller-tools/envtest 26 | 27 | # Install dependencies. 28 | RUN apt update && \ 29 | apt install unzip rsync -y && \ 30 | mkdir -p $DEST 31 | 32 | # kube-apiserver 33 | RUN curl -sfLO https://dl.k8s.io/${KUBERNETES_VERSION}/bin/${OS}/${ARCH}/kube-apiserver && \ 34 | chmod +x kube-apiserver && \ 35 | cp kube-apiserver $DEST 36 | 37 | # kubectl 38 | RUN curl -sfLO https://dl.k8s.io/${KUBERNETES_VERSION}/bin/${OS}/${ARCH}/kubectl && \ 39 | chmod +x kubectl && \ 40 | cp kubectl $DEST 41 | 42 | # etcd 43 | ENV ETCD_BASE_NAME=etcd-${ETCD_VERSION}-${OS}-${ARCH} 44 | RUN curl -sfLO https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/${ETCD_BASE_NAME}.tar.gz && \ 45 | tar xzf ${ETCD_BASE_NAME}.tar.gz && \ 46 | cp ${ETCD_BASE_NAME}/etcd $DEST 47 | 48 | # Package into tarball. 49 | RUN tar -czvf /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz $DEST 50 | RUN sha512sum /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz > /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz.sha512 51 | 52 | # Build the final image with the binaries. 53 | FROM scratch 54 | ARG OS 55 | ARG ARCH 56 | ARG KUBERNETES_VERSION 57 | COPY --from=builder /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz / 58 | COPY --from=builder /envtest-${KUBERNETES_VERSION}-${OS}-${ARCH}.tar.gz.sha512 / 59 | -------------------------------------------------------------------------------- /hack/envtest/update-releases.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2024 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -o errexit 17 | set -o nounset 18 | set -o pipefail 19 | set -x 20 | 21 | ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. 22 | 23 | if [ -z "${KUBERNETES_VERSION}" ]; then 24 | echo "Missing KUBERNETES_VERSION environment variable" 25 | exit 1 26 | fi 27 | 28 | # Create the releases.yaml file in hack/envtest if it does not exist 29 | if [ ! -f "${ROOT}"/envtest-releases.yaml ]; then 30 | echo "releases:" > "${ROOT}"/envtest-releases.yaml 31 | fi 32 | 33 | # Add the newly built Kubernetes version to the releases.yaml file with yq as an object key under releases 34 | yq eval ".releases += {\"${KUBERNETES_VERSION}\": {}}" -i "${ROOT}"/envtest-releases.yaml 35 | 36 | for file in "${ROOT}"/out/*.tar.gz; do 37 | file_name=$(basename "${file}") 38 | file_hash=$(awk '{ print $1 }' < "${file}.sha512") 39 | self_link=https://github.com/kubernetes-sigs/controller-tools/releases/download/envtest-${KUBERNETES_VERSION}/${file_name} 40 | 41 | yq eval \ 42 | ".releases[\"${KUBERNETES_VERSION}\"] += {\"${file_name}\": {\"hash\": \"${file_hash}\", \"selfLink\": \"${self_link}\"}}" \ 43 | -i "${ROOT}"/envtest-releases.yaml 44 | done 45 | -------------------------------------------------------------------------------- /hack/go-install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2021 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -o errexit 17 | set -o nounset 18 | set -o pipefail 19 | 20 | if [ -z "${1}" ]; then 21 | echo "must provide module as first parameter" 22 | exit 1 23 | fi 24 | 25 | if [ -z "${2}" ]; then 26 | echo "must provide binary name as second parameter" 27 | exit 1 28 | fi 29 | 30 | if [ -z "${3}" ]; then 31 | echo "must provide version as third parameter" 32 | exit 1 33 | fi 34 | 35 | if [ -z "${GOBIN}" ]; then 36 | echo "GOBIN is not set. Must set GOBIN to install the bin in a specified directory." 37 | exit 1 38 | fi 39 | 40 | rm -f "${GOBIN}/${2}"* || true 41 | 42 | # install the golang module specified as the first argument 43 | go install "${1}@${3}" 44 | mv "${GOBIN}/${2}" "${GOBIN}/${2}-${3}" 45 | ln -sf "${GOBIN}/${2}-${3}" "${GOBIN}/${2}" 46 | -------------------------------------------------------------------------------- /hack/tools/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-sigs/controller-tools/67249c598b39237877a67c43301ce92564efd115/hack/tools/.keep -------------------------------------------------------------------------------- /hack/verify-pr-title.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2024 The Kubernetes Authors. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Define regex patterns 18 | WIP_REGEX="^\W?WIP\W" 19 | TAG_REGEX="^\[[[:alnum:]\._-]*\]" 20 | PR_TITLE="$1" 21 | 22 | # Trim WIP and tags from title 23 | trimmed_title=$(echo "$PR_TITLE" | sed -E "s/$WIP_REGEX//" | sed -E "s/$TAG_REGEX//" | xargs) 24 | 25 | # Normalize common emojis in text form to actual emojis 26 | trimmed_title=$(echo "$trimmed_title" | sed -E "s/:warning:/⚠/g") 27 | trimmed_title=$(echo "$trimmed_title" | sed -E "s/:sparkles:/✨/g") 28 | trimmed_title=$(echo "$trimmed_title" | sed -E "s/:bug:/🐛/g") 29 | trimmed_title=$(echo "$trimmed_title" | sed -E "s/:book:/📖/g") 30 | trimmed_title=$(echo "$trimmed_title" | sed -E "s/:rocket:/🚀/g") 31 | trimmed_title=$(echo "$trimmed_title" | sed -E "s/:seedling:/🌱/g") 32 | 33 | # Check PR type prefix 34 | if [[ "$trimmed_title" =~ ^(⚠|✨|🐛|📖|🚀|🌱) ]]; then 35 | echo "PR title is valid: $trimmed_title" 36 | else 37 | echo "Error: No matching PR type indicator found in title." 38 | echo "You need to have one of these as the prefix of your PR title:" 39 | echo "- Breaking change: ⚠ (:warning:)" 40 | echo "- Non-breaking feature: ✨ (:sparkles:)" 41 | echo "- Patch fix: 🐛 (:bug:)" 42 | echo "- Docs: 📖 (:book:)" 43 | echo "- Release: 🚀 (:rocket:)" 44 | echo "- Infra/Tests/Other: 🌱 (:seedling:)" 45 | exit 1 46 | fi 47 | 48 | # Check that PR title does not contain Issue or PR number 49 | if [[ "$trimmed_title" =~ \#[0-9]+ ]]; then 50 | echo "Error: PR title should not contain issue or PR number." 51 | echo "Issue numbers belong in the PR body as either \"Fixes #XYZ\" (if it closes the issue or PR), or something like \"Related to #XYZ\" (if it's just related)." 52 | exit 1 53 | fi 54 | 55 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/applyconfiguration_suite_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package applyconfiguration 18 | 19 | import ( 20 | "testing" 21 | 22 | . "github.com/onsi/ginkgo" 23 | . "github.com/onsi/gomega" 24 | ) 25 | 26 | func TestObjectGeneration(t *testing.T) { 27 | RegisterFailHandler(Fail) 28 | RunSpecs(t, "ApplyConfiguration Generation Suite") 29 | } 30 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package applyconfigurations generates types for constructing declarative apply configurations. 18 | package applyconfiguration 19 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/associativetype.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | // AssociativeTypeApplyConfiguration represents a declarative configuration of the AssociativeType type for use 6 | // with apply. 7 | type AssociativeTypeApplyConfiguration struct { 8 | Name *string `json:"name,omitempty"` 9 | Secondary *int `json:"secondary,omitempty"` 10 | Foo *string `json:"foo,omitempty"` 11 | } 12 | 13 | // AssociativeTypeApplyConfiguration constructs a declarative configuration of the AssociativeType type for use with 14 | // apply. 15 | func AssociativeType() *AssociativeTypeApplyConfiguration { 16 | return &AssociativeTypeApplyConfiguration{} 17 | } 18 | 19 | // WithName sets the Name field in the declarative configuration to the given value 20 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 21 | // If called multiple times, the Name field is set to the value of the last call. 22 | func (b *AssociativeTypeApplyConfiguration) WithName(value string) *AssociativeTypeApplyConfiguration { 23 | b.Name = &value 24 | return b 25 | } 26 | 27 | // WithSecondary sets the Secondary field in the declarative configuration to the given value 28 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 29 | // If called multiple times, the Secondary field is set to the value of the last call. 30 | func (b *AssociativeTypeApplyConfiguration) WithSecondary(value int) *AssociativeTypeApplyConfiguration { 31 | b.Secondary = &value 32 | return b 33 | } 34 | 35 | // WithFoo sets the Foo field in the declarative configuration to the given value 36 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 37 | // If called multiple times, the Foo field is set to the value of the last call. 38 | func (b *AssociativeTypeApplyConfiguration) WithFoo(value string) *AssociativeTypeApplyConfiguration { 39 | b.Foo = &value 40 | return b 41 | } 42 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/containsnestedmap.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | // ContainsNestedMapApplyConfiguration represents a declarative configuration of the ContainsNestedMap type for use 6 | // with apply. 7 | type ContainsNestedMapApplyConfiguration struct { 8 | InnerMap map[string]string `json:"innerMap,omitempty"` 9 | } 10 | 11 | // ContainsNestedMapApplyConfiguration constructs a declarative configuration of the ContainsNestedMap type for use with 12 | // apply. 13 | func ContainsNestedMap() *ContainsNestedMapApplyConfiguration { 14 | return &ContainsNestedMapApplyConfiguration{} 15 | } 16 | 17 | // WithInnerMap puts the entries into the InnerMap field in the declarative configuration 18 | // and returns the receiver, so that objects can be build by chaining "With" function invocations. 19 | // If called multiple times, the entries provided by each call will be put on the InnerMap field, 20 | // overwriting an existing map entries in InnerMap field with the same key. 21 | func (b *ContainsNestedMapApplyConfiguration) WithInnerMap(entries map[string]string) *ContainsNestedMapApplyConfiguration { 22 | if b.InnerMap == nil && len(entries) > 0 { 23 | b.InnerMap = make(map[string]string, len(entries)) 24 | } 25 | for k, v := range entries { 26 | b.InnerMap[k] = v 27 | } 28 | return b 29 | } 30 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/duration.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | import ( 6 | time "time" 7 | ) 8 | 9 | // DurationApplyConfiguration represents a declarative configuration of the Duration type for use 10 | // with apply. 11 | type DurationApplyConfiguration struct { 12 | Value *time.Duration `json:"value,omitempty"` 13 | } 14 | 15 | // DurationApplyConfiguration constructs a declarative configuration of the Duration type for use with 16 | // apply. 17 | func Duration() *DurationApplyConfiguration { 18 | return &DurationApplyConfiguration{} 19 | } 20 | 21 | // WithValue sets the Value field in the declarative configuration to the given value 22 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 23 | // If called multiple times, the Value field is set to the value of the last call. 24 | func (b *DurationApplyConfiguration) WithValue(value time.Duration) *DurationApplyConfiguration { 25 | b.Value = &value 26 | return b 27 | } 28 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/embeddedstruct.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | // EmbeddedStructApplyConfiguration represents a declarative configuration of the EmbeddedStruct type for use 6 | // with apply. 7 | type EmbeddedStructApplyConfiguration struct { 8 | FromEmbedded *string `json:"fromEmbedded,omitempty"` 9 | } 10 | 11 | // EmbeddedStructApplyConfiguration constructs a declarative configuration of the EmbeddedStruct type for use with 12 | // apply. 13 | func EmbeddedStruct() *EmbeddedStructApplyConfiguration { 14 | return &EmbeddedStructApplyConfiguration{} 15 | } 16 | 17 | // WithFromEmbedded sets the FromEmbedded field in the declarative configuration to the given value 18 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 19 | // If called multiple times, the FromEmbedded field is set to the value of the last call. 20 | func (b *EmbeddedStructApplyConfiguration) WithFromEmbedded(value string) *EmbeddedStructApplyConfiguration { 21 | b.FromEmbedded = &value 22 | return b 23 | } 24 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/empiableobject.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | // EmpiableObjectApplyConfiguration represents a declarative configuration of the EmpiableObject type for use 6 | // with apply. 7 | type EmpiableObjectApplyConfiguration struct { 8 | Foo *string `json:"foo,omitempty"` 9 | Bar *string `json:"bar,omitempty"` 10 | } 11 | 12 | // EmpiableObjectApplyConfiguration constructs a declarative configuration of the EmpiableObject type for use with 13 | // apply. 14 | func EmpiableObject() *EmpiableObjectApplyConfiguration { 15 | return &EmpiableObjectApplyConfiguration{} 16 | } 17 | 18 | // WithFoo sets the Foo field in the declarative configuration to the given value 19 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 20 | // If called multiple times, the Foo field is set to the value of the last call. 21 | func (b *EmpiableObjectApplyConfiguration) WithFoo(value string) *EmpiableObjectApplyConfiguration { 22 | b.Foo = &value 23 | return b 24 | } 25 | 26 | // WithBar sets the Bar field in the declarative configuration to the given value 27 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 28 | // If called multiple times, the Bar field is set to the value of the last call. 29 | func (b *EmpiableObjectApplyConfiguration) WithBar(value string) *EmpiableObjectApplyConfiguration { 30 | b.Bar = &value 31 | return b 32 | } 33 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/exportedstruct.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | // ExportedStructApplyConfiguration represents a declarative configuration of the ExportedStruct type for use 6 | // with apply. 7 | type ExportedStructApplyConfiguration struct { 8 | Baz *string `json:"baz,omitempty"` 9 | } 10 | 11 | // ExportedStructApplyConfiguration constructs a declarative configuration of the ExportedStruct type for use with 12 | // apply. 13 | func ExportedStruct() *ExportedStructApplyConfiguration { 14 | return &ExportedStructApplyConfiguration{} 15 | } 16 | 17 | // WithBaz sets the Baz field in the declarative configuration to the given value 18 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 19 | // If called multiple times, the Baz field is set to the value of the last call. 20 | func (b *ExportedStructApplyConfiguration) WithBaz(value string) *ExportedStructApplyConfiguration { 21 | b.Baz = &value 22 | return b 23 | } 24 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/justnestedobject.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | // JustNestedObjectApplyConfiguration represents a declarative configuration of the JustNestedObject type for use 6 | // with apply. 7 | type JustNestedObjectApplyConfiguration struct { 8 | Foo *string `json:"foo,omitempty"` 9 | Bar *bool `json:"bar,omitempty"` 10 | } 11 | 12 | // JustNestedObjectApplyConfiguration constructs a declarative configuration of the JustNestedObject type for use with 13 | // apply. 14 | func JustNestedObject() *JustNestedObjectApplyConfiguration { 15 | return &JustNestedObjectApplyConfiguration{} 16 | } 17 | 18 | // WithFoo sets the Foo field in the declarative configuration to the given value 19 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 20 | // If called multiple times, the Foo field is set to the value of the last call. 21 | func (b *JustNestedObjectApplyConfiguration) WithFoo(value string) *JustNestedObjectApplyConfiguration { 22 | b.Foo = &value 23 | return b 24 | } 25 | 26 | // WithBar sets the Bar field in the declarative configuration to the given value 27 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 28 | // If called multiple times, the Bar field is set to the value of the last call. 29 | func (b *JustNestedObjectApplyConfiguration) WithBar(value bool) *JustNestedObjectApplyConfiguration { 30 | b.Bar = &value 31 | return b 32 | } 33 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/minmaxobject.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | // MinMaxObjectApplyConfiguration represents a declarative configuration of the MinMaxObject type for use 6 | // with apply. 7 | type MinMaxObjectApplyConfiguration struct { 8 | Foo *string `json:"foo,omitempty"` 9 | Bar *string `json:"bar,omitempty"` 10 | Baz *string `json:"baz,omitempty"` 11 | } 12 | 13 | // MinMaxObjectApplyConfiguration constructs a declarative configuration of the MinMaxObject type for use with 14 | // apply. 15 | func MinMaxObject() *MinMaxObjectApplyConfiguration { 16 | return &MinMaxObjectApplyConfiguration{} 17 | } 18 | 19 | // WithFoo sets the Foo field in the declarative configuration to the given value 20 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 21 | // If called multiple times, the Foo field is set to the value of the last call. 22 | func (b *MinMaxObjectApplyConfiguration) WithFoo(value string) *MinMaxObjectApplyConfiguration { 23 | b.Foo = &value 24 | return b 25 | } 26 | 27 | // WithBar sets the Bar field in the declarative configuration to the given value 28 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 29 | // If called multiple times, the Bar field is set to the value of the last call. 30 | func (b *MinMaxObjectApplyConfiguration) WithBar(value string) *MinMaxObjectApplyConfiguration { 31 | b.Bar = &value 32 | return b 33 | } 34 | 35 | // WithBaz sets the Baz field in the declarative configuration to the given value 36 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 37 | // If called multiple times, the Baz field is set to the value of the last call. 38 | func (b *MinMaxObjectApplyConfiguration) WithBaz(value string) *MinMaxObjectApplyConfiguration { 39 | b.Baz = &value 40 | return b 41 | } 42 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/nestedobject.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | // NestedObjectApplyConfiguration represents a declarative configuration of the NestedObject type for use 6 | // with apply. 7 | type NestedObjectApplyConfiguration struct { 8 | Foo *string `json:"foo,omitempty"` 9 | Bar *bool `json:"bar,omitempty"` 10 | } 11 | 12 | // NestedObjectApplyConfiguration constructs a declarative configuration of the NestedObject type for use with 13 | // apply. 14 | func NestedObject() *NestedObjectApplyConfiguration { 15 | return &NestedObjectApplyConfiguration{} 16 | } 17 | 18 | // WithFoo sets the Foo field in the declarative configuration to the given value 19 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 20 | // If called multiple times, the Foo field is set to the value of the last call. 21 | func (b *NestedObjectApplyConfiguration) WithFoo(value string) *NestedObjectApplyConfiguration { 22 | b.Foo = &value 23 | return b 24 | } 25 | 26 | // WithBar sets the Bar field in the declarative configuration to the given value 27 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 28 | // If called multiple times, the Bar field is set to the value of the last call. 29 | func (b *NestedObjectApplyConfiguration) WithBar(value bool) *NestedObjectApplyConfiguration { 30 | b.Bar = &value 31 | return b 32 | } 33 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/nestedstructwithseveralfields.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | // NestedStructWithSeveralFieldsApplyConfiguration represents a declarative configuration of the NestedStructWithSeveralFields type for use 6 | // with apply. 7 | type NestedStructWithSeveralFieldsApplyConfiguration struct { 8 | Foo *string `json:"foo,omitempty"` 9 | Bar *bool `json:"bar,omitempty"` 10 | } 11 | 12 | // NestedStructWithSeveralFieldsApplyConfiguration constructs a declarative configuration of the NestedStructWithSeveralFields type for use with 13 | // apply. 14 | func NestedStructWithSeveralFields() *NestedStructWithSeveralFieldsApplyConfiguration { 15 | return &NestedStructWithSeveralFieldsApplyConfiguration{} 16 | } 17 | 18 | // WithFoo sets the Foo field in the declarative configuration to the given value 19 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 20 | // If called multiple times, the Foo field is set to the value of the last call. 21 | func (b *NestedStructWithSeveralFieldsApplyConfiguration) WithFoo(value string) *NestedStructWithSeveralFieldsApplyConfiguration { 22 | b.Foo = &value 23 | return b 24 | } 25 | 26 | // WithBar sets the Bar field in the declarative configuration to the given value 27 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 28 | // If called multiple times, the Bar field is set to the value of the last call. 29 | func (b *NestedStructWithSeveralFieldsApplyConfiguration) WithBar(value bool) *NestedStructWithSeveralFieldsApplyConfiguration { 30 | b.Bar = &value 31 | return b 32 | } 33 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/preserved.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | // PreservedApplyConfiguration represents a declarative configuration of the Preserved type for use 6 | // with apply. 7 | type PreservedApplyConfiguration struct { 8 | ConcreteField *string `json:"concreteField,omitempty"` 9 | } 10 | 11 | // PreservedApplyConfiguration constructs a declarative configuration of the Preserved type for use with 12 | // apply. 13 | func Preserved() *PreservedApplyConfiguration { 14 | return &PreservedApplyConfiguration{} 15 | } 16 | 17 | // WithConcreteField sets the ConcreteField field in the declarative configuration to the given value 18 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 19 | // If called multiple times, the ConcreteField field is set to the value of the last call. 20 | func (b *PreservedApplyConfiguration) WithConcreteField(value string) *PreservedApplyConfiguration { 21 | b.ConcreteField = &value 22 | return b 23 | } 24 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/rootobject.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | // RootObjectApplyConfiguration represents a declarative configuration of the RootObject type for use 6 | // with apply. 7 | type RootObjectApplyConfiguration struct { 8 | Nested *NestedObjectApplyConfiguration `json:"nested,omitempty"` 9 | } 10 | 11 | // RootObjectApplyConfiguration constructs a declarative configuration of the RootObject type for use with 12 | // apply. 13 | func RootObject() *RootObjectApplyConfiguration { 14 | return &RootObjectApplyConfiguration{} 15 | } 16 | 17 | // WithNested sets the Nested field in the declarative configuration to the given value 18 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 19 | // If called multiple times, the Nested field is set to the value of the last call. 20 | func (b *RootObjectApplyConfiguration) WithNested(value *NestedObjectApplyConfiguration) *RootObjectApplyConfiguration { 21 | b.Nested = value 22 | return b 23 | } 24 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/api/v1/unexportedstruct.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package v1 4 | 5 | // UnexportedStructApplyConfiguration represents a declarative configuration of the UnexportedStruct type for use 6 | // with apply. 7 | type UnexportedStructApplyConfiguration struct { 8 | Foo *string `json:"foo,omitempty"` 9 | } 10 | 11 | // UnexportedStructApplyConfiguration constructs a declarative configuration of the UnexportedStruct type for use with 12 | // apply. 13 | func UnexportedStruct() *UnexportedStructApplyConfiguration { 14 | return &UnexportedStructApplyConfiguration{} 15 | } 16 | 17 | // WithFoo sets the Foo field in the declarative configuration to the given value 18 | // and returns the receiver, so that objects can be built by chaining "With" function invocations. 19 | // If called multiple times, the Foo field is set to the value of the last call. 20 | func (b *UnexportedStructApplyConfiguration) WithFoo(value string) *UnexportedStructApplyConfiguration { 21 | b.Foo = &value 22 | return b 23 | } 24 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/applyconfiguration/internal/internal.go: -------------------------------------------------------------------------------- 1 | // Code generated by applyconfiguration. DO NOT EDIT. 2 | 3 | package internal 4 | 5 | import ( 6 | fmt "fmt" 7 | sync "sync" 8 | 9 | typed "sigs.k8s.io/structured-merge-diff/v4/typed" 10 | ) 11 | 12 | func Parser() *typed.Parser { 13 | parserOnce.Do(func() { 14 | var err error 15 | parser, err = typed.NewParser(schemaYAML) 16 | if err != nil { 17 | panic(fmt.Sprintf("Failed to parse schema: %v", err)) 18 | } 19 | }) 20 | return parser 21 | } 22 | 23 | var parserOnce sync.Once 24 | var parser *typed.Parser 25 | var schemaYAML = typed.YAMLObject(`types: 26 | - name: __untyped_atomic_ 27 | scalar: untyped 28 | list: 29 | elementType: 30 | namedType: __untyped_atomic_ 31 | elementRelationship: atomic 32 | map: 33 | elementType: 34 | namedType: __untyped_atomic_ 35 | elementRelationship: atomic 36 | - name: __untyped_deduced_ 37 | scalar: untyped 38 | list: 39 | elementType: 40 | namedType: __untyped_atomic_ 41 | elementRelationship: atomic 42 | map: 43 | elementType: 44 | namedType: __untyped_deduced_ 45 | elementRelationship: separable 46 | `) 47 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/api/v1/groupversion_info.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +groupName=testdata.kubebuilder.io 18 | // +versionName=v1 19 | // +kubebuilder:ac:generate=true 20 | // +kubebuilder:ac:output:package="applyconfiguration" 21 | package v1 22 | 23 | import ( 24 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 | "k8s.io/apimachinery/pkg/runtime" 26 | "k8s.io/apimachinery/pkg/runtime/schema" 27 | ) 28 | 29 | var ( 30 | GroupName = "testdata.kubebuilder.io" 31 | GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} 32 | SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) 33 | 34 | // AddToScheme exists solely to keep the old generators creating valid code 35 | AddToScheme = SchemeBuilder.AddToScheme 36 | ) 37 | 38 | // Adds the list of known types to api.Scheme. 39 | func addKnownTypes(scheme *runtime.Scheme) error { 40 | metav1.AddToGroupVersion(scheme, GroupVersion) 41 | 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/testdata/cronjob/go.mod: -------------------------------------------------------------------------------- 1 | module sigs.k8s.io/controller-tools/pkg/applyconfiguration/testdata/cronjob 2 | 3 | go 1.24.0 4 | 5 | toolchain go1.24.1 6 | 7 | require ( 8 | k8s.io/api v0.33.0 9 | k8s.io/apimachinery v0.33.0 10 | k8s.io/client-go v0.33.0 11 | sigs.k8s.io/structured-merge-diff/v4 v4.6.0 12 | ) 13 | 14 | require ( 15 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect 16 | github.com/emicklei/go-restful/v3 v3.11.0 // indirect 17 | github.com/fxamacker/cbor/v2 v2.7.0 // indirect 18 | github.com/go-logr/logr v1.4.2 // indirect 19 | github.com/go-openapi/jsonpointer v0.21.0 // indirect 20 | github.com/go-openapi/jsonreference v0.20.2 // indirect 21 | github.com/go-openapi/swag v0.23.0 // indirect 22 | github.com/gogo/protobuf v1.3.2 // indirect 23 | github.com/google/gnostic-models v0.6.9 // indirect 24 | github.com/google/uuid v1.6.0 // indirect 25 | github.com/josharian/intern v1.0.0 // indirect 26 | github.com/json-iterator/go v1.1.12 // indirect 27 | github.com/mailru/easyjson v0.7.7 // indirect 28 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 29 | github.com/modern-go/reflect2 v1.0.2 // indirect 30 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect 31 | github.com/pkg/errors v0.9.1 // indirect 32 | github.com/x448/float16 v0.8.4 // indirect 33 | golang.org/x/net v0.38.0 // indirect 34 | golang.org/x/oauth2 v0.27.0 // indirect 35 | golang.org/x/sys v0.31.0 // indirect 36 | golang.org/x/term v0.30.0 // indirect 37 | golang.org/x/text v0.23.0 // indirect 38 | golang.org/x/time v0.9.0 // indirect 39 | google.golang.org/protobuf v1.36.5 // indirect 40 | gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect 41 | gopkg.in/inf.v0 v0.9.1 // indirect 42 | gopkg.in/yaml.v3 v3.0.1 // indirect 43 | k8s.io/klog/v2 v2.130.1 // indirect 44 | k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect 45 | k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect 46 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect 47 | sigs.k8s.io/randfill v1.0.0 // indirect 48 | sigs.k8s.io/yaml v1.4.0 // indirect 49 | ) 50 | -------------------------------------------------------------------------------- /pkg/applyconfiguration/zz_generated.markerhelp.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | 3 | /* 4 | Copyright2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Code generated by helpgen. DO NOT EDIT. 20 | 21 | package applyconfiguration 22 | 23 | import ( 24 | "sigs.k8s.io/controller-tools/pkg/markers" 25 | ) 26 | 27 | func (Generator) Help() *markers.DefinitionHelp { 28 | return &markers.DefinitionHelp{ 29 | Category: "", 30 | DetailedHelp: markers.DetailedHelp{ 31 | Summary: "generates code containing apply configuration type implementations.", 32 | Details: "", 33 | }, 34 | FieldHelp: map[string]markers.DetailedHelp{ 35 | "HeaderFile": { 36 | Summary: "specifies the header text (e.g. license) to prepend to generated files.", 37 | Details: "", 38 | }, 39 | }, 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /pkg/crd/conv.go: -------------------------------------------------------------------------------- 1 | package crd 2 | 3 | import ( 4 | "fmt" 5 | 6 | apiextinternal "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" 7 | apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" 8 | apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" 9 | "k8s.io/apimachinery/pkg/runtime" 10 | "k8s.io/apimachinery/pkg/runtime/schema" 11 | ) 12 | 13 | var ( 14 | conversionScheme = runtime.NewScheme() 15 | ) 16 | 17 | func init() { 18 | if err := apiextinternal.AddToScheme(conversionScheme); err != nil { 19 | panic("must be able to add internal apiextensions to the CRD conversion Scheme") 20 | } 21 | if err := apiext.AddToScheme(conversionScheme); err != nil { 22 | panic("must be able to add apiextensions/v1 to the CRD conversion Scheme") 23 | } 24 | } 25 | 26 | // AsVersion converts a CRD from the canonical internal form (currently v1) to some external form. 27 | func AsVersion(original apiext.CustomResourceDefinition, gv schema.GroupVersion) (runtime.Object, error) { 28 | // TODO: Do we need to keep maintaining this conversion function 29 | // post 1.22 when only CRDv1 is served by the apiserver? 30 | if gv == apiextv1beta1.SchemeGroupVersion { 31 | return nil, fmt.Errorf("apiVersion %q is not supported", gv.String()) 32 | } 33 | // We can use the internal versions an existing conversions from kubernetes, since they're not in k/k itself. 34 | // This punts the problem of conversion down the road for a future maintainer (or future instance of @directxman12) 35 | // when we have to support older versions that get removed, or when API machinery decides to yell at us for this 36 | // questionable decision. 37 | intVer, err := conversionScheme.ConvertToVersion(&original, apiextinternal.SchemeGroupVersion) 38 | if err != nil { 39 | return nil, fmt.Errorf("unable to convert to internal CRD version: %w", err) 40 | } 41 | 42 | return conversionScheme.ConvertToVersion(intVer, gv) 43 | } 44 | -------------------------------------------------------------------------------- /pkg/crd/crd_spec_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package crd_test 18 | 19 | import ( 20 | . "github.com/onsi/ginkgo" 21 | ) 22 | 23 | var _ = Describe("CRD Generation", func() { 24 | 25 | }) 26 | -------------------------------------------------------------------------------- /pkg/crd/crd_suite_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package crd_test 18 | 19 | import ( 20 | "testing" 21 | 22 | . "github.com/onsi/ginkgo" 23 | . "github.com/onsi/gomega" 24 | ) 25 | 26 | func TestCRDGeneration(t *testing.T) { 27 | RegisterFailHandler(Fail) 28 | RunSpecs(t, "CRD Generation Suite") 29 | } 30 | -------------------------------------------------------------------------------- /pkg/crd/markers/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package markers defines markers for generating schema valiation 18 | // and CRD structure. 19 | // 20 | // All markers related to CRD generation live in AllDefinitions. 21 | // 22 | // # Validation Markers 23 | // 24 | // Validation markers have values that implement ApplyToSchema 25 | // (crd.SchemaMarker). Any marker implementing this will automatically 26 | // be run after the rest of a given schema node has been generated. 27 | // Markers that need to be run before any other markers can also 28 | // implement ApplyFirst, but this is discouraged and may change 29 | // in the future. It is recommended to implement the ApplyPriority 30 | // interface in combination with ApplyPriorityDefault and 31 | // ApplyPriorityFirst constants. Following is an example of how to 32 | // implement such a marker: 33 | // 34 | // type MyCustomMarker string 35 | // 36 | // func (m MyCustomMarker) ApplyPriority() ApplyPriority { 37 | // return ApplyPriorityFirst 38 | // } 39 | // 40 | // func (m MyCustomMarker) ApplyToSchema(schema *apiext.JSONSchemaProps) error { 41 | // ... 42 | // } 43 | // 44 | // All validation markers start with "+kubebuilder:validation", and 45 | // have the same name as their type name. 46 | // 47 | // # CRD Markers 48 | // 49 | // Markers that modify anything in the CRD itself *except* for the schema 50 | // implement ApplyToCRD (crd.SpecMarker). They are expected to detect whether 51 | // they should apply themselves to a specific version in the CRD (as passed to 52 | // them), or to the root-level CRD for legacy cases. They are applied *after* 53 | // the rest of the CRD is computed. 54 | // 55 | // # Misc 56 | // 57 | // This package also defines the "+groupName" and "+versionName" package-level 58 | // markers, for defining package<->group-version mappings. 59 | package markers 60 | -------------------------------------------------------------------------------- /pkg/crd/markers/package.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package markers 18 | 19 | import ( 20 | "sigs.k8s.io/controller-tools/pkg/markers" 21 | ) 22 | 23 | func init() { 24 | AllDefinitions = append(AllDefinitions, 25 | mustOptional(markers.MakeDefinition("groupName", markers.DescribesPackage, "")). 26 | WithHelp(markers.SimpleHelp("CRD", "specifies the API group name for this package.")), 27 | 28 | must(markers.MakeDefinition("versionName", markers.DescribesPackage, "")). 29 | WithHelp(markers.SimpleHelp("CRD", "overrides the API group version for this package (defaults to the package name).")), 30 | 31 | must(markers.MakeDefinition("kubebuilder:validation:Optional", markers.DescribesPackage, struct{}{})). 32 | WithHelp(markers.SimpleHelp("CRD validation", "specifies that all fields in this package are optional by default.")), 33 | 34 | must(markers.MakeDefinition("kubebuilder:validation:Required", markers.DescribesPackage, struct{}{})). 35 | WithHelp(markers.SimpleHelp("CRD validation", "specifies that all fields in this package are required by default.")), 36 | 37 | must(markers.MakeDefinition("kubebuilder:skip", markers.DescribesPackage, struct{}{})). 38 | WithHelp(markers.SimpleHelp("CRD", "don't consider this package as an API version.")), 39 | ) 40 | } 41 | -------------------------------------------------------------------------------- /pkg/crd/markers/priority.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package markers 18 | 19 | // ApplyPriority designates the order markers should be applied. 20 | // Lower priority indicates it should be applied first 21 | type ApplyPriority int64 22 | 23 | const ( 24 | // ApplyPriorityDefault is the default priority for markers 25 | // that don't implement ApplyPriorityMarker 26 | ApplyPriorityDefault ApplyPriority = 10 27 | 28 | // ApplyPriorityFirst is the priority value assigned to markers 29 | // that implement the ApplyFirst() method 30 | ApplyPriorityFirst ApplyPriority = 1 31 | ) 32 | 33 | // ApplyPriorityMarker designates the order validation markers should be applied. 34 | // Lower priority indicates it should be applied first 35 | type ApplyPriorityMarker interface { 36 | ApplyPriority() ApplyPriority 37 | } 38 | -------------------------------------------------------------------------------- /pkg/crd/testdata/README.md: -------------------------------------------------------------------------------- 1 | # CRD Integration Test testdata 2 | 3 | This contains a tiny module used for testdata for the CRD integration 4 | test. The directory should always be called testdata, so Go treats it 5 | specially. 6 | 7 | The `cronjob_types.go` file contains the input types, and is loosely based 8 | on the CronJob tutorial from the [KubeBuilder 9 | Book](https://book.kubebuilder.io/cronjob-tutorial/cronjob-tutorial.html), but with added 10 | fields to test additional markers and generation behavior. 11 | 12 | If you add a new marker, re-generate the golden output file, 13 | `testdata.kubebuilder.io_cronjobs.yaml`, with (if you have the latest 14 | controller-gen on your path): 15 | 16 | ```bash 17 | go generate 18 | ``` 19 | 20 | or, if you don't have the latest controller-gen on your path, use: 21 | 22 | ```bash 23 | $ /path/to/current/build/of/controller-gen crd paths=. output:dir=. 24 | ``` 25 | 26 | Make sure you review the diff to ensure that it only contains the desired 27 | changes! 28 | 29 | If you didn't add a new marker and this output changes, make sure you have 30 | a good explanation for why generated output needs to change! 31 | -------------------------------------------------------------------------------- /pkg/crd/testdata/deprecated/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | // +groupName=testdata.kubebuilder.io 17 | // +versionName=v1beta2 18 | package deprecated 19 | 20 | import ( 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | ) 23 | 24 | // +kubebuilder:object:root=true 25 | // +kubebuilder:subresource:status 26 | // +kubebuilder:resource:singular=mycronjob 27 | // +kubebuilder:deprecatedversion:warning="use v1 instead, this version causes your data center to catch fire when used on Tuesdays" 28 | 29 | // CronJob is the Schema for the cronjobs API 30 | type CronJob struct { 31 | /* 32 | */ 33 | metav1.TypeMeta `json:",inline"` 34 | metav1.ObjectMeta `json:"metadata,omitempty"` 35 | } 36 | 37 | // +kubebuilder:object:root=true 38 | 39 | // CronJobList contains a list of CronJob 40 | type CronJobList struct { 41 | metav1.TypeMeta `json:",inline"` 42 | metav1.ListMeta `json:"metadata,omitempty"` 43 | Items []CronJob `json:"items"` 44 | } 45 | -------------------------------------------------------------------------------- /pkg/crd/testdata/gen/bar.example.com_foos.v1beta1.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apiextensions.k8s.io/v1beta1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | annotations: 6 | controller-gen.kubebuilder.io/version: (devel) 7 | name: foos.bar.example.com 8 | spec: 9 | group: bar.example.com 10 | names: 11 | kind: Foo 12 | listKind: FooList 13 | plural: foos 14 | singular: foo 15 | scope: Namespaced 16 | validation: 17 | openAPIV3Schema: 18 | properties: 19 | apiVersion: 20 | description: 'APIVersion defines the versioned schema of this representation 21 | of an object. Servers should convert recognized schemas to the latest 22 | internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' 23 | type: string 24 | kind: 25 | description: 'Kind is a string value representing the REST resource this 26 | object represents. Servers may infer this from the endpoint the client 27 | submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' 28 | type: string 29 | metadata: 30 | type: object 31 | spec: 32 | description: Spec comments SHOULD appear in the CRD spec 33 | properties: 34 | defaultedString: 35 | description: This tests that defaulted fields are stripped for v1beta1, 36 | but not for v1 37 | type: string 38 | required: 39 | - defaultedString 40 | type: object 41 | status: 42 | description: Status comments SHOULD appear in the CRD spec 43 | type: object 44 | type: object 45 | version: foo 46 | versions: 47 | - name: foo 48 | served: true 49 | storage: true 50 | -------------------------------------------------------------------------------- /pkg/crd/testdata/gen/bar.example.com_foos.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | annotations: 6 | controller-gen.kubebuilder.io/version: (devel) 7 | name: foos.bar.example.com 8 | spec: 9 | group: bar.example.com 10 | names: 11 | kind: Foo 12 | listKind: FooList 13 | plural: foos 14 | singular: foo 15 | scope: Namespaced 16 | versions: 17 | - name: foo 18 | schema: 19 | openAPIV3Schema: 20 | properties: 21 | apiVersion: 22 | description: |- 23 | APIVersion defines the versioned schema of this representation of an object. 24 | Servers should convert recognized schemas to the latest internal value, and 25 | may reject unrecognized values. 26 | More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources 27 | type: string 28 | kind: 29 | description: |- 30 | Kind is a string value representing the REST resource this object represents. 31 | Servers may infer this from the endpoint the client submits requests to. 32 | Cannot be updated. 33 | In CamelCase. 34 | More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 35 | type: string 36 | metadata: 37 | type: object 38 | spec: 39 | description: Spec comments SHOULD appear in the CRD spec 40 | properties: 41 | defaultedString: 42 | default: fooDefaultString 43 | description: |- 44 | This tests that defaulted fields are stripped for v1beta1, 45 | but not for v1 46 | example: fooExampleString 47 | type: string 48 | required: 49 | - defaultedString 50 | type: object 51 | status: 52 | description: Status comments SHOULD appear in the CRD spec 53 | type: object 54 | type: object 55 | served: true 56 | storage: true 57 | -------------------------------------------------------------------------------- /pkg/crd/testdata/gen/bar.example.com_foos_maxdesclen.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | annotations: 6 | controller-gen.kubebuilder.io/version: (devel) 7 | name: foos.bar.example.com 8 | spec: 9 | group: bar.example.com 10 | names: 11 | kind: Foo 12 | listKind: FooList 13 | plural: foos 14 | singular: foo 15 | scope: Namespaced 16 | versions: 17 | - name: foo 18 | schema: 19 | openAPIV3Schema: 20 | properties: 21 | apiVersion: 22 | description: APIVersion defines the versioned schema of this... 23 | type: string 24 | kind: 25 | description: Kind is a string value representing the REST... 26 | type: string 27 | metadata: 28 | type: object 29 | spec: 30 | description: Spec comments SHOULD appear in the CRD spec 31 | properties: 32 | defaultedString: 33 | default: fooDefaultString 34 | description: This tests that defaulted fields are stripped for... 35 | example: fooExampleString 36 | type: string 37 | required: 38 | - defaultedString 39 | type: object 40 | status: 41 | description: Status comments SHOULD appear in the CRD spec 42 | type: object 43 | type: object 44 | served: true 45 | storage: true 46 | -------------------------------------------------------------------------------- /pkg/crd/testdata/gen/foo_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | //go:generate ../../../../.run-controller-gen.sh crd:crdVersions=v1beta1 paths=. output:dir=. 17 | //go:generate mv bar.example.com_foos.yaml bar.example.com_foos.v1beta1.yaml 18 | //go:generate ../../../../.run-controller-gen.sh crd:crdVersions=v1 paths=. output:dir=. 19 | 20 | // +groupName=bar.example.com 21 | package foo 22 | 23 | import ( 24 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 | ) 26 | 27 | type FooSpec struct { 28 | // This tests that defaulted fields are stripped for v1beta1, 29 | // but not for v1 30 | // +kubebuilder:default=fooDefaultString 31 | // +kubebuilder:example=fooExampleString 32 | DefaultedString string `json:"defaultedString"` 33 | } 34 | type FooStatus struct{} 35 | 36 | type Foo struct { 37 | // TypeMeta comments should NOT appear in the CRD spec 38 | metav1.TypeMeta `json:",inline"` 39 | // ObjectMeta comments should NOT appear in the CRD spec 40 | metav1.ObjectMeta `json:"metadata,omitempty"` 41 | 42 | // Spec comments SHOULD appear in the CRD spec 43 | Spec FooSpec `json:"spec,omitempty"` 44 | // Status comments SHOULD appear in the CRD spec 45 | Status FooStatus `json:"status,omitempty"` 46 | } 47 | -------------------------------------------------------------------------------- /pkg/crd/testdata/gen/zoo/bar.example.com_zoos.v1beta1.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apiextensions.k8s.io/v1beta1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | annotations: 6 | controller-gen.kubebuilder.io/version: (devel) 7 | name: zoos.bar.example.com 8 | spec: 9 | group: bar.example.com 10 | names: 11 | kind: Zoo 12 | listKind: ZooList 13 | plural: zoos 14 | singular: zoo 15 | scope: Namespaced 16 | validation: 17 | openAPIV3Schema: 18 | properties: 19 | apiVersion: 20 | description: 'APIVersion defines the versioned schema of this representation 21 | of an object. Servers should convert recognized schemas to the latest 22 | internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' 23 | type: string 24 | kind: 25 | description: 'Kind is a string value representing the REST resource this 26 | object represents. Servers may infer this from the endpoint the client 27 | submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' 28 | type: string 29 | metadata: 30 | type: object 31 | spec: 32 | description: Spec comments SHOULD appear in the CRD spec 33 | properties: 34 | defaultedString: 35 | description: This tests that defaulted fields are stripped for v1beta1, 36 | but not for v1 37 | type: string 38 | required: 39 | - defaultedString 40 | type: object 41 | status: 42 | description: Status comments SHOULD appear in the CRD spec 43 | type: object 44 | type: object 45 | version: zoo 46 | versions: 47 | - name: zoo 48 | served: true 49 | storage: true 50 | -------------------------------------------------------------------------------- /pkg/crd/testdata/gen/zoo/bar.example.com_zoos.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | annotations: 6 | controller-gen.kubebuilder.io/version: (devel) 7 | name: zoos.bar.example.com 8 | spec: 9 | group: bar.example.com 10 | names: 11 | kind: Zoo 12 | listKind: ZooList 13 | plural: zoos 14 | singular: zoo 15 | scope: Namespaced 16 | versions: 17 | - name: zoo 18 | schema: 19 | openAPIV3Schema: 20 | properties: 21 | apiVersion: 22 | description: |- 23 | APIVersion defines the versioned schema of this representation of an object. 24 | Servers should convert recognized schemas to the latest internal value, and 25 | may reject unrecognized values. 26 | More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources 27 | type: string 28 | kind: 29 | description: |- 30 | Kind is a string value representing the REST resource this object represents. 31 | Servers may infer this from the endpoint the client submits requests to. 32 | Cannot be updated. 33 | In CamelCase. 34 | More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 35 | type: string 36 | metadata: 37 | type: object 38 | spec: 39 | description: Spec comments SHOULD appear in the CRD spec 40 | properties: 41 | defaultedString: 42 | default: zooDefaultString 43 | description: |- 44 | This tests that defaulted fields are stripped for v1beta1, 45 | but not for v1 46 | example: zooExampleString 47 | type: string 48 | required: 49 | - defaultedString 50 | type: object 51 | status: 52 | description: Status comments SHOULD appear in the CRD spec 53 | type: object 54 | type: object 55 | served: true 56 | storage: true 57 | -------------------------------------------------------------------------------- /pkg/crd/testdata/gen/zoo/zoo_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | //go:generate ../../../../../.run-controller-gen.sh crd:crdVersions=v1beta1 paths=. output:dir=. 17 | //go:generate mv bar.example.com_zoos.yaml bar.example.com_zoos.v1beta1.yaml 18 | //go:generate ../../../../../.run-controller-gen.sh crd:crdVersions=v1 paths=. output:dir=. 19 | 20 | // +groupName=bar.example.com 21 | package zoo 22 | 23 | import ( 24 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 | ) 26 | 27 | type ZooSpec struct { 28 | // This tests that defaulted fields are stripped for v1beta1, 29 | // but not for v1 30 | // +kubebuilder:default=zooDefaultString 31 | // +kubebuilder:example=zooExampleString 32 | DefaultedString string `json:"defaultedString"` 33 | } 34 | type ZooStatus struct{} 35 | 36 | type Zoo struct { 37 | // TypeMeta comments should NOT appear in the CRD spec 38 | metav1.TypeMeta `json:",inline"` 39 | // ObjectMeta comments should NOT appear in the CRD spec 40 | metav1.ObjectMeta `json:"metadata,omitempty"` 41 | 42 | // Spec comments SHOULD appear in the CRD spec 43 | Spec ZooSpec `json:"spec,omitempty"` 44 | // Status comments SHOULD appear in the CRD spec 45 | Status ZooStatus `json:"status,omitempty"` 46 | } 47 | -------------------------------------------------------------------------------- /pkg/crd/testdata/go.mod: -------------------------------------------------------------------------------- 1 | module testdata.kubebuilder.io/cronjob 2 | 3 | go 1.22.0 4 | 5 | toolchain go1.22.1 6 | 7 | require ( 8 | k8s.io/api v0.31.0 9 | k8s.io/apimachinery v0.31.0 10 | ) 11 | 12 | require ( 13 | github.com/fxamacker/cbor/v2 v2.7.0 // indirect 14 | github.com/go-logr/logr v1.4.2 // indirect 15 | github.com/gogo/protobuf v1.3.2 // indirect 16 | github.com/google/gofuzz v1.2.0 // indirect 17 | github.com/json-iterator/go v1.1.12 // indirect 18 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 19 | github.com/modern-go/reflect2 v1.0.2 // indirect 20 | github.com/x448/float16 v0.8.4 // indirect 21 | golang.org/x/net v0.26.0 // indirect 22 | golang.org/x/text v0.16.0 // indirect 23 | gopkg.in/inf.v0 v0.9.1 // indirect 24 | gopkg.in/yaml.v2 v2.4.0 // indirect 25 | k8s.io/klog/v2 v2.130.1 // indirect 26 | k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect 27 | sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect 28 | sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect 29 | ) 30 | -------------------------------------------------------------------------------- /pkg/crd/testdata/internal_version/internal_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | // +kubebuilder:skip 17 | package internal_version 18 | 19 | import ( 20 | corev1 "k8s.io/api/core/v1" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | ) 23 | 24 | // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! 25 | // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. 26 | 27 | // CronJobSpec defines the desired state of CronJob 28 | type CronJobSpec struct { 29 | // The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. 30 | Schedule string 31 | } 32 | 33 | // CronJobStatus defines the observed state of CronJob 34 | type CronJobStatus struct { 35 | // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster 36 | // Important: Run "make" to regenerate code after modifying this file 37 | 38 | // A list of pointers to currently running jobs. 39 | // +optional 40 | Active []corev1.ObjectReference 41 | 42 | // Information when was the last time the job was successfully scheduled. 43 | // +optional 44 | LastScheduleTime *metav1.Time 45 | 46 | // Information about the last time the job was successfully scheduled, 47 | // with microsecond precision. 48 | // +optional 49 | LastScheduleMicroTime *metav1.MicroTime 50 | } 51 | 52 | // +kubebuilder:object:root=true 53 | // +kubebuilder:subresource:status 54 | // +kubebuilder:resource 55 | 56 | // CronJob is the Schema for the cronjobs API 57 | type CronJob struct { 58 | /* 59 | */ 60 | metav1.TypeMeta 61 | metav1.ObjectMeta 62 | 63 | Spec CronJobSpec 64 | Status CronJobStatus 65 | } 66 | 67 | // +kubebuilder:object:root=true 68 | 69 | // CronJobList contains a list of CronJob 70 | type CronJobList struct { 71 | metav1.TypeMeta 72 | metav1.ListMeta 73 | Items []CronJob 74 | } 75 | 76 | func init() { 77 | SchemeBuilder.Register(&CronJob{}, &CronJobList{}) 78 | } 79 | -------------------------------------------------------------------------------- /pkg/crd/testdata/job/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | // +groupName=testdata.kubebuilder.io 17 | // +versionName=v1beta1 18 | package job 19 | 20 | import ( 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | 23 | "testdata.kubebuilder.io/cronjob/unserved" 24 | ) 25 | 26 | // +kubebuilder:object:root=true 27 | // +kubebuilder:subresource:status 28 | // +kubebuilder:resource:singular=job 29 | 30 | // JobSpec is the spec for the jobs API. 31 | type JobSpec struct { 32 | // FriendlyName is the friendly name for the job. 33 | // 34 | // +kubebuilder:validation:MinLength=5 35 | FriendlyName string `json:"friendlyName"` 36 | 37 | // Count is the number of times a job may be executed. 38 | // 39 | // +kubebuilder:validation:Minimum=0 40 | // +kubebuilder:validation:Maximum=10 41 | Count int32 `json:"count"` 42 | 43 | // CronJob is the spec for the related CrongJob. 44 | CronnJob unserved.CronJobSpec `json:"crongJob"` 45 | } 46 | 47 | // Job is the Schema for the jobs API 48 | type Job struct { 49 | /* 50 | */ 51 | metav1.TypeMeta `json:",inline"` 52 | metav1.ObjectMeta `json:"metadata,omitempty"` 53 | 54 | Spec JobSpec `json:"spec"` 55 | } 56 | 57 | // +kubebuilder:object:root=true 58 | 59 | // JobList contains a list of Job 60 | type JobList struct { 61 | metav1.TypeMeta `json:",inline"` 62 | metav1.ListMeta `json:"metadata,omitempty"` 63 | Items []Job `json:"items"` 64 | } 65 | -------------------------------------------------------------------------------- /pkg/crd/testdata/multiple_versions/common.go: -------------------------------------------------------------------------------- 1 | //go:generate ../../../../.run-controller-gen.sh crd paths=./v1beta1;./v1beta2 output:dir=. 2 | 3 | package multiple_versions 4 | 5 | type InnerStruct struct { 6 | Foo string `json:"foo,omitempty"` 7 | } 8 | 9 | type OuterStruct struct { 10 | // +structType=atomic 11 | Struct InnerStruct `json:"struct,omitempty"` 12 | } 13 | -------------------------------------------------------------------------------- /pkg/crd/testdata/multiple_versions/v1beta1/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | // +groupName=testdata.kubebuilder.io 17 | package v1beta1 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | multiver "testdata.kubebuilder.io/cronjob/multiple_versions" 22 | ) 23 | 24 | type VersionedResourceSpec struct { 25 | Struct multiver.OuterStruct `json:"struct,omitempty"` 26 | } 27 | 28 | // +kubebuilder:object:root=true 29 | // +kubebuilder:subresource:status 30 | // +kubebuilder:resource:singular=versionedresource 31 | 32 | type VersionedResource struct { 33 | metav1.TypeMeta `json:",inline"` 34 | metav1.ObjectMeta `json:"metadata,omitempty"` 35 | 36 | Spec VersionedResourceSpec `json:"spec"` 37 | } 38 | 39 | // +kubebuilder:object:root=true 40 | 41 | type VersionedResourceList struct { 42 | metav1.TypeMeta `json:",inline"` 43 | metav1.ListMeta `json:"metadata,omitempty"` 44 | Items []VersionedResource `json:"items"` 45 | } 46 | -------------------------------------------------------------------------------- /pkg/crd/testdata/multiple_versions/v1beta2/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | // +groupName=testdata.kubebuilder.io 17 | package v1beta2 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | multiver "testdata.kubebuilder.io/cronjob/multiple_versions" 22 | ) 23 | 24 | type VersionedResourceSpec struct { 25 | Struct multiver.OuterStruct `json:"struct,omitempty"` 26 | } 27 | 28 | // +kubebuilder:storageversion 29 | // +kubebuilder:object:root=true 30 | // +kubebuilder:subresource:status 31 | // +kubebuilder:resource:singular=versionedresource 32 | 33 | type VersionedResource struct { 34 | metav1.TypeMeta `json:",inline"` 35 | metav1.ObjectMeta `json:"metadata,omitempty"` 36 | 37 | Spec VersionedResourceSpec `json:"spec"` 38 | } 39 | 40 | // +kubebuilder:object:root=true 41 | 42 | type VersionedResourceList struct { 43 | metav1.TypeMeta `json:",inline"` 44 | metav1.ListMeta `json:"metadata,omitempty"` 45 | Items []VersionedResource `json:"items"` 46 | } 47 | -------------------------------------------------------------------------------- /pkg/crd/testdata/nogroup/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | // +groupName= 17 | package nogroup 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | ) 22 | 23 | // +kubebuilder:object:root=true 24 | 25 | // CronJob is the Schema for the cronjobs API 26 | type CronJob struct { 27 | metav1.TypeMeta `json:",inline"` 28 | metav1.ObjectMeta `json:"metadata,omitempty"` 29 | } 30 | -------------------------------------------------------------------------------- /pkg/crd/testdata/plural/plural.example.com_testquotas.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | annotations: 6 | controller-gen.kubebuilder.io/version: (devel) 7 | name: testquotas.plural.example.com 8 | spec: 9 | group: plural.example.com 10 | names: 11 | kind: TestQuota 12 | listKind: TestQuotaList 13 | plural: testquotas 14 | singular: testquota 15 | scope: Namespaced 16 | versions: 17 | - name: v1 18 | schema: 19 | openAPIV3Schema: 20 | properties: 21 | apiVersion: 22 | description: |- 23 | APIVersion defines the versioned schema of this representation of an object. 24 | Servers should convert recognized schemas to the latest internal value, and 25 | may reject unrecognized values. 26 | More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources 27 | type: string 28 | kind: 29 | description: |- 30 | Kind is a string value representing the REST resource this object represents. 31 | Servers may infer this from the endpoint the client submits requests to. 32 | Cannot be updated. 33 | In CamelCase. 34 | More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 35 | type: string 36 | metadata: 37 | type: object 38 | test: 39 | type: string 40 | type: object 41 | served: true 42 | storage: true 43 | -------------------------------------------------------------------------------- /pkg/crd/testdata/plural/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | //go:generate ../../../../.run-controller-gen.sh crd:crdVersions=v1 paths=. output:dir=. 17 | 18 | // +groupName=plural.example.com 19 | // +versionName=v1 20 | package plural 21 | 22 | import ( 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | ) 25 | 26 | type TestQuota struct { 27 | metav1.TypeMeta `json:",inline"` 28 | metav1.ObjectMeta `json:"metadata,omitempty"` 29 | 30 | Test string `json:"test,omitempty"` 31 | } 32 | -------------------------------------------------------------------------------- /pkg/crd/testdata/testdata._cronjobs.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apiextensions.k8s.io/v1 3 | kind: CustomResourceDefinition 4 | metadata: 5 | annotations: 6 | controller-gen.kubebuilder.io/version: (devel) 7 | name: cronjobs. 8 | spec: 9 | group: "" 10 | names: 11 | kind: CronJob 12 | listKind: CronJobList 13 | plural: cronjobs 14 | singular: cronjob 15 | scope: Namespaced 16 | versions: 17 | - name: nogroup 18 | schema: 19 | openAPIV3Schema: 20 | description: CronJob is the Schema for the cronjobs API 21 | properties: 22 | apiVersion: 23 | description: |- 24 | APIVersion defines the versioned schema of this representation of an object. 25 | Servers should convert recognized schemas to the latest internal value, and 26 | may reject unrecognized values. 27 | More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources 28 | type: string 29 | kind: 30 | description: |- 31 | Kind is a string value representing the REST resource this object represents. 32 | Servers may infer this from the endpoint the client submits requests to. 33 | Cannot be updated. 34 | In CamelCase. 35 | More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 36 | type: string 37 | metadata: 38 | type: object 39 | type: object 40 | served: true 41 | storage: true 42 | -------------------------------------------------------------------------------- /pkg/crd/testdata/unserved/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | // +groupName=testdata.kubebuilder.io 17 | // +versionName=v1beta1 18 | package unserved 19 | 20 | import ( 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | ) 23 | 24 | // CronJobSpec defines the desired state of CronJob 25 | type CronJobSpec struct { 26 | // This tests that markers that are allowed on both fields and types are applied to fields 27 | // +kubebuilder:validation:MinLength=4 28 | TwoOfAKindPart0 string `json:"twoOfAKindPart0"` 29 | 30 | // +kubebuilder:validation:Minimum=-2 31 | // +kubebuilder:validation:Maximum=2 32 | // +kubebuilder:validation:MultipleOf=2 33 | Int32WithValidations int32 `json:"int32WithValidations"` 34 | } 35 | 36 | // +kubebuilder:object:root=true 37 | // +kubebuilder:subresource:status 38 | // +kubebuilder:resource:singular=mycronjob 39 | // +kubebuilder:unservedversion 40 | 41 | // CronJob is the Schema for the cronjobs API 42 | type CronJob struct { 43 | /* 44 | */ 45 | metav1.TypeMeta `json:",inline"` 46 | metav1.ObjectMeta `json:"metadata,omitempty"` 47 | 48 | Spec CronJobSpec `json:"spec,omitempty"` 49 | } 50 | 51 | // +kubebuilder:object:root=true 52 | 53 | // CronJobList contains a list of CronJob 54 | type CronJobList struct { 55 | metav1.TypeMeta `json:",inline"` 56 | metav1.ListMeta `json:"metadata,omitempty"` 57 | Items []CronJob `json:"items"` 58 | } 59 | -------------------------------------------------------------------------------- /pkg/crd/testdata/wrong_title_format/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | // +groupName=testdata.kubebuilder.io 17 | // +versionName=v1beta1 18 | package job 19 | 20 | import ( 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | 23 | "testdata.kubebuilder.io/cronjob/unserved" 24 | ) 25 | 26 | // +kubebuilder:object:root=true 27 | // +kubebuilder:subresource:status 28 | // +kubebuilder:resource:singular=job 29 | 30 | type TestType struct { 31 | // Count is the number of times a job may be executed. 32 | // 33 | // +kubebuilder:title={} 34 | Count int32 `json:"count"` 35 | } 36 | 37 | // JobSpec is the spec for the jobs API. 38 | type JobSpec struct { 39 | // FriendlyName is the friendly name for the job. 40 | // 41 | // +kubebuilder:title=123 42 | FriendlyName string `json:"friendlyName"` 43 | 44 | // CronJob is the spec for the related CrongJob. 45 | CronnJob unserved.CronJobSpec `json:"crongJob"` 46 | } 47 | 48 | // Job is the Schema for the jobs API 49 | type Job struct { 50 | /* 51 | */ 52 | metav1.TypeMeta `json:",inline"` 53 | metav1.ObjectMeta `json:"metadata,omitempty"` 54 | 55 | Spec JobSpec `json:"spec"` 56 | } 57 | 58 | // +kubebuilder:object:root=true 59 | 60 | // JobList contains a list of Job 61 | type JobList struct { 62 | metav1.TypeMeta `json:",inline"` 63 | metav1.ListMeta `json:"metadata,omitempty"` 64 | Items []Job `json:"items"` 65 | } 66 | -------------------------------------------------------------------------------- /pkg/deepcopy/deepcopy_suite_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package deepcopy_test 18 | 19 | import ( 20 | "testing" 21 | 22 | . "github.com/onsi/ginkgo" 23 | . "github.com/onsi/gomega" 24 | ) 25 | 26 | func TestObjectGeneration(t *testing.T) { 27 | RegisterFailHandler(Fail) 28 | RunSpecs(t, "DeepCopy/runtime.Object Generation Suite") 29 | } 30 | -------------------------------------------------------------------------------- /pkg/deepcopy/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package deepcopy generates DeepCopy, DeepCopyInto, and DeepCopyObject 18 | // implementations for types. 19 | // 20 | // It's ported from k8s.io/code-generator's / k8s.io/gengo's deepcopy-gen, 21 | // but it's scoped specifically to runtime.Object and skips support for 22 | // deepcopying interfaces, which aren't handled in CRDs anyway. 23 | package deepcopy 24 | -------------------------------------------------------------------------------- /pkg/deepcopy/testdata/README.md: -------------------------------------------------------------------------------- 1 | # DeepCopy Integration Test testdata 2 | 3 | This contains a tiny module used for testdata for the DeepCopy integration 4 | test. The directory should always be called testdata, so Go treats it 5 | specially. 6 | 7 | The `cronjob_types.go` file contains the input types, and is loosely based 8 | on the CronJob tutorial from the [KubeBuilder 9 | Book](https://book.kubebuilder.io/cronjob-tutorial/cronjob-tutorial.html), but with added 10 | fields to test additional DeepCopy cases. 11 | 12 | If you for some reason need to change deepcopy generation, you can 13 | re-generate the golden output file, 14 | `zz_generated.deepcopy.go`, with (if you have the latest 15 | controller-gen on your path): 16 | 17 | ```bash 18 | go generate 19 | ``` 20 | 21 | or, if you don't have the latest controller-gen on your path, use: 22 | 23 | ```bash 24 | $ /path/to/current/build/of/controller-gen object paths=. 25 | ``` 26 | 27 | 28 | Make sure you review the diff to ensure that it only contains the desired 29 | changes! 30 | 31 | If you didn't add a new marker and this output changes, make sure you have 32 | a good explanation for why generated output needs to change! 33 | -------------------------------------------------------------------------------- /pkg/deepcopy/testdata/go.mod: -------------------------------------------------------------------------------- 1 | module testdata.kubebuilder.io/cronjob 2 | 3 | go 1.15 4 | 5 | require ( 6 | k8s.io/api v0.19.2 7 | k8s.io/apimachinery v0.19.2 8 | ) 9 | -------------------------------------------------------------------------------- /pkg/deepcopy/zz_generated.markerhelp.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | 3 | /* 4 | Copyright2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Code generated by helpgen. DO NOT EDIT. 20 | 21 | package deepcopy 22 | 23 | import ( 24 | "sigs.k8s.io/controller-tools/pkg/markers" 25 | ) 26 | 27 | func (Generator) Help() *markers.DefinitionHelp { 28 | return &markers.DefinitionHelp{ 29 | Category: "", 30 | DetailedHelp: markers.DetailedHelp{ 31 | Summary: "generates code containing DeepCopy, DeepCopyInto, and", 32 | Details: "DeepCopyObject method implementations.", 33 | }, 34 | FieldHelp: map[string]markers.DetailedHelp{ 35 | "HeaderFile": { 36 | Summary: "specifies the header text (e.g. license) to prepend to generated files.", 37 | Details: "", 38 | }, 39 | "Year": { 40 | Summary: "specifies the year to substitute for \" YEAR\" in the header file.", 41 | Details: "", 42 | }, 43 | }, 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pkg/genall/help/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package help contains utilities for actually writing out marker help. 18 | // 19 | // Namely, it contains a series of structs (and helpers for producing them) 20 | // that represent a merged view of marker definition and help that can be used 21 | // for consumption by the pretty subpackage (for terminal help) or serialized 22 | // as JSON (e.g. for generating HTML help). 23 | package help 24 | -------------------------------------------------------------------------------- /pkg/genall/help/pretty/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package pretty contains utilities for formatting terminal help output, 18 | // and a use of those to display marker help. 19 | // 20 | // # Terminal Output 21 | // 22 | // The Span interface and Table struct allow you to construct tables with 23 | // colored formatting, without causing ANSI formatting characters to mess up width 24 | // calculations. 25 | // 26 | // # Marker Help 27 | // 28 | // The MarkersSummary prints a summary table for marker help, while the MarkersDetails 29 | // prints out more detailed information, with explainations of the individual marker fields. 30 | package pretty 31 | -------------------------------------------------------------------------------- /pkg/genall/help/pretty/table.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package pretty 18 | 19 | // TableCalculator calculates column widths (with optional padding) 20 | // for a table based on the maximum required column width. 21 | type TableCalculator struct { 22 | cellSizesByCol [][]int 23 | 24 | Padding int 25 | MaxWidth int 26 | } 27 | 28 | // AddRowSizes registers a new row with cells of the given sizes. 29 | func (c *TableCalculator) AddRowSizes(cellSizes ...int) { 30 | if len(cellSizes) > len(c.cellSizesByCol) { 31 | for range cellSizes[len(c.cellSizesByCol):] { 32 | c.cellSizesByCol = append(c.cellSizesByCol, []int(nil)) 33 | } 34 | } 35 | for i, size := range cellSizes { 36 | c.cellSizesByCol[i] = append(c.cellSizesByCol[i], size) 37 | } 38 | } 39 | 40 | // ColumnWidths calculates the appropriate column sizes given the 41 | // previously registered rows. 42 | func (c *TableCalculator) ColumnWidths() []int { 43 | maxColWidths := make([]int, len(c.cellSizesByCol)) 44 | 45 | for colInd, cellSizes := range c.cellSizesByCol { 46 | maxValue := 0 47 | for _, cellSize := range cellSizes { 48 | if maxValue < cellSize { 49 | maxValue = cellSize 50 | } 51 | } 52 | maxColWidths[colInd] = maxValue 53 | } 54 | 55 | actualMaxWidth := c.MaxWidth - c.Padding 56 | for i, width := range maxColWidths { 57 | if actualMaxWidth > 0 && width > actualMaxWidth { 58 | maxColWidths[i] = actualMaxWidth 59 | } 60 | maxColWidths[i] += c.Padding 61 | } 62 | 63 | return maxColWidths 64 | } 65 | -------------------------------------------------------------------------------- /pkg/genall/input.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package genall 18 | 19 | import ( 20 | "io" 21 | "os" 22 | ) 23 | 24 | // InputRule describes how to load non-code boilerplate artifacts. 25 | // It's not used for loading code. 26 | type InputRule interface { 27 | // OpenForRead opens the given non-code artifact for reading. 28 | OpenForRead(path string) (io.ReadCloser, error) 29 | } 30 | type inputFromFileSystem struct{} 31 | 32 | func (inputFromFileSystem) OpenForRead(path string) (io.ReadCloser, error) { 33 | return os.Open(path) 34 | } 35 | 36 | // InputFromFileSystem reads from the filesystem as normal. 37 | var InputFromFileSystem = inputFromFileSystem{} 38 | -------------------------------------------------------------------------------- /pkg/loader/errors.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package loader 18 | 19 | import ( 20 | "errors" 21 | "fmt" 22 | "go/token" 23 | ) 24 | 25 | // PositionedError represents some error with an associated position. 26 | // The position is tied to some external token.FileSet. 27 | type PositionedError struct { 28 | Pos token.Pos 29 | error 30 | } 31 | 32 | // Node is the intersection of go/ast.Node and go/types.Var. 33 | type Node interface { 34 | Pos() token.Pos // position of first character belonging to the node 35 | } 36 | 37 | // ErrFromNode returns the given error, with additional information 38 | // attaching it to the given AST node. It will automatically map 39 | // over error lists. 40 | func ErrFromNode(err error, node Node) error { 41 | var asList ErrList 42 | if isList := errors.As(err, &asList); isList { 43 | resList := make(ErrList, len(asList)) 44 | for i, baseErr := range asList { 45 | resList[i] = ErrFromNode(baseErr, node) 46 | } 47 | return resList 48 | } 49 | return PositionedError{ 50 | Pos: node.Pos(), 51 | error: err, 52 | } 53 | } 54 | 55 | // MaybeErrList constructs an ErrList if the given list of 56 | // errors has any errors, otherwise returning nil. 57 | func MaybeErrList(errs []error) error { 58 | if len(errs) == 0 { 59 | return nil 60 | } 61 | return ErrList(errs) 62 | } 63 | 64 | // ErrList is a list of errors aggregated together into a single error. 65 | type ErrList []error 66 | 67 | func (l ErrList) Error() string { 68 | return fmt.Sprintf("%v", []error(l)) 69 | } 70 | -------------------------------------------------------------------------------- /pkg/loader/loader_suite_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package loader_test 18 | 19 | import ( 20 | "testing" 21 | 22 | . "github.com/onsi/ginkgo" 23 | . "github.com/onsi/gomega" 24 | ) 25 | 26 | func TestLoader(t *testing.T) { 27 | RegisterFailHandler(Fail) 28 | RunSpecs(t, "Loader Patching Suite") 29 | } 30 | -------------------------------------------------------------------------------- /pkg/loader/paths.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package loader 18 | 19 | import ( 20 | "strings" 21 | ) 22 | 23 | // NonVendorPath returns a package path that does not include anything before the 24 | // last vendor directory. This is useful for when using vendor directories, 25 | // and using go/types.Package.Path(), which returns the full path including vendor. 26 | // 27 | // If you're using this, make sure you really need it -- it's better to index by 28 | // the actual Package object when you can. 29 | func NonVendorPath(rawPath string) string { 30 | parts := strings.Split(rawPath, "/vendor/") 31 | return parts[len(parts)-1] 32 | } 33 | -------------------------------------------------------------------------------- /pkg/loader/testmod/dummy.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package dummy 18 | -------------------------------------------------------------------------------- /pkg/loader/testmod/go.mod: -------------------------------------------------------------------------------- 1 | module sigs.k8s.io/controller-tools/pkg/loader/testmod 2 | 3 | go 1.17 4 | 5 | replace sigs.k8s.io/controller-tools/pkg/loader/testmod/submod1 => ./submod1 6 | 7 | require sigs.k8s.io/controller-tools/pkg/loader/testmod/submod1 v0.0.0-00010101000000-000000000000 // indirect 8 | -------------------------------------------------------------------------------- /pkg/loader/testmod/subdir1/dummy.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package dummy 18 | -------------------------------------------------------------------------------- /pkg/loader/testmod/subdir1/subdir1/dummy.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package dummy 18 | -------------------------------------------------------------------------------- /pkg/loader/testmod/subdir1/subdir2/dummy.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package dummy 18 | -------------------------------------------------------------------------------- /pkg/loader/testmod/subdir1/submod1/dummy.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package dummy 18 | -------------------------------------------------------------------------------- /pkg/loader/testmod/subdir1/submod1/go.mod: -------------------------------------------------------------------------------- 1 | module sigs.k8s.io/controller-tools/pkg/loader/testmod/subdir1/submod1 2 | 3 | go 1.17 4 | -------------------------------------------------------------------------------- /pkg/loader/testmod/submod1/dummy.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package dummy 18 | -------------------------------------------------------------------------------- /pkg/loader/testmod/submod1/go.mod: -------------------------------------------------------------------------------- 1 | module sigs.k8s.io/controller-tools/pkg/loader/testmod/submod1 2 | 3 | go 1.17 4 | -------------------------------------------------------------------------------- /pkg/loader/testmod/submod1/subdir1/dummy.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package dummy 18 | -------------------------------------------------------------------------------- /pkg/loader/visit.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package loader 18 | 19 | import ( 20 | "go/ast" 21 | "reflect" 22 | "strconv" 23 | ) 24 | 25 | // TypeCallback is a callback called for each raw AST (gendecl, typespec) combo. 26 | type TypeCallback func(file *ast.File, decl *ast.GenDecl, spec *ast.TypeSpec) 27 | 28 | // EachType calls the given callback for each (gendecl, typespec) combo in the 29 | // given package. Generally, using markers.EachType is better when working 30 | // with marker data, and has a more convinient representation. 31 | func EachType(pkg *Package, cb TypeCallback) { 32 | visitor := &typeVisitor{ 33 | callback: cb, 34 | } 35 | pkg.NeedSyntax() 36 | for _, file := range pkg.Syntax { 37 | visitor.file = file 38 | ast.Walk(visitor, file) 39 | } 40 | } 41 | 42 | // typeVisitor visits all TypeSpecs, calling the given callback for each. 43 | type typeVisitor struct { 44 | callback TypeCallback 45 | decl *ast.GenDecl 46 | file *ast.File 47 | } 48 | 49 | // Visit visits all TypeSpecs. 50 | func (v *typeVisitor) Visit(node ast.Node) ast.Visitor { 51 | if node == nil { 52 | v.decl = nil 53 | return v 54 | } 55 | 56 | switch typedNode := node.(type) { 57 | case *ast.File: 58 | v.file = typedNode 59 | return v 60 | case *ast.GenDecl: 61 | v.decl = typedNode 62 | return v 63 | case *ast.TypeSpec: 64 | v.callback(v.file, v.decl, typedNode) 65 | return nil // don't recurse 66 | default: 67 | return nil 68 | } 69 | } 70 | 71 | // ParseAstTag parses the given raw tag literal into a reflect.StructTag. 72 | func ParseAstTag(tag *ast.BasicLit) reflect.StructTag { 73 | if tag == nil { 74 | return reflect.StructTag("") 75 | } 76 | tagStr, err := strconv.Unquote(tag.Value) 77 | if err != nil { 78 | return reflect.StructTag("") 79 | } 80 | return reflect.StructTag(tagStr) 81 | } 82 | -------------------------------------------------------------------------------- /pkg/markers/regutil.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package markers 18 | 19 | // Must panics on errors creating definitions. 20 | func Must(def *Definition, err error) *Definition { 21 | if err != nil { 22 | panic(err) 23 | } 24 | return def 25 | } 26 | 27 | // RegisterAll attempts to register all definitions against the given registry, 28 | // stopping and returning if an error occurs. 29 | func RegisterAll(reg *Registry, defs ...*Definition) error { 30 | for _, def := range defs { 31 | if err := reg.Register(def); err != nil { 32 | return err 33 | } 34 | } 35 | return nil 36 | } 37 | -------------------------------------------------------------------------------- /pkg/rbac/rbac_suite_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package rbac_test 18 | 19 | import ( 20 | "testing" 21 | 22 | . "github.com/onsi/ginkgo" 23 | . "github.com/onsi/gomega" 24 | ) 25 | 26 | func TestCRDGeneration(t *testing.T) { 27 | RegisterFailHandler(Fail) 28 | RunSpecs(t, "RBAC Generation Suite") 29 | } 30 | -------------------------------------------------------------------------------- /pkg/rbac/testdata/README.md: -------------------------------------------------------------------------------- 1 | # RBAC Integration Test testdata 2 | 3 | This contains a tiny module used for testdata for the RBAC integration 4 | test. The directory should always be called testdata, so Go treats it 5 | specially. 6 | 7 | If you add a new marker, re-generate the golden output file, 8 | `role.yaml`, with: 9 | 10 | ```bash 11 | $ /path/to/current/build/of/controller-gen rbac:roleName=manager-role paths=. output:dir=. 12 | ``` 13 | 14 | Make sure you review the diff to ensure that it only contains the desired 15 | changes! 16 | 17 | If you didn't add a new marker and this output changes, make sure you have 18 | a good explanation for why generated output needs to change! 19 | -------------------------------------------------------------------------------- /pkg/schemapatcher/crdschema_suite_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package schemapatcher_test 18 | 19 | import ( 20 | "testing" 21 | 22 | . "github.com/onsi/ginkgo" 23 | . "github.com/onsi/gomega" 24 | ) 25 | 26 | func TestInPlaceCRDSchemaGeneration(t *testing.T) { 27 | RegisterFailHandler(Fail) 28 | RunSpecs(t, "In-Place CRD Patching Suite") 29 | } 30 | -------------------------------------------------------------------------------- /pkg/schemapatcher/internal/yaml/convert.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package yaml 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | 23 | "gopkg.in/yaml.v3" 24 | ) 25 | 26 | // ToYAML converts some object that serializes to JSON into a YAML node tree. 27 | // It's useful since it pays attention to JSON tags, unlike yaml.Unmarshal or 28 | // yaml.Node.Decode. 29 | func ToYAML(rawObj interface{}) (*yaml.Node, error) { 30 | if rawObj == nil { 31 | return &yaml.Node{Kind: yaml.ScalarNode, Value: "null", Tag: "!!null"}, nil 32 | } 33 | 34 | rawJSON, err := json.Marshal(rawObj) 35 | if err != nil { 36 | return nil, fmt.Errorf("failed to marshal object: %w", err) 37 | } 38 | 39 | var out yaml.Node 40 | if err := yaml.Unmarshal(rawJSON, &out); err != nil { 41 | return nil, fmt.Errorf("unable to unmarshal marshalled object: %w", err) 42 | } 43 | return &out, nil 44 | } 45 | 46 | // changeAll calls the given callback for all nodes in 47 | // the given YAML node tree. 48 | func changeAll(root *yaml.Node, cb func(*yaml.Node)) { 49 | cb(root) 50 | for _, child := range root.Content { 51 | changeAll(child, cb) 52 | } 53 | } 54 | 55 | // SetStyle sets the style for all nodes in the given 56 | // node tree to the given style. 57 | func SetStyle(root *yaml.Node, style yaml.Style) { 58 | changeAll(root, func(node *yaml.Node) { 59 | node.Style = style 60 | }) 61 | } 62 | -------------------------------------------------------------------------------- /pkg/schemapatcher/internal/yaml/yaml_suite_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package yaml 18 | 19 | import ( 20 | "testing" 21 | 22 | . "github.com/onsi/ginkgo" 23 | . "github.com/onsi/gomega" 24 | ) 25 | 26 | func TestYAMLEditing(t *testing.T) { 27 | RegisterFailHandler(Fail) 28 | RunSpecs(t, "In-place YAML Operations Suite") 29 | } 30 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | ../../../.run-controller-gen.sh schemapatch:manifests=./manifests output:dir=./expected paths=./apis/... 3 | egrep -v -- "- foo" < expected/kubebuilder-example-crd.yaml > manifests/kubebuilder-example-crd.yaml 4 | egrep -v -- "- foo" < expected/kubebuilder-example-crd.v1.yaml > manifests/kubebuilder-example-crd.v1.yaml 5 | egrep -v -- "- foo" < expected/legacy-example-crd.yaml > manifests/legacy-example-crd.yaml 6 | 7 | .PHONY: all 8 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/README.md: -------------------------------------------------------------------------------- 1 | # CRD Schema Patcher Integration Test testdata 2 | 3 | This contains a tiny module used for testdata for the CRD Schema Patcher 4 | integration test. The directory should always be called testdata, so Go 5 | treats it specially. 6 | 7 | The types in `apis/` represent different CRD schema versions that 8 | are either expected to change or not change. 9 | 10 | The `kubebuilder` API group contains types that look like modern 11 | KubeBuilder-generated types, while the `legacy` API group contains types 12 | that look like core k8s/legacy kubebuilder types. 13 | 14 | The `manifests` directory contains input manifests that will be patched, 15 | while `expected` contains expected output from the patching process. 16 | 17 | It's *highly* unlikely that the generated expected manifests will 18 | ever change from these -- if they do, you've probably broken something. 19 | Nonetheless, you can regenerate output using `make`. 20 | 21 | Make sure you review the diff to ensure that it only contains the desired 22 | changes! 23 | 24 | If you didn't add a new marker and this output changes, make sure you have 25 | a good explanation for why generated output needs to change! 26 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/apis/kubebuilder/v1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +kubebuilder:object:generate=true 18 | // +groupName=kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 19 | 20 | // Package v1 is the v1 version of the API. It uses kubebuilder markers. 21 | package v1 22 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/apis/kubebuilder/v1/types_example.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | ) 22 | 23 | // +kubebuilder:object:root=true 24 | 25 | // Example is a kind with schema changes. 26 | type Example struct { 27 | metav1.TypeMeta `json:",inline"` 28 | metav1.ObjectMeta `json:"metadata,omitempty"` 29 | // +required 30 | Spec ExampleSpec `json:"spec"` 31 | } 32 | 33 | type ExampleSpec struct { 34 | // foo contains foo. 35 | Foo string `json:"foo"` 36 | // foo contains foo. 37 | Bar string `json:"bar"` 38 | } 39 | 40 | // +kubebuilder:object:root=true 41 | 42 | // ExampleList contains a list of Example. 43 | type ExampleList struct { 44 | metav1.TypeMeta `json:",inline"` 45 | metav1.ListMeta `json:"metadata"` 46 | Items []Example `json:"items"` 47 | } 48 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/apis/kubebuilder/v1/types_unchanged.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | ) 22 | 23 | // +kubebuilder:object:root=true 24 | 25 | // Unchanged is a kind without schema changes. 26 | type Unchanged struct { 27 | metav1.TypeMeta `json:",inline"` 28 | metav1.ObjectMeta `json:"metadata,omitempty"` 29 | // +required 30 | Spec UnchangedSpec `json:"spec"` 31 | } 32 | 33 | type UnchangedSpec struct { 34 | // foo contains foo. 35 | Foo string `json:"foo"` 36 | // foo contains foo. 37 | Bar string `json:"bar"` 38 | } 39 | 40 | // +kubebuilder:object:root=true 41 | 42 | // UnchangedList contains a list of Unchanged. 43 | type UnchangedList struct { 44 | metav1.TypeMeta `json:",inline"` 45 | metav1.ListMeta `json:"metadata"` 46 | Items []Example `json:"items"` 47 | } 48 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/apis/legacy/v1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package,register 18 | // +k8s:defaulter-gen=TypeMeta 19 | // +k8s:openapi-gen=true 20 | // +groupName=legacy.schemapatcher.controller-tools.sigs.k8s.io 21 | 22 | // Package v1 is the v1 version of the API. It uses legacy k8s.io/code-generator markers. 23 | package v1 24 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/apis/legacy/v1/types_example.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | ) 22 | 23 | // +genclient 24 | // +genclient:nonNamespaced 25 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 26 | 27 | // Example is a kind with schema changes. 28 | type Example struct { 29 | metav1.TypeMeta `json:",inline"` 30 | metav1.ObjectMeta `json:"metadata,omitempty"` 31 | // +required 32 | Spec ExampleSpec `json:"spec"` 33 | } 34 | 35 | type ExampleSpec struct { 36 | // foo contains foo. 37 | Foo string `json:"foo"` 38 | // foo contains foo. 39 | Bar string `json:"bar"` 40 | } 41 | 42 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 43 | 44 | // ExampleList contains a list of Example. 45 | type ExampleList struct { 46 | metav1.TypeMeta `json:",inline"` 47 | metav1.ListMeta `json:"metadata"` 48 | Items []Example `json:"items"` 49 | } 50 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/apis/legacy/v1/types_unchanged.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | ) 22 | 23 | // +genclient 24 | // +genclient:nonNamespaced 25 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 26 | 27 | // Unchanged is a kind without schema changes. 28 | type Unchanged struct { 29 | metav1.TypeMeta `json:",inline"` 30 | metav1.ObjectMeta `json:"metadata,omitempty"` 31 | // +required 32 | Spec UnchangedSpec `json:"spec"` 33 | } 34 | 35 | type UnchangedSpec struct { 36 | // foo contains foo. 37 | Foo string `json:"foo"` 38 | // foo contains foo. 39 | Bar string `json:"bar"` 40 | } 41 | 42 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 43 | 44 | // UnchangedList contains a list of Unchanged. 45 | type UnchangedList struct { 46 | metav1.TypeMeta `json:",inline"` 47 | metav1.ListMeta `json:"metadata"` 48 | Items []Example `json:"items"` 49 | } 50 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/expected/kubebuilder-example-crd.v1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apiextensions.k8s.io/v1 2 | kind: CustomResourceDefinition 3 | metadata: 4 | name: example.kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 5 | spec: 6 | group: kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 7 | scope: Cluster 8 | names: 9 | kind: Example 10 | singular: example 11 | plural: examples 12 | listKind: ExampleList 13 | versions: 14 | - name: v1 15 | schema: 16 | openAPIV3Schema: 17 | description: Example is a kind with schema changes. 18 | type: object 19 | required: 20 | - spec 21 | properties: 22 | apiVersion: 23 | description: |- 24 | APIVersion defines the versioned schema of this representation of an object. 25 | Servers should convert recognized schemas to the latest internal value, and 26 | may reject unrecognized values. 27 | More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources 28 | type: string 29 | kind: 30 | description: |- 31 | Kind is a string value representing the REST resource this object represents. 32 | Servers may infer this from the endpoint the client submits requests to. 33 | Cannot be updated. 34 | In CamelCase. 35 | More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 36 | type: string 37 | metadata: 38 | type: object 39 | spec: 40 | type: object 41 | required: 42 | - bar 43 | - foo 44 | properties: 45 | bar: 46 | description: foo contains foo. 47 | type: string 48 | foo: 49 | description: foo contains foo. 50 | type: string 51 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/expected/kubebuilder-unchanged-crd.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apiextensions.k8s.io/v1 2 | kind: CustomResourceDefinition 3 | metadata: 4 | name: unchanged.kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 5 | spec: 6 | group: kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 7 | scope: Cluster 8 | names: 9 | kind: Unchanged 10 | singular: unchanged 11 | plural: unchangeds 12 | listKind: UnchangedList 13 | versions: 14 | - name: v1 15 | schema: 16 | openAPIV3Schema: 17 | description: Unchanged is a kind without schema changes. 18 | type: object 19 | required: 20 | - spec 21 | properties: 22 | apiVersion: 23 | description: |- 24 | APIVersion defines the versioned schema of this representation of an object. 25 | Servers should convert recognized schemas to the latest internal value, and 26 | may reject unrecognized values. 27 | More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources 28 | type: string 29 | kind: 30 | description: |- 31 | Kind is a string value representing the REST resource this object represents. 32 | Servers may infer this from the endpoint the client submits requests to. 33 | Cannot be updated. 34 | In CamelCase. 35 | More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 36 | type: string 37 | metadata: 38 | type: object 39 | spec: 40 | type: object 41 | required: 42 | - bar 43 | - foo 44 | properties: 45 | bar: 46 | description: foo contains foo. 47 | type: string 48 | foo: 49 | description: foo contains foo. 50 | type: string 51 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/go.mod: -------------------------------------------------------------------------------- 1 | module testdata.kubebuilder.io/inplaceschema 2 | 3 | go 1.15 4 | 5 | require k8s.io/apimachinery v0.19.2 6 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/invalid/kubebuilder-example-crd.v1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apiextensions.k8s.io/v1 2 | kind: CustomResourceDefinition 3 | metadata: 4 | name: example.kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 5 | spec: 6 | group: kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 7 | scope: Cluster 8 | names: 9 | kind: Example 10 | singular: example 11 | plural: examples 12 | listKind: ExampleList 13 | versions: 14 | - name: v1 15 | schema: 16 | openAPIV3Schema: 17 | description: Example is a kind with schema changes. 18 | type: object 19 | required: 20 | - spec 21 | properties: 22 | apiVersion: 23 | description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' 24 | type: string 25 | kind: 26 | description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' 27 | type: string 28 | metadata: 29 | type: object 30 | spec: 31 | type: object 32 | required: 33 | - bar 34 | properties: 35 | bar: 36 | description: foo contains foo. 37 | type: string 38 | foo: 39 | description: foo contains foo. 40 | type: string 41 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/invalid/kubebuilder-example-crd.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apiextensions.k8s.io/v1beta1 2 | kind: CustomResourceDefinition 3 | metadata: 4 | name: example.kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 5 | spec: 6 | group: kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 7 | scope: Cluster 8 | names: 9 | kind: Example 10 | singular: example 11 | plural: examples 12 | listKind: ExampleList 13 | version: v1 14 | validation: 15 | openAPIV3Schema: 16 | description: Example is a kind with schema changes. 17 | type: object 18 | required: 19 | - spec 20 | properties: 21 | apiVersion: 22 | description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' 23 | type: string 24 | kind: 25 | description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' 26 | type: string 27 | metadata: 28 | type: object 29 | spec: 30 | type: object 31 | required: 32 | - bar 33 | properties: 34 | bar: 35 | description: foo contains foo. 36 | type: string 37 | foo: 38 | description: foo contains foo. 39 | type: string 40 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/valid/example.cr.yaml: -------------------------------------------------------------------------------- 1 | # This is an example of the resource defined in this package. 2 | apiVersion: kubebuilder.schemapatcher.controller-tools.sigs.k8s.io/v1 3 | kind: Example 4 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/valid/kubebuilder-example-crd.v1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apiextensions.k8s.io/v1 2 | kind: CustomResourceDefinition 3 | metadata: 4 | name: example.kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 5 | spec: 6 | group: kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 7 | scope: Cluster 8 | names: 9 | kind: Example 10 | singular: example 11 | plural: examples 12 | listKind: ExampleList 13 | versions: 14 | - name: v1 15 | schema: 16 | openAPIV3Schema: 17 | description: Example is a kind with schema changes. 18 | type: object 19 | required: 20 | - spec 21 | properties: 22 | apiVersion: 23 | description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' 24 | type: string 25 | kind: 26 | description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' 27 | type: string 28 | metadata: 29 | type: object 30 | spec: 31 | type: object 32 | required: 33 | - bar 34 | properties: 35 | bar: 36 | description: foo contains foo. 37 | type: string 38 | foo: 39 | description: foo contains foo. 40 | type: string 41 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/valid/kubebuilder-unchanged-crd.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apiextensions.k8s.io/v1 2 | kind: CustomResourceDefinition 3 | metadata: 4 | name: unchanged.kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 5 | spec: 6 | group: kubebuilder.schemapatcher.controller-tools.sigs.k8s.io 7 | scope: Cluster 8 | names: 9 | kind: Unchanged 10 | singular: unchanged 11 | plural: unchangeds 12 | listKind: UnchangedList 13 | versions: 14 | - name: v1 15 | schema: 16 | openAPIV3Schema: 17 | description: Unchanged is a kind without schema changes. 18 | type: object 19 | required: 20 | - spec 21 | properties: 22 | apiVersion: 23 | description: 'APIVersion defines the versioned schema of this representation 24 | of an object. Servers should convert recognized schemas to the latest 25 | internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources' 26 | type: string 27 | kind: 28 | description: 'Kind is a string value representing the REST resource this 29 | object represents. Servers may infer this from the endpoint the client 30 | submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds' 31 | type: string 32 | metadata: 33 | type: object 34 | spec: 35 | type: object 36 | required: 37 | - bar 38 | - foo 39 | properties: 40 | bar: 41 | description: foo contains foo. 42 | type: string 43 | foo: 44 | description: foo contains foo. 45 | type: string 46 | -------------------------------------------------------------------------------- /pkg/schemapatcher/testdata/valid/random.yaml: -------------------------------------------------------------------------------- 1 | name: This is a random YAML file to ensure the generator doesn't error with non-kube YAML files. 2 | -------------------------------------------------------------------------------- /pkg/schemapatcher/zz_generated.markerhelp.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | 3 | /* 4 | Copyright2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Code generated by helpgen. DO NOT EDIT. 20 | 21 | package schemapatcher 22 | 23 | import ( 24 | "sigs.k8s.io/controller-tools/pkg/markers" 25 | ) 26 | 27 | func (Generator) Help() *markers.DefinitionHelp { 28 | return &markers.DefinitionHelp{ 29 | Category: "", 30 | DetailedHelp: markers.DetailedHelp{ 31 | Summary: "patches existing CRDs with new schemata.", 32 | Details: "It will generate output for each \"CRD Version\" (API version of the CRD type\nitself) , e.g. apiextensions/v1) available.", 33 | }, 34 | FieldHelp: map[string]markers.DetailedHelp{ 35 | "ManifestsPath": { 36 | Summary: "contains the CustomResourceDefinition YAML files.", 37 | Details: "", 38 | }, 39 | "MaxDescLen": { 40 | Summary: "specifies the maximum description length for fields in CRD's OpenAPI schema.", 41 | Details: "0 indicates drop the description for all fields completely.\nn indicates limit the description to at most n characters and truncate the description to\nclosest sentence boundary if it exceeds n characters.", 42 | }, 43 | "GenerateEmbeddedObjectMeta": { 44 | Summary: "specifies if any embedded ObjectMeta in the CRD should be generated", 45 | Details: "", 46 | }, 47 | }, 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /pkg/typescaffold/resource.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package typescaffold 18 | 19 | import ( 20 | "fmt" 21 | "strings" 22 | 23 | "github.com/gobuffalo/flect" 24 | ) 25 | 26 | // Resource contains the information required to scaffold files for a resource. 27 | type Resource struct { 28 | // Namespaced is true if the resource is namespaced 29 | Namespaced bool 30 | 31 | // Kind is the API Kind. 32 | Kind string 33 | 34 | // Resource is the API Resource. 35 | Resource string 36 | } 37 | 38 | // Validate checks the Resource values to make sure they are valid. 39 | func (r *Resource) Validate() error { 40 | if len(r.Kind) == 0 { 41 | return fmt.Errorf("kind cannot be empty") 42 | } 43 | 44 | if len(r.Resource) == 0 { 45 | r.Resource = flect.Pluralize(strings.ToLower(r.Kind)) 46 | } 47 | 48 | if r.Kind != flect.Pascalize(r.Kind) { 49 | return fmt.Errorf("kind must be CamelCase (expected %s was %s)", flect.Pascalize(r.Kind), r.Kind) 50 | } 51 | 52 | return nil 53 | } 54 | -------------------------------------------------------------------------------- /pkg/version/version.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package version provides the version of the main module. 18 | package version 19 | 20 | import ( 21 | "fmt" 22 | "runtime/debug" 23 | ) 24 | 25 | // version to be set using ldflags: 26 | // -ldflags "-X sigs.k8s.io/controller-tools/pkg/version.version=v1.0.0" 27 | // falls back to module information is unset 28 | var version = "" 29 | 30 | // Version returns the version of the main module 31 | func Version() string { 32 | if version != "" { 33 | return version 34 | } 35 | info, ok := debug.ReadBuildInfo() 36 | if !ok || info == nil || info.Main.Version == "" { 37 | // binary has not been built with module support or doesn't contain a version. 38 | return "(unknown)" 39 | } 40 | return info.Main.Version 41 | } 42 | 43 | // Print prints the main module version on stdout. 44 | // 45 | // Print will display either: 46 | // 47 | // - "Version: v0.2.1" when the program has been compiled with: 48 | // 49 | // $ go get github.com/controller-tools/cmd/controller-gen@v0.2.1 50 | // 51 | // Note: go modules requires the usage of semver compatible tags starting with 52 | // 'v' to have nice human-readable versions. 53 | // 54 | // - "Version: (devel)" when the program is compiled from a local git checkout. 55 | // 56 | // - "Version: (unknown)" when not using go modules. 57 | func Print() { 58 | fmt.Printf("Version: %s\n", Version()) 59 | } 60 | -------------------------------------------------------------------------------- /pkg/version/version_suite_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package version 18 | 19 | import ( 20 | "testing" 21 | 22 | . "github.com/onsi/ginkgo" 23 | . "github.com/onsi/gomega" 24 | ) 25 | 26 | func TestVersioning(t *testing.T) { 27 | RegisterFailHandler(Fail) 28 | RunSpecs(t, "Test Version Suite") 29 | } 30 | -------------------------------------------------------------------------------- /pkg/version/version_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package version 18 | 19 | import ( 20 | . "github.com/onsi/ginkgo" 21 | . "github.com/onsi/gomega" 22 | ) 23 | 24 | var _ = Describe("TestVersion", func() { 25 | tests := []struct { 26 | name string 27 | version string 28 | expected string 29 | }{ 30 | { 31 | name: "empty returns unknown", 32 | version: "", 33 | expected: "(devel)", 34 | }, 35 | { 36 | name: "set to a value returns it", 37 | version: "1.2.3", 38 | expected: "1.2.3", 39 | }, 40 | } 41 | for _, tc := range tests { 42 | It("Version set to "+tc.name, func() { 43 | versionBackup := version 44 | defer func() { 45 | version = versionBackup 46 | }() 47 | version = tc.version 48 | result := Version() 49 | Expect(result).To(Equal(tc.expected)) 50 | }) 51 | } 52 | }) 53 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/README.md: -------------------------------------------------------------------------------- 1 | # Webhook Integration Test testdata 2 | 3 | This contains a tiny module used for testdata for the webhook integration 4 | test. The directory should always be called testdata, so Go treats it 5 | specially. 6 | 7 | The `cronjob_types.go` file contains the input types, and is loosely based 8 | on the CronJob tutorial from the [KubeBuilder 9 | Book](https://book.kubebuilder.io/cronjob-tutorial/cronjob-tutorial.html), but with added 10 | methods to test webhook generation behavior. 11 | 12 | If you add a new marker, re-generate the golden output file, 13 | `manifests.yaml`, with 14 | 15 | ```bash 16 | go generate 17 | ``` 18 | 19 | Make sure you review the diff to ensure that it only contains the desired 20 | changes! 21 | 22 | If you didn't add a new marker and this output changes, make sure you have 23 | a good explanation for why generated output needs to change! 24 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/cronjob_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | //go:generate ../../../.run-controller-gen.sh webhook paths=. output:dir=. 17 | 18 | // +groupName=testdata.kubebuilder.io 19 | // +versionName=v1 20 | package cronjob 21 | 22 | import ( 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | ) 25 | 26 | // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! 27 | // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. 28 | 29 | // CronJobSpec defines the desired state of CronJob 30 | type CronJobSpec struct { 31 | // The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. 32 | Schedule string `json:"schedule"` 33 | } 34 | 35 | // CronJobStatus defines the observed state of CronJob 36 | type CronJobStatus struct { 37 | // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster 38 | // Important: Run "make" to regenerate code after modifying this file 39 | 40 | // Information when was the last time the job was successfully scheduled. 41 | // +optional 42 | LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"` 43 | } 44 | 45 | // +kubebuilder:object:root=true 46 | // +kubebuilder:subresource:status 47 | // +kubebuilder:resource:singular=mycronjob 48 | 49 | // CronJob is the Schema for the cronjobs API 50 | type CronJob struct { 51 | /* 52 | */ 53 | metav1.TypeMeta `json:",inline"` 54 | metav1.ObjectMeta `json:"metadata,omitempty"` 55 | 56 | Spec CronJobSpec `json:"spec,omitempty"` 57 | Status CronJobStatus `json:"status,omitempty"` 58 | } 59 | 60 | // +kubebuilder:object:root=true 61 | 62 | // CronJobList contains a list of CronJob 63 | type CronJobList struct { 64 | metav1.TypeMeta `json:",inline"` 65 | metav1.ListMeta `json:"metadata,omitempty"` 66 | Items []CronJob `json:"items"` 67 | } 68 | 69 | func init() { 70 | SchemeBuilder.Register(&CronJob{}, &CronJobList{}) 71 | } 72 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/go.mod: -------------------------------------------------------------------------------- 1 | module testdata.kubebuilder.io/cronjob 2 | 3 | go 1.15 4 | 5 | require ( 6 | k8s.io/api v0.19.2 7 | k8s.io/apimachinery v0.19.2 8 | sigs.k8s.io/controller-runtime v0.7.0 9 | ) 10 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/invalid-admissionReviewVersionsRequired/manifests.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: admissionregistration.k8s.io/v1 3 | kind: MutatingWebhookConfiguration 4 | metadata: 5 | name: mutating-webhook-configuration 6 | webhooks: 7 | - admissionReviewVersions: 8 | - v1 9 | - v1beta1 10 | clientConfig: 11 | service: 12 | name: webhook-service 13 | namespace: system 14 | path: /mutate-testdata-kubebuilder-io-v1-cronjob 15 | failurePolicy: Fail 16 | matchPolicy: Equivalent 17 | name: default.cronjob.testdata.kubebuilder.io 18 | rules: 19 | - apiGroups: 20 | - testdata.kubebuilder.io 21 | apiVersions: 22 | - v1 23 | operations: 24 | - CREATE 25 | - UPDATE 26 | resources: 27 | - cronjobs 28 | sideEffects: None 29 | timeoutSeconds: 10 30 | --- 31 | apiVersion: admissionregistration.k8s.io/v1 32 | kind: ValidatingWebhookConfiguration 33 | metadata: 34 | name: validating-webhook-configuration 35 | webhooks: 36 | - admissionReviewVersions: 37 | - v1 38 | - v1beta1 39 | clientConfig: 40 | service: 41 | name: webhook-service 42 | namespace: system 43 | path: /validate-testdata-kubebuilder-io-v1-cronjob 44 | failurePolicy: Fail 45 | matchPolicy: Equivalent 46 | name: validation.cronjob.testdata.kubebuilder.io 47 | rules: 48 | - apiGroups: 49 | - testdata.kubebuilder.io 50 | apiVersions: 51 | - v1 52 | operations: 53 | - CREATE 54 | - UPDATE 55 | resources: 56 | - cronjobs 57 | sideEffects: None 58 | timeoutSeconds: 10 59 | - admissionReviewVersions: 60 | - v1 61 | - v1beta1 62 | clientConfig: 63 | service: 64 | name: webhook-service 65 | namespace: system 66 | path: /validate-testdata-kubebuilder-io-v1-cronjob 67 | failurePolicy: Fail 68 | matchPolicy: Equivalent 69 | name: validation.cronjob.testdata.kubebuilder.io 70 | rules: 71 | - apiGroups: 72 | - testdata.kubebuilder.io 73 | apiVersions: 74 | - v1 75 | operations: 76 | - CREATE 77 | - UPDATE 78 | resources: 79 | - cronjobs 80 | sideEffects: NoneOnDryRun 81 | timeoutSeconds: 10 82 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/invalid-admissionReviewVersionsRequired/webhook.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package cronjob 17 | 18 | import ( 19 | "k8s.io/apimachinery/pkg/runtime" 20 | ctrl "sigs.k8s.io/controller-runtime" 21 | "sigs.k8s.io/controller-runtime/pkg/webhook" 22 | ) 23 | 24 | func (c *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error { 25 | return ctrl.NewWebhookManagedBy(mgr). 26 | For(c). 27 | Complete() 28 | } 29 | 30 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10 31 | // +kubebuilder:webhook:verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=NoneOnDryRun,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 32 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/mutate-testdata-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=default.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 33 | 34 | var _ webhook.Defaulter = &CronJob{} 35 | var _ webhook.Validator = &CronJob{} 36 | 37 | func (c *CronJob) Default() { 38 | } 39 | 40 | func (c *CronJob) ValidateCreate() error { 41 | return nil 42 | } 43 | 44 | func (c *CronJob) ValidateUpdate(_ runtime.Object) error { 45 | return nil 46 | } 47 | 48 | func (c *CronJob) ValidateDelete() error { 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/invalid-path-and-url/webhook.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package cronjob 17 | 18 | import ( 19 | "k8s.io/apimachinery/pkg/runtime" 20 | ctrl "sigs.k8s.io/controller-runtime" 21 | "sigs.k8s.io/controller-runtime/pkg/webhook" 22 | ) 23 | 24 | func (c *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error { 25 | return ctrl.NewWebhookManagedBy(mgr). 26 | For(c). 27 | Complete() 28 | } 29 | 30 | // +kubebuilder:webhook:url="https://anothersomewebhook:9443/validate-testdata-kubebuilder-io-v1-cronjob",path="/somepath",verbs=create;update,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=NoneOnDryRun,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 31 | 32 | var _ webhook.Defaulter = &CronJob{} 33 | var _ webhook.Validator = &CronJob{} 34 | 35 | func (c *CronJob) Default() { 36 | } 37 | 38 | func (c *CronJob) ValidateCreate() error { 39 | return nil 40 | } 41 | 42 | func (c *CronJob) ValidateUpdate(_ runtime.Object) error { 43 | return nil 44 | } 45 | 46 | func (c *CronJob) ValidateDelete() error { 47 | return nil 48 | } 49 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/invalid-sideEffects/manifests.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: admissionregistration.k8s.io/v1 3 | kind: MutatingWebhookConfiguration 4 | metadata: 5 | name: mutating-webhook-configuration 6 | webhooks: 7 | - admissionReviewVersions: 8 | - v1 9 | - v1beta1 10 | clientConfig: 11 | service: 12 | name: webhook-service 13 | namespace: system 14 | path: /mutate-testdata-kubebuilder-io-v1-cronjob 15 | failurePolicy: Fail 16 | matchPolicy: Equivalent 17 | name: default.cronjob.testdata.kubebuilder.io 18 | rules: 19 | - apiGroups: 20 | - testdata.kubebuilder.io 21 | apiVersions: 22 | - v1 23 | operations: 24 | - CREATE 25 | - UPDATE 26 | resources: 27 | - cronjobs 28 | sideEffects: None 29 | timeoutSeconds: 10 30 | --- 31 | apiVersion: admissionregistration.k8s.io/v1 32 | kind: ValidatingWebhookConfiguration 33 | metadata: 34 | name: validating-webhook-configuration 35 | webhooks: 36 | - admissionReviewVersions: 37 | - v1 38 | - v1beta1 39 | clientConfig: 40 | service: 41 | name: webhook-service 42 | namespace: system 43 | path: /validate-testdata-kubebuilder-io-v1-cronjob 44 | failurePolicy: Fail 45 | matchPolicy: Equivalent 46 | name: validation.cronjob.testdata.kubebuilder.io 47 | rules: 48 | - apiGroups: 49 | - testdata.kubebuilder.io 50 | apiVersions: 51 | - v1 52 | operations: 53 | - CREATE 54 | - UPDATE 55 | resources: 56 | - cronjobs 57 | sideEffects: None 58 | timeoutSeconds: 10 59 | - admissionReviewVersions: 60 | - v1 61 | - v1beta1 62 | clientConfig: 63 | service: 64 | name: webhook-service 65 | namespace: system 66 | path: /validate-testdata-kubebuilder-io-v1-cronjob 67 | failurePolicy: Fail 68 | matchPolicy: Equivalent 69 | name: validation.cronjob.testdata.kubebuilder.io 70 | rules: 71 | - apiGroups: 72 | - testdata.kubebuilder.io 73 | apiVersions: 74 | - v1 75 | operations: 76 | - CREATE 77 | - UPDATE 78 | resources: 79 | - cronjobs 80 | sideEffects: NoneOnDryRun 81 | timeoutSeconds: 10 82 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/invalid-sideEffects/webhook.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package cronjob 17 | 18 | import ( 19 | "k8s.io/apimachinery/pkg/runtime" 20 | ctrl "sigs.k8s.io/controller-runtime" 21 | "sigs.k8s.io/controller-runtime/pkg/webhook" 22 | ) 23 | 24 | func (c *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error { 25 | return ctrl.NewWebhookManagedBy(mgr). 26 | For(c). 27 | Complete() 28 | } 29 | 30 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=Some,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 31 | // +kubebuilder:webhook:verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=NoneOnDryRun,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 32 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/mutate-testdata-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=default.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 33 | 34 | var _ webhook.Defaulter = &CronJob{} 35 | var _ webhook.Validator = &CronJob{} 36 | 37 | func (c *CronJob) Default() { 38 | } 39 | 40 | func (c *CronJob) ValidateCreate() error { 41 | return nil 42 | } 43 | 44 | func (c *CronJob) ValidateUpdate(_ runtime.Object) error { 45 | return nil 46 | } 47 | 48 | func (c *CronJob) ValidateDelete() error { 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/invalid-timeoutSeconds/manifests.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: admissionregistration.k8s.io/v1 3 | kind: MutatingWebhookConfiguration 4 | metadata: 5 | creationTimestamp: null 6 | name: mutating-webhook-configuration 7 | webhooks: 8 | - admissionReviewVersions: 9 | - v1 10 | - v1beta1 11 | clientConfig: 12 | service: 13 | name: webhook-service 14 | namespace: system 15 | path: /mutate-testdata-kubebuilder-io-v1-cronjob 16 | failurePolicy: Fail 17 | matchPolicy: Equivalent 18 | name: default.cronjob.testdata.kubebuilder.io 19 | rules: 20 | - apiGroups: 21 | - testdata.kubebuilder.io 22 | apiVersions: 23 | - v1 24 | operations: 25 | - CREATE 26 | - UPDATE 27 | resources: 28 | - cronjobs 29 | sideEffects: None 30 | timeoutSeconds: 40 31 | --- 32 | apiVersion: admissionregistration.k8s.io/v1 33 | kind: ValidatingWebhookConfiguration 34 | metadata: 35 | creationTimestamp: null 36 | name: validating-webhook-configuration 37 | webhooks: 38 | - admissionReviewVersions: 39 | - v1 40 | - v1beta1 41 | clientConfig: 42 | service: 43 | name: webhook-service 44 | namespace: system 45 | path: /validate-testdata-kubebuilder-io-v1-cronjob 46 | failurePolicy: Fail 47 | matchPolicy: Equivalent 48 | name: validation.cronjob.testdata.kubebuilder.io 49 | rules: 50 | - apiGroups: 51 | - testdata.kubebuilder.io 52 | apiVersions: 53 | - v1 54 | operations: 55 | - CREATE 56 | - UPDATE 57 | resources: 58 | - cronjobs 59 | sideEffects: None 60 | timeoutSeconds: 10 61 | - admissionReviewVersions: 62 | - v1 63 | - v1beta1 64 | clientConfig: 65 | service: 66 | name: webhook-service 67 | namespace: system 68 | path: /validate-testdata-kubebuilder-io-v1-cronjob 69 | failurePolicy: Fail 70 | matchPolicy: Equivalent 71 | name: validation.cronjob.testdata.kubebuilder.io 72 | rules: 73 | - apiGroups: 74 | - testdata.kubebuilder.io 75 | apiVersions: 76 | - v1 77 | operations: 78 | - CREATE 79 | - UPDATE 80 | resources: 81 | - cronjobs 82 | sideEffects: None 83 | timeoutSeconds: -1 84 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/invalid-timeoutSeconds/webhook.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package cronjob 17 | 18 | import ( 19 | "k8s.io/apimachinery/pkg/runtime" 20 | ctrl "sigs.k8s.io/controller-runtime" 21 | "sigs.k8s.io/controller-runtime/pkg/webhook" 22 | ) 23 | 24 | func (c *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error { 25 | return ctrl.NewWebhookManagedBy(mgr). 26 | For(c). 27 | Complete() 28 | } 29 | 30 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=40,admissionReviewVersions=v1;v1beta1 31 | // +kubebuilder:webhook:verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 32 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/mutate-testdata-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=default.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=-1,admissionReviewVersions=v1;v1beta1 33 | 34 | var _ webhook.Defaulter = &CronJob{} 35 | var _ webhook.Validator = &CronJob{} 36 | 37 | func (c *CronJob) Default() { 38 | } 39 | 40 | func (c *CronJob) ValidateCreate() error { 41 | return nil 42 | } 43 | 44 | func (c *CronJob) ValidateUpdate(_ runtime.Object) error { 45 | return nil 46 | } 47 | 48 | func (c *CronJob) ValidateDelete() error { 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/invalid-v1beta1NotSupported/manifests.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: admissionregistration.k8s.io/v1 3 | kind: MutatingWebhookConfiguration 4 | metadata: 5 | name: mutating-webhook-configuration 6 | webhooks: 7 | - admissionReviewVersions: 8 | - v1 9 | - v1beta1 10 | clientConfig: 11 | service: 12 | name: webhook-service 13 | namespace: system 14 | path: /mutate-testdata-kubebuilder-io-v1-cronjob 15 | failurePolicy: Fail 16 | matchPolicy: Equivalent 17 | name: default.cronjob.testdata.kubebuilder.io 18 | rules: 19 | - apiGroups: 20 | - testdata.kubebuilder.io 21 | apiVersions: 22 | - v1 23 | operations: 24 | - CREATE 25 | - UPDATE 26 | resources: 27 | - cronjobs 28 | sideEffects: None 29 | timeoutSeconds: 10 30 | --- 31 | apiVersion: admissionregistration.k8s.io/v1 32 | kind: ValidatingWebhookConfiguration 33 | metadata: 34 | name: validating-webhook-configuration 35 | webhooks: 36 | - admissionReviewVersions: 37 | - v1 38 | - v1beta1 39 | clientConfig: 40 | service: 41 | name: webhook-service 42 | namespace: system 43 | path: /validate-testdata-kubebuilder-io-v1-cronjob 44 | failurePolicy: Fail 45 | matchPolicy: Equivalent 46 | name: validation.cronjob.testdata.kubebuilder.io 47 | rules: 48 | - apiGroups: 49 | - testdata.kubebuilder.io 50 | apiVersions: 51 | - v1 52 | operations: 53 | - CREATE 54 | - UPDATE 55 | resources: 56 | - cronjobs 57 | sideEffects: None 58 | timeoutSeconds: 10 59 | - admissionReviewVersions: 60 | - v1 61 | - v1beta1 62 | clientConfig: 63 | service: 64 | name: webhook-service 65 | namespace: system 66 | path: /validate-testdata-kubebuilder-io-v1-cronjob 67 | failurePolicy: Fail 68 | matchPolicy: Equivalent 69 | name: validation.cronjob.testdata.kubebuilder.io 70 | rules: 71 | - apiGroups: 72 | - testdata.kubebuilder.io 73 | apiVersions: 74 | - v1 75 | operations: 76 | - CREATE 77 | - UPDATE 78 | resources: 79 | - cronjobs 80 | sideEffects: NoneOnDryRun 81 | timeoutSeconds: 10 82 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/invalid-v1beta1NotSupported/webhook.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package cronjob 17 | 18 | import ( 19 | "k8s.io/apimachinery/pkg/runtime" 20 | ctrl "sigs.k8s.io/controller-runtime" 21 | "sigs.k8s.io/controller-runtime/pkg/webhook" 22 | ) 23 | 24 | func (c *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error { 25 | return ctrl.NewWebhookManagedBy(mgr). 26 | For(c). 27 | Complete() 28 | } 29 | 30 | // +kubebuilder:webhook:webhookVersions=v1beta1,verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 31 | // +kubebuilder:webhook:verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=NoneOnDryRun,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 32 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/mutate-testdata-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=default.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 33 | 34 | var _ webhook.Defaulter = &CronJob{} 35 | var _ webhook.Validator = &CronJob{} 36 | 37 | func (c *CronJob) Default() { 38 | } 39 | 40 | func (c *CronJob) ValidateCreate() error { 41 | return nil 42 | } 43 | 44 | func (c *CronJob) ValidateUpdate(_ runtime.Object) error { 45 | return nil 46 | } 47 | 48 | func (c *CronJob) ValidateDelete() error { 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/manifests.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: admissionregistration.k8s.io/v1 3 | kind: MutatingWebhookConfiguration 4 | metadata: 5 | name: mutating-webhook-configuration 6 | webhooks: 7 | - admissionReviewVersions: 8 | - v1 9 | - v1beta1 10 | clientConfig: 11 | service: 12 | name: webhook-service 13 | namespace: system 14 | path: /mutate-testdata-kubebuilder-io-v1-cronjob 15 | failurePolicy: Fail 16 | matchPolicy: Equivalent 17 | name: default.cronjob.testdata.kubebuilder.io 18 | reinvocationPolicy: Never 19 | rules: 20 | - apiGroups: 21 | - testdata.kubebuilder.io 22 | apiVersions: 23 | - v1 24 | operations: 25 | - CREATE 26 | - UPDATE 27 | resources: 28 | - cronjobs 29 | sideEffects: None 30 | timeoutSeconds: 10 31 | --- 32 | apiVersion: admissionregistration.k8s.io/v1 33 | kind: ValidatingWebhookConfiguration 34 | metadata: 35 | name: validating-webhook-configuration 36 | webhooks: 37 | - admissionReviewVersions: 38 | - v1 39 | - v1beta1 40 | clientConfig: 41 | service: 42 | name: webhook-service 43 | namespace: system 44 | path: /validate-testdata-kubebuilder-io-v1-cronjob 45 | failurePolicy: Fail 46 | matchPolicy: Equivalent 47 | name: validation.cronjob.testdata.kubebuilder.io 48 | rules: 49 | - apiGroups: 50 | - testdata.kubebuilder.io 51 | apiVersions: 52 | - v1 53 | operations: 54 | - CREATE 55 | - UPDATE 56 | resources: 57 | - cronjobs 58 | sideEffects: None 59 | timeoutSeconds: 10 60 | - admissionReviewVersions: 61 | - v1 62 | - v1beta1 63 | clientConfig: 64 | service: 65 | name: webhook-service 66 | namespace: system 67 | path: /validate-testdata-kubebuilder-io-v1-cronjob 68 | failurePolicy: Fail 69 | matchPolicy: Equivalent 70 | name: validation.cronjob.testdata.kubebuilder.io 71 | rules: 72 | - apiGroups: 73 | - testdata.kubebuilder.io 74 | apiVersions: 75 | - v1 76 | operations: 77 | - CREATE 78 | - UPDATE 79 | resources: 80 | - cronjobs 81 | sideEffects: NoneOnDryRun 82 | timeoutSeconds: 10 83 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/valid-custom-name/manifests.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: admissionregistration.k8s.io/v1 3 | kind: MutatingWebhookConfiguration 4 | metadata: 5 | name: foo 6 | webhooks: 7 | - admissionReviewVersions: 8 | - v1 9 | - v1beta1 10 | clientConfig: 11 | service: 12 | name: webhook-service 13 | namespace: system 14 | path: /mutate-testdata-kubebuilder-io-v1-cronjob 15 | failurePolicy: Fail 16 | matchPolicy: Equivalent 17 | name: default.cronjob.testdata.kubebuilder.io 18 | rules: 19 | - apiGroups: 20 | - testdata.kubebuilder.io 21 | apiVersions: 22 | - v1 23 | operations: 24 | - CREATE 25 | - UPDATE 26 | resources: 27 | - cronjobs 28 | sideEffects: None 29 | timeoutSeconds: 10 30 | reinvocationPolicy: IfNeeded 31 | --- 32 | apiVersion: admissionregistration.k8s.io/v1 33 | kind: ValidatingWebhookConfiguration 34 | metadata: 35 | name: bar 36 | webhooks: 37 | - admissionReviewVersions: 38 | - v1 39 | - v1beta1 40 | clientConfig: 41 | service: 42 | name: webhook-service 43 | namespace: system 44 | path: /validate-testdata-kubebuilder-io-v1-cronjob 45 | failurePolicy: Fail 46 | matchPolicy: Equivalent 47 | name: validation.cronjob.testdata.kubebuilder.io 48 | rules: 49 | - apiGroups: 50 | - testdata.kubebuilder.io 51 | apiVersions: 52 | - v1 53 | operations: 54 | - CREATE 55 | - UPDATE 56 | resources: 57 | - cronjobs 58 | sideEffects: None 59 | timeoutSeconds: 10 60 | - admissionReviewVersions: 61 | - v1 62 | - v1beta1 63 | clientConfig: 64 | service: 65 | name: webhook-service 66 | namespace: system 67 | path: /validate-testdata-kubebuilder-io-v1-cronjob 68 | failurePolicy: Fail 69 | matchPolicy: Equivalent 70 | name: validation.cronjob.testdata.kubebuilder.io 71 | rules: 72 | - apiGroups: 73 | - testdata.kubebuilder.io 74 | apiVersions: 75 | - v1 76 | operations: 77 | - CREATE 78 | - UPDATE 79 | resources: 80 | - cronjobs 81 | sideEffects: NoneOnDryRun 82 | timeoutSeconds: 10 83 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/valid-custom-service/manifests.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: admissionregistration.k8s.io/v1 3 | kind: MutatingWebhookConfiguration 4 | metadata: 5 | name: mutating-webhook-configuration 6 | webhooks: 7 | - admissionReviewVersions: 8 | - v1 9 | - v1beta1 10 | clientConfig: 11 | service: 12 | name: FOO 13 | namespace: system 14 | path: /mutate-testdata-kubebuilder-io-v1-cronjob 15 | failurePolicy: Fail 16 | matchPolicy: Equivalent 17 | name: default.cronjob.testdata.kubebuilder.io 18 | rules: 19 | - apiGroups: 20 | - testdata.kubebuiler.io 21 | apiVersions: 22 | - v1 23 | operations: 24 | - CREATE 25 | - UPDATE 26 | resources: 27 | - cronjobs 28 | sideEffects: None 29 | timeoutSeconds: 10 30 | reinvocationPolicy: IfNeeded 31 | --- 32 | apiVersion: admissionregistration.k8s.io/v1 33 | kind: ValidatingWebhookConfiguration 34 | metadata: 35 | name: validating-webhook-configuration 36 | webhooks: 37 | - admissionReviewVersions: 38 | - v1 39 | - v1beta1 40 | clientConfig: 41 | service: 42 | name: DEAD 43 | namespace: BEEF 44 | path: /validate-testdata-kubebuilder-io-v1-cronjob 45 | port: 1234 46 | failurePolicy: Fail 47 | matchPolicy: Equivalent 48 | name: validation.cronjob.testdata.kubebuilder.io 49 | rules: 50 | - apiGroups: 51 | - testdata.kubebuiler.io 52 | apiVersions: 53 | - v1 54 | operations: 55 | - CREATE 56 | - UPDATE 57 | resources: 58 | - cronjobs 59 | sideEffects: None 60 | timeoutSeconds: 10 61 | - admissionReviewVersions: 62 | - v1 63 | - v1beta1 64 | clientConfig: 65 | service: 66 | name: webhook-service 67 | namespace: system 68 | path: /validate-testdata-kubebuilder-io-v1-cronjob 69 | failurePolicy: Fail 70 | matchPolicy: Equivalent 71 | name: validation.cronjob.testdata.kubebuilder.io 72 | rules: 73 | - apiGroups: 74 | - testdata.kubebuiler.io 75 | apiVersions: 76 | - v1 77 | operations: 78 | - CREATE 79 | - UPDATE 80 | resources: 81 | - cronjobs 82 | sideEffects: NoneOnDryRun 83 | timeoutSeconds: 10 84 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/valid-custom-service/webhook.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package cronjob 17 | 18 | import ( 19 | "k8s.io/apimachinery/pkg/runtime" 20 | ctrl "sigs.k8s.io/controller-runtime" 21 | "sigs.k8s.io/controller-runtime/pkg/webhook" 22 | ) 23 | 24 | func (c *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error { 25 | return ctrl.NewWebhookManagedBy(mgr). 26 | For(c). 27 | Complete() 28 | } 29 | 30 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuiler.io,resources=cronjobs,serviceName=DEAD,serviceNamespace=BEEF,servicePort=1234,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 31 | // +kubebuilder:webhook:verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuiler.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=NoneOnDryRun,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 32 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/mutate-testdata-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuiler.io,resources=cronjobs,serviceName=FOO,versions=v1,name=default.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1,reinvocationPolicy=IfNeeded 33 | 34 | var _ webhook.Defaulter = &CronJob{} 35 | var _ webhook.Validator = &CronJob{} 36 | 37 | func (c *CronJob) Default() { 38 | } 39 | 40 | func (c *CronJob) ValidateCreate() error { 41 | return nil 42 | } 43 | 44 | func (c *CronJob) ValidateUpdate(_ runtime.Object) error { 45 | return nil 46 | } 47 | 48 | func (c *CronJob) ValidateDelete() error { 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/valid-ordered/cronjob_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | //go:generate ../../../.run-controller-gen.sh webhook paths=. output:dir=. 17 | 18 | // +groupName=testdata.kubebuilder.io 19 | // +versionName=v1 20 | package cronjob 21 | 22 | import ( 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | ) 25 | 26 | // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! 27 | // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. 28 | 29 | // CronJobSpec defines the desired state of CronJob 30 | type CronJobSpec struct { 31 | // The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. 32 | Schedule string `json:"schedule"` 33 | } 34 | 35 | // CronJobStatus defines the observed state of CronJob 36 | type CronJobStatus struct { 37 | // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster 38 | // Important: Run "make" to regenerate code after modifying this file 39 | 40 | // Information when was the last time the job was successfully scheduled. 41 | // +optional 42 | LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"` 43 | } 44 | 45 | // +kubebuilder:object:root=true 46 | // +kubebuilder:subresource:status 47 | // +kubebuilder:resource:singular=mycronjob 48 | 49 | // CronJob is the Schema for the cronjobs API 50 | type CronJob struct { 51 | /* 52 | */ 53 | metav1.TypeMeta `json:",inline"` 54 | metav1.ObjectMeta `json:"metadata,omitempty"` 55 | 56 | Spec CronJobSpec `json:"spec,omitempty"` 57 | Status CronJobStatus `json:"status,omitempty"` 58 | } 59 | 60 | // +kubebuilder:object:root=true 61 | 62 | // CronJobList contains a list of CronJob 63 | type CronJobList struct { 64 | metav1.TypeMeta `json:",inline"` 65 | metav1.ListMeta `json:"metadata,omitempty"` 66 | Items []CronJob `json:"items"` 67 | } 68 | 69 | func init() { 70 | SchemeBuilder.Register(&CronJob{}, &CronJobList{}) 71 | } 72 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/valid-ordered/manifests.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: admissionregistration.k8s.io/v1 3 | kind: ValidatingWebhookConfiguration 4 | metadata: 5 | name: validating-webhook-configuration 6 | webhooks: 7 | - admissionReviewVersions: 8 | - v1 9 | - v1beta1 10 | clientConfig: 11 | service: 12 | name: webhook-service 13 | namespace: system 14 | path: /validate-testdata-kubebuilder-io-v1-cronjob 15 | failurePolicy: Fail 16 | matchPolicy: Equivalent 17 | name: cronjob.testdata.kubebuilder.io 18 | rules: 19 | - apiGroups: 20 | - testdata.kubebuilder.io 21 | apiVersions: 22 | - v1 23 | operations: 24 | - CREATE 25 | - UPDATE 26 | resources: 27 | - cronjobs 28 | sideEffects: None 29 | - admissionReviewVersions: 30 | - v1 31 | - v1beta1 32 | clientConfig: 33 | service: 34 | name: webhook-service 35 | namespace: system 36 | path: /validate-testdata-kubebuilder-io-v1-cronjoblist 37 | failurePolicy: Fail 38 | matchPolicy: Equivalent 39 | name: cronjoblist.testdata.kubebuilder.io 40 | rules: 41 | - apiGroups: 42 | - testdata.kubebuilder.io 43 | apiVersions: 44 | - v1 45 | operations: 46 | - CREATE 47 | - UPDATE 48 | resources: 49 | - cronjoblist 50 | sideEffects: None 51 | - admissionReviewVersions: 52 | - v1 53 | - v1beta1 54 | clientConfig: 55 | service: 56 | name: webhook-service 57 | namespace: system 58 | path: /validate-testdata-kubebuilder-io-v1-deployments 59 | failurePolicy: Fail 60 | matchPolicy: Equivalent 61 | name: deployment.testdata.kubebuilder.io 62 | rules: 63 | - apiGroups: 64 | - testdata.kubebuilder.io 65 | apiVersions: 66 | - v1 67 | operations: 68 | - CREATE 69 | - UPDATE 70 | resources: 71 | - deployments 72 | sideEffects: None 73 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/valid-url/cronjob_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | //go:generate ../../../../.run-controller-gen.sh webhook paths=. output:dir=. 17 | 18 | // +groupName=testdata.kubebuilder.io 19 | // +versionName=v1 20 | package cronjob 21 | 22 | import ( 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | ) 25 | 26 | // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! 27 | // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. 28 | 29 | // CronJobSpec defines the desired state of CronJob 30 | type CronJobSpec struct { 31 | // The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. 32 | Schedule string `json:"schedule"` 33 | } 34 | 35 | // CronJobStatus defines the observed state of CronJob 36 | type CronJobStatus struct { 37 | // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster 38 | // Important: Run "make" to regenerate code after modifying this file 39 | 40 | // Information when was the last time the job was successfully scheduled. 41 | // +optional 42 | LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"` 43 | } 44 | 45 | // +kubebuilder:object:root=true 46 | // +kubebuilder:subresource:status 47 | // +kubebuilder:resource:singular=mycronjob 48 | 49 | // CronJob is the Schema for the cronjobs API 50 | type CronJob struct { 51 | /* 52 | */ 53 | metav1.TypeMeta `json:",inline"` 54 | metav1.ObjectMeta `json:"metadata,omitempty"` 55 | 56 | Spec CronJobSpec `json:"spec,omitempty"` 57 | Status CronJobStatus `json:"status,omitempty"` 58 | } 59 | 60 | // +kubebuilder:object:root=true 61 | 62 | // CronJobList contains a list of CronJob 63 | type CronJobList struct { 64 | metav1.TypeMeta `json:",inline"` 65 | metav1.ListMeta `json:"metadata,omitempty"` 66 | Items []CronJob `json:"items"` 67 | } 68 | 69 | func init() { 70 | SchemeBuilder.Register(&CronJob{}, &CronJobList{}) 71 | } 72 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/valid-url/manifests.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: admissionregistration.k8s.io/v1 3 | kind: MutatingWebhookConfiguration 4 | metadata: 5 | name: mutating-webhook-configuration 6 | webhooks: 7 | - admissionReviewVersions: 8 | - v1 9 | - v1beta1 10 | clientConfig: 11 | service: 12 | name: webhook-service 13 | namespace: system 14 | path: /mutate-testdata-kubebuilder-io-v1-cronjob 15 | failurePolicy: Fail 16 | matchPolicy: Equivalent 17 | name: default.cronjob.testdata.kubebuilder.io 18 | rules: 19 | - apiGroups: 20 | - testdata.kubebuilder.io 21 | apiVersions: 22 | - v1 23 | operations: 24 | - CREATE 25 | - UPDATE 26 | resources: 27 | - cronjobs 28 | sideEffects: None 29 | timeoutSeconds: 10 30 | reinvocationPolicy: IfNeeded 31 | --- 32 | apiVersion: admissionregistration.k8s.io/v1 33 | kind: ValidatingWebhookConfiguration 34 | metadata: 35 | name: validating-webhook-configuration 36 | webhooks: 37 | - admissionReviewVersions: 38 | - v1 39 | - v1beta1 40 | clientConfig: 41 | url: https://somewebhook:9443/validate-testdata-kubebuilder-io-v1-cronjob 42 | failurePolicy: Fail 43 | matchPolicy: Equivalent 44 | name: validation.cronjob.testdata.kubebuilder.io 45 | rules: 46 | - apiGroups: 47 | - testdata.kubebuilder.io 48 | apiVersions: 49 | - v1 50 | operations: 51 | - CREATE 52 | - UPDATE 53 | resources: 54 | - cronjobs 55 | sideEffects: None 56 | timeoutSeconds: 10 57 | - admissionReviewVersions: 58 | - v1 59 | - v1beta1 60 | clientConfig: 61 | url: https://anothersomewebhook:9443/validate-testdata-kubebuilder-io-v1-cronjob 62 | failurePolicy: Fail 63 | matchPolicy: Equivalent 64 | name: validation.cronjob.testdata.kubebuilder.io 65 | rules: 66 | - apiGroups: 67 | - testdata.kubebuilder.io 68 | apiVersions: 69 | - v1 70 | operations: 71 | - CREATE 72 | - UPDATE 73 | resources: 74 | - cronjobs 75 | sideEffects: NoneOnDryRun 76 | timeoutSeconds: 10 77 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/valid-url/webhook.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package cronjob 17 | 18 | import ( 19 | "k8s.io/apimachinery/pkg/runtime" 20 | ctrl "sigs.k8s.io/controller-runtime" 21 | "sigs.k8s.io/controller-runtime/pkg/webhook" 22 | ) 23 | 24 | func (c *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error { 25 | return ctrl.NewWebhookManagedBy(mgr). 26 | For(c). 27 | Complete() 28 | } 29 | 30 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1,url="https://somewebhook:9443/validate-testdata-kubebuilder-io-v1-cronjob" 31 | // +kubebuilder:webhook:url="https://anothersomewebhook:9443/validate-testdata-kubebuilder-io-v1-cronjob",verbs=create;update,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=NoneOnDryRun,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 32 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/mutate-testdata-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=default.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1,reinvocationPolicy=IfNeeded 33 | 34 | var _ webhook.Defaulter = &CronJob{} 35 | var _ webhook.Validator = &CronJob{} 36 | 37 | func (c *CronJob) Default() { 38 | } 39 | 40 | func (c *CronJob) ValidateCreate() error { 41 | return nil 42 | } 43 | 44 | func (c *CronJob) ValidateUpdate(_ runtime.Object) error { 45 | return nil 46 | } 47 | 48 | func (c *CronJob) ValidateDelete() error { 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/valid/cronjob_types.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | //go:generate ../../../../.run-controller-gen.sh webhook paths=. output:dir=. 17 | 18 | // +groupName=testdata.kubebuilder.io 19 | // +versionName=v1 20 | package cronjob 21 | 22 | import ( 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | ) 25 | 26 | // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! 27 | // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. 28 | 29 | // CronJobSpec defines the desired state of CronJob 30 | type CronJobSpec struct { 31 | // The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. 32 | Schedule string `json:"schedule"` 33 | } 34 | 35 | // CronJobStatus defines the observed state of CronJob 36 | type CronJobStatus struct { 37 | // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster 38 | // Important: Run "make" to regenerate code after modifying this file 39 | 40 | // Information when was the last time the job was successfully scheduled. 41 | // +optional 42 | LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"` 43 | } 44 | 45 | // +kubebuilder:object:root=true 46 | // +kubebuilder:subresource:status 47 | // +kubebuilder:resource:singular=mycronjob 48 | 49 | // CronJob is the Schema for the cronjobs API 50 | type CronJob struct { 51 | /* 52 | */ 53 | metav1.TypeMeta `json:",inline"` 54 | metav1.ObjectMeta `json:"metadata,omitempty"` 55 | 56 | Spec CronJobSpec `json:"spec,omitempty"` 57 | Status CronJobStatus `json:"status,omitempty"` 58 | } 59 | 60 | // +kubebuilder:object:root=true 61 | 62 | // CronJobList contains a list of CronJob 63 | type CronJobList struct { 64 | metav1.TypeMeta `json:",inline"` 65 | metav1.ListMeta `json:"metadata,omitempty"` 66 | Items []CronJob `json:"items"` 67 | } 68 | 69 | func init() { 70 | SchemeBuilder.Register(&CronJob{}, &CronJobList{}) 71 | } 72 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/valid/manifests.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: admissionregistration.k8s.io/v1 3 | kind: MutatingWebhookConfiguration 4 | metadata: 5 | name: mutating-webhook-configuration 6 | webhooks: 7 | - admissionReviewVersions: 8 | - v1 9 | - v1beta1 10 | clientConfig: 11 | service: 12 | name: webhook-service 13 | namespace: system 14 | path: /mutate-testdata-kubebuilder-io-v1-cronjob 15 | failurePolicy: Fail 16 | matchPolicy: Equivalent 17 | name: default.cronjob.testdata.kubebuilder.io 18 | rules: 19 | - apiGroups: 20 | - testdata.kubebuilder.io 21 | apiVersions: 22 | - v1 23 | operations: 24 | - CREATE 25 | - UPDATE 26 | resources: 27 | - cronjobs 28 | sideEffects: None 29 | timeoutSeconds: 10 30 | reinvocationPolicy: IfNeeded 31 | --- 32 | apiVersion: admissionregistration.k8s.io/v1 33 | kind: ValidatingWebhookConfiguration 34 | metadata: 35 | name: validating-webhook-configuration 36 | webhooks: 37 | - admissionReviewVersions: 38 | - v1 39 | - v1beta1 40 | clientConfig: 41 | service: 42 | name: webhook-service 43 | namespace: system 44 | path: /validate-testdata-kubebuilder-io-v1-cronjob 45 | failurePolicy: Fail 46 | matchPolicy: Equivalent 47 | name: validation.cronjob.testdata.kubebuilder.io 48 | rules: 49 | - apiGroups: 50 | - testdata.kubebuilder.io 51 | apiVersions: 52 | - v1 53 | operations: 54 | - CREATE 55 | - UPDATE 56 | resources: 57 | - cronjobs 58 | sideEffects: None 59 | timeoutSeconds: 10 60 | - admissionReviewVersions: 61 | - v1 62 | - v1beta1 63 | clientConfig: 64 | service: 65 | name: webhook-service 66 | namespace: system 67 | path: /validate-testdata-kubebuilder-io-v1-cronjob 68 | failurePolicy: Fail 69 | matchPolicy: Equivalent 70 | name: validation.cronjob.testdata.kubebuilder.io 71 | rules: 72 | - apiGroups: 73 | - testdata.kubebuilder.io 74 | apiVersions: 75 | - v1 76 | operations: 77 | - CREATE 78 | - UPDATE 79 | resources: 80 | - cronjobs 81 | sideEffects: NoneOnDryRun 82 | timeoutSeconds: 10 83 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/valid/webhook.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package cronjob 17 | 18 | import ( 19 | "k8s.io/apimachinery/pkg/runtime" 20 | ctrl "sigs.k8s.io/controller-runtime" 21 | "sigs.k8s.io/controller-runtime/pkg/webhook" 22 | ) 23 | 24 | func (c *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error { 25 | return ctrl.NewWebhookManagedBy(mgr). 26 | For(c). 27 | Complete() 28 | } 29 | 30 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 31 | // +kubebuilder:webhook:verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=NoneOnDryRun,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 32 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/mutate-testdata-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=default.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1,reinvocationPolicy=IfNeeded 33 | 34 | var _ webhook.Defaulter = &CronJob{} 35 | var _ webhook.Validator = &CronJob{} 36 | 37 | func (c *CronJob) Default() { 38 | } 39 | 40 | func (c *CronJob) ValidateCreate() error { 41 | return nil 42 | } 43 | 44 | func (c *CronJob) ValidateUpdate(_ runtime.Object) error { 45 | return nil 46 | } 47 | 48 | func (c *CronJob) ValidateDelete() error { 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /pkg/webhook/testdata/webhook.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | */ 15 | 16 | package cronjob 17 | 18 | import ( 19 | "k8s.io/apimachinery/pkg/runtime" 20 | ctrl "sigs.k8s.io/controller-runtime" 21 | "sigs.k8s.io/controller-runtime/pkg/webhook" 22 | ) 23 | 24 | func (c *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error { 25 | return ctrl.NewWebhookManagedBy(mgr). 26 | For(c). 27 | Complete() 28 | } 29 | 30 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 31 | // +kubebuilder:webhook:verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=NoneOnDryRun,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1 32 | // +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/mutate-testdata-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=default.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1,reinvocationPolicy=Never 33 | 34 | var _ webhook.Defaulter = &CronJob{} 35 | var _ webhook.Validator = &CronJob{} 36 | 37 | func (c *CronJob) Default() { 38 | } 39 | 40 | func (c *CronJob) ValidateCreate() error { 41 | return nil 42 | } 43 | 44 | func (c *CronJob) ValidateUpdate(_ runtime.Object) error { 45 | return nil 46 | } 47 | 48 | func (c *CronJob) ValidateDelete() error { 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /pkg/webhook/webhook_suite_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package webhook_test 18 | 19 | import ( 20 | "testing" 21 | 22 | . "github.com/onsi/ginkgo" 23 | . "github.com/onsi/gomega" 24 | ) 25 | 26 | func TestWebhookGeneration(t *testing.T) { 27 | RegisterFailHandler(Fail) 28 | RunSpecs(t, "Webhook Generation Suite") 29 | } 30 | --------------------------------------------------------------------------------