diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml deleted file mode 100644 index 1779e7450..000000000 --- a/.github/dependabot.yaml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -# Maintain dependencies for GitHub Actions -- package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "daily" \ No newline at end of file diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 3bd2dc946..6f8ae05be 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,21 +1,13 @@ -## Summary - -## Related issue(s) +See the monorepo structure document for more details: +https://docs.kcp.io/kcp/main/contributing/monorepo/ -Fixes # +--> diff --git a/.github/workflows/pr-verifier.yaml b/.github/workflows/pr-verifier.yaml deleted file mode 100644 index 5d152c258..000000000 --- a/.github/workflows/pr-verifier.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: PR Verifier - -on: - # NB: using `pull_request_target` runs this in the context of - # the base repository, so it has permission to upload to the checks API. - # This means changes won't kick in to this file until merged onto the - # main branch. - pull_request_target: - types: [opened, edited, reopened, synchronize] - -jobs: - verify: - name: verify PR contents - permissions: - checks: write - pull-requests: read - runs-on: ubuntu-latest - steps: - - name: Verifier action - id: verifier - uses: kubernetes-sigs/kubebuilder-release-tools@v0.3.0 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 05a7332f6..80048efd4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ *.dll *.so *.dylib -/bin +/_build # Test binary, built with `go test -c` *.test @@ -14,9 +14,7 @@ # Dependency directories vendor/ +hack/tools/ # IDE files .idea - -hack/tools - diff --git a/.prow.yaml b/.prow.yaml deleted file mode 100644 index 390577a0c..000000000 --- a/.prow.yaml +++ /dev/null @@ -1,40 +0,0 @@ -presubmits: - - name: pull-code-generator-verify - always_run: true - decorate: true - clone_uri: "ssh://git@github.com/kcp-dev/code-generator.git" - labels: - preset-goproxy: "true" - spec: - containers: - - image: ghcr.io/kcp-dev/infra/build:1.19.9-1 - command: - - make - - verify-codegen - - verify-boilerplate - - - name: pull-code-generator-lint - always_run: true - decorate: true - clone_uri: "ssh://git@github.com/kcp-dev/code-generator.git" - labels: - preset-goproxy: "true" - spec: - containers: - - image: ghcr.io/kcp-dev/infra/build:1.19.9-1 - command: - - make - - lint - - - name: pull-code-generator-test - always_run: true - decorate: true - clone_uri: "ssh://git@github.com/kcp-dev/code-generator.git" - labels: - preset-goproxy: "true" - spec: - containers: - - image: ghcr.io/kcp-dev/infra/build:1.19.9-1 - command: - - make - - test diff --git a/Makefile b/Makefile index 32a2bdf1d..993687697 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Copyright 2022 The KCP Authors. +# Copyright 2025 The KCP Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,91 +14,57 @@ SHELL := /usr/bin/env bash -GO_INSTALL = ./hack/go-install.sh +KCP_ROOT_DIR ?= $(abspath ../../../../..) + +GO_INSTALL = $(KCP_ROOT_DIR)/hack/go-install.sh + +BUILD_DEST ?= _build +BUILDFLAGS ?= +CMD ?= $(notdir $(wildcard ./cmd/*)) TOOLS_DIR=hack/tools -GOBIN_DIR := $(abspath $(TOOLS_DIR)) +GOBIN_DIR := $(KCP_ROOT_DIR)/$(TOOLS_DIR) TMPDIR := $(shell mktemp -d) -CONTROLLER_GEN_VER := v0.8.0 -CONTROLLER_GEN_BIN := controller-gen -CONTROLLER_GEN := $(GOBIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER) -export CONTROLLER_GEN - -GOLANGCI_LINT_VER := v1.49.0 +GOLANGCI_LINT_VER := v2.1.6 GOLANGCI_LINT_BIN := golangci-lint GOLANGCI_LINT := $(GOBIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER) -KUBE_CLIENT_GEN_VER := v0.26.3 -KUBE_CLIENT_GEN_BIN := client-gen -KUBE_LISTER_GEN_VER := v0.26.3 -KUBE_LISTER_GEN_BIN := lister-gen -KUBE_INFORMER_GEN_VER := v0.26.3 -KUBE_INFORMER_GEN_BIN := informer-gen -KUBE_APPLYCONFIGURATION_GEN_VER := v0.26.3 -KUBE_APPLYCONFIGURATION_GEN_BIN := applyconfiguration-gen - -KUBE_CLIENT_GEN := $(GOBIN_DIR)/$(KUBE_CLIENT_GEN_BIN)-$(KUBE_CLIENT_GEN_VER) -export KUBE_CLIENT_GEN -KUBE_LISTER_GEN := $(GOBIN_DIR)/$(KUBE_LISTER_GEN_BIN)-$(KUBE_LISTER_GEN_VER) -export KUBE_LISTER_GEN -KUBE_INFORMER_GEN := $(GOBIN_DIR)/$(KUBE_INFORMER_GEN_BIN)-$(KUBE_INFORMER_GEN_VER) -export KUBE_INFORMER_GEN -KUBE_APPLYCONFIGURATION_GEN := $(GOBIN_DIR)/$(KUBE_APPLYCONFIGURATION_GEN_BIN)-$(KUBE_APPLYCONFIGURATION_GEN_VER) -export KUBE_APPLYCONFIGURATION_GEN - -OPENSHIFT_GOIMPORTS_VER := c72f1dc2e3aacfa00aece3391d938c9bc734e791 -OPENSHIFT_GOIMPORTS_BIN := openshift-goimports -OPENSHIFT_GOIMPORTS := $(TOOLS_DIR)/$(OPENSHIFT_GOIMPORTS_BIN)-$(OPENSHIFT_GOIMPORTS_VER) -export OPENSHIFT_GOIMPORTS # so hack scripts can use it - -$(OPENSHIFT_GOIMPORTS): - GOBIN=$(GOBIN_DIR) $(GO_INSTALL) github.com/openshift-eng/openshift-goimports $(OPENSHIFT_GOIMPORTS_BIN) $(OPENSHIFT_GOIMPORTS_VER) - -imports: $(OPENSHIFT_GOIMPORTS) - $(OPENSHIFT_GOIMPORTS) -m github.com/kcp-dev/code-generator - $(OPENSHIFT_GOIMPORTS) --path ./examples -m acme.corp -.PHONY: imports +$(GOLANGCI_LINT): + GOBIN=$(GOBIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER) -$(CONTROLLER_GEN): - GOBIN=$(GOBIN_DIR) $(GO_INSTALL) sigs.k8s.io/controller-tools/cmd/$(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER) +.PHONY: imports +imports: WHAT ?= +imports: $(GOLANGCI_LINT) + if [ -n "$(WHAT)" ]; then \ + $(GOLANGCI_LINT) fmt --enable gci -c $(KCP_ROOT_DIR)/.golangci.yaml $(WHAT); \ + else \ + $(GOLANGCI_LINT) fmt --enable gci -c $(KCP_ROOT_DIR)/.golangci.yaml ; \ + fi; + +.PHONY: clean +clean: + rm -rf $(BUILD_DEST) + @echo "Cleaned $(BUILD_DEST)" -$(KUBE_CLIENT_GEN): - GOBIN=$(GOBIN_DIR) $(GO_INSTALL) k8s.io/code-generator/cmd/$(KUBE_CLIENT_GEN_BIN) $(KUBE_CLIENT_GEN_BIN) $(KUBE_CLIENT_GEN_VER) -$(KUBE_LISTER_GEN): - GOBIN=$(GOBIN_DIR) $(GO_INSTALL) k8s.io/code-generator/cmd/$(KUBE_LISTER_GEN_BIN) $(KUBE_LISTER_GEN_BIN) $(KUBE_LISTER_GEN_VER) -$(KUBE_INFORMER_GEN): - GOBIN=$(GOBIN_DIR) $(GO_INSTALL) k8s.io/code-generator/cmd/$(KUBE_INFORMER_GEN_BIN) $(KUBE_INFORMER_GEN_BIN) $(KUBE_INFORMER_GEN_VER) -$(KUBE_APPLYCONFIGURATION_GEN): - GOBIN=$(GOBIN_DIR) $(GO_INSTALL) k8s.io/code-generator/cmd/$(KUBE_APPLYCONFIGURATION_GEN_BIN) $(KUBE_APPLYCONFIGURATION_GEN_BIN) $(KUBE_APPLYCONFIGURATION_GEN_VER) +.PHONY: build +build: $(CMD) +.PHONY: $(CMD) +$(CMD): %: $(BUILD_DEST)/% -.PHONY: build -build: ## Build the project - mkdir -p bin - go build -o bin +$(BUILD_DEST)/%: cmd/% + go build $(BUILDFLAGS) -o $@ ./cmd/$* .PHONY: install install: go install .PHONY: codegen -codegen: $(CONTROLLER_GEN) $(KUBE_CLIENT_GEN) $(KUBE_LISTER_GEN) $(KUBE_INFORMER_GEN) $(KUBE_APPLYCONFIGURATION_GEN) build +codegen: build ./hack/update-codegen.sh $(MAKE) imports -$(GOLANGCI_LINT): - GOBIN=$(GOBIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER) - -.PHONY: lint -lint: $(GOLANGCI_LINT) - $(GOLANGCI_LINT) run --timeout=10m ./... - cd examples && $(GOLANGCI_LINT) run --timeout=10m ./... - -.PHONY: test -test: - go test ./... - # Note, running this locally if you have any modified files, even those that are not generated, # will result in an error. This target is mostly for CI jobs. .PHONY: verify-codegen @@ -115,12 +81,3 @@ verify-codegen: echo "You need to run 'make codegen' to update generated files and commit them"; \ exit 1; \ fi - -$(TOOLS_DIR)/verify_boilerplate.py: - mkdir -p $(TOOLS_DIR) - curl --fail --retry 3 -L -o $(TOOLS_DIR)/verify_boilerplate.py https://raw.githubusercontent.com/kubernetes/repo-infra/master/hack/verify_boilerplate.py - chmod +x $(TOOLS_DIR)/verify_boilerplate.py - -.PHONY: verify-boilerplate -verify-boilerplate: $(TOOLS_DIR)/verify_boilerplate.py - $(TOOLS_DIR)/verify_boilerplate.py --boilerplate-dir=hack/boilerplate diff --git a/OWNERS b/OWNERS index 0bddfe94f..bb4aad297 100644 --- a/OWNERS +++ b/OWNERS @@ -1,7 +1,7 @@ approvers: - - ncdc - - stevekuznetsov - - fabianvf - - varshaprasad96 - - njhale - - sttts +- clubanderson +- scheeles +- sttts +- xrstf +- mjudeikis +- embik diff --git a/README.md b/README.md index c81291187..ccdabd9e3 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,82 @@ -## Code Generators for KCP-aware informers and listers +> ⚠️ **This is an automatically published staged repository for kcp**. +> Contributions, including issues and pull requests, should be made to the main kcp repository: [https://github.com/kcp-dev/kcp](https://github.com/kcp-dev/kcp). +> This repository is read-only for importing, and not used for direct contributions. +> See the [monorepo structure document](https://docs.kcp.io/kcp/main/contributing/monorepo/) for more details. -### Usage: +## Code Generators for KCP-aware clients, informers and listers -``` -code-generator [input-flags] -``` +This repository contains code generation tools analogous to the Kubernetes +code-generator. It contains: -where `` can be one of: -- lister -- informer +* `cluster-client-gen` to generate a cluster-aware clientset, +* `cluster-informer-gen` to generate cluster-aware informers and +* `cluster-lister-gen` to do the same for listers. -It is possible to run the code generation for multiple components at once `code-generator lister,informer [input-flags]` +Note that you need to have generated the versioned Kubernetes clientset and +applyconfiguration packages already in order to generate and use cluster-aware +code. Single-cluster listers and informers however are optional and the +generator here can generate the necessary interfaces itself. -#### Input flags: +### Usage -1. `--input-dir` - The directory path where APIs are defined. Make sure that the types are defined in `/pkg/apis/{$GROUP}/{$VERSION}`. For example, if your input apis are defined in `types.go` inside `examples/pkg/apis/apps/v1/types.go`, the input directory should be specified as `examples/pkg`. `{$GROUP}/{$VERSION}` is appended in the input path. -**Note**: This is the relative path to the input directory where APIs live. +It is strongly recommended to use the provided `cluster_codegen.sh`, which works +very much like Kubernetes' `kube_codegen.sh`. A common way to acquire it is to +have a synthetic Go dependency on `github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen` +(often done in a `hack/tools.go`) and then call it like so in your project: -2. `--output-dir` - The directory where output clients are to be generated. It defaults to the `output` folder under current working directory. - - Listers are output to `/listers/${GROUP}/${VERSION}/${TYPE}.go` - - Individual informers are output to `/informers/externalversions/${GROUP}/${VERSION}/${TYPE}.go` +```bash +# Often you would want to generate both the regular Kubernetes clientset and +# the cluster-aware clienset. -3. `--clientset-api-path` - The path to where `clientset` generated by `k8s.io/code-gen` is present. +CODEGEN_PKG="$(go list -f '{{.Dir}}' -m k8s.io/code-generator)" +CLUSTER_CODEGEN_PKG="$(go list -f '{{.Dir}}' -m github.com/kcp-dev/code-generator/v3)" -4. `--group-versions` - List of group versions in the format `group:version`. Define multiple groups by specifying the flag again. For example, the inputs can be: - - `--group-version="apps:v1"` - - `--group-versions="rbac:v1" --group-versions="apps:v1"` - - `--group-version="rbac:v1,v2"` +source "$CODEGEN_PKG/kube_codegen.sh" +source "$CLUSTER_CODEGEN_PKG/cluster_codegen.sh" -5. `--go-header-file` - Path to the header file. +# Now you can call kube::codegen:: and cluster::codegen:: functions. -Example: -To run it locally and see how it works, use the following command: +kube::codegen::gen_client \ + --boilerplate hack/boilerplate/examples/boilerplate.generatego.txt \ + --output-dir pkg/generated \ + --output-pkg acme.corp/pkg/generated \ + --with-applyconfig \ + --applyconfig-name applyconfigurations \ + --with-watch \ + ./pkg/apis +cluster::codegen::gen_client \ + --boilerplate hack/boilerplate/examples/boilerplate.generatego.txt \ + --output-dir pkg/clients \ + --output-pkg acme.corp/pkg/clients \ + --with-watch \ + --single-cluster-versioned-clientset-pkg acme.corp/pkg/generated/clientset/versioned \ + --single-cluster-applyconfigurations-pkg acme.corp/pkg/generated/applyconfigurations \ + --single-cluster-listers-pkg acme.corp/pkg/generated/listers \ + --single-cluster-informers-pkg acme.corp/pkg/generated/informers/externalversions \ + pkg/apis ``` -go run main.go informer,lister --go-header-file testdata/header.txt - --clientset-api-path=github.com/kcp-dev/code-generator/testdata/pkg/generated/clientset/versioned - --input-dir testdata/pkg/apis - --output-dir testdata/pkg --group-versions example:v1 -``` -creates output folders in `testdata/pkg/informers` and `testdata/pkg/listers`. +Please refer to the [cluster_codegen.sh](./cluster_codegen.sh) for more information +on the available command line flags. + +## Contributing + +We ❤️ our contributors! If you're interested in helping us out, please check out [contributing to kcp](https://docs.kcp.io/kcp/main/contributing/). + +This community has a [Code of Conduct](./code-of-conduct.md). Please make sure to follow it. + +## Getting in touch + +There are several ways to communicate with us: + +- The [`#kcp-dev` channel](https://app.slack.com/client/T09NY5SBT/C021U8WSAFK) in the [Kubernetes Slack workspace](https://slack.k8s.io). +- Our mailing lists: + - [kcp-dev](https://groups.google.com/g/kcp-dev) for development discussions. + - [kcp-users](https://groups.google.com/g/kcp-users) for discussions among users and potential users. +- By joining the kcp-dev mailing list, you should receive an invite to our bi-weekly community meetings. +- See recordings of past community meetings on [YouTube](https://www.youtube.com/channel/UCfP_yS5uYix0ppSbm2ltS5Q). +- The next community meeting dates are available via our [CNCF community group](https://community.cncf.io/kcp/). +- Check the [community meeting notes document](https://docs.google.com/document/d/1PrEhbmq1WfxFv1fTikDBZzXEIJkUWVHdqDFxaY1Ply4) for future and past meeting agendas. +- Browse the [shared Google Drive](https://drive.google.com/drive/folders/1FN7AZ_Q1CQor6eK0gpuKwdGFNwYI517M?usp=sharing) to share design docs, notes, etc. + - Members of the kcp-dev mailing list can view this drive. diff --git a/cluster_codegen.sh b/cluster_codegen.sh new file mode 100755 index 000000000..bb9e2847f --- /dev/null +++ b/cluster_codegen.sh @@ -0,0 +1,412 @@ +#!/usr/bin/env bash + +# Copyright 2025 The KCP Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This presents several functions for packages which want to use kcp +# code-generation tools. + +# These functions insist that your input IDL (commented go) files be located in +# go packages following the pattern $input_pkg_root/$something_sans_slash/$api_version. +# Those $something_sans_slash will be propagated into the output directory structure. + +# This file has been adapted from k8s.io/code-generator and can be sourced in +# parallel to its kube_codegen.sh. It works the same way, just with cluster:: as the +# function prefix rather than kube::. + +set -o errexit +set -o nounset +set -o pipefail + +CLUSTER_CODEGEN_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" + +# Callers which want a specific tag of the github.com/kcp-dev/code-generator repo +# should set the CLUSTER_CODEGEN_TAG to the tag name, e.g. CLUSTER_CODEGEN_TAG="kcp-1.32.2" +# before sourcing this file. +CLUSTER_CODEGEN_VERSION_SPEC="${CLUSTER_CODEGEN_TAG:+"@${CLUSTER_CODEGEN_TAG}"}" + +function cluster::codegen::internal::grep() { + # We use `grep` rather than `git grep` because sometimes external projects + # use this across repos. + grep "$@" \ + --exclude-dir .git \ + --exclude-dir _output \ + --exclude-dir vendor +} + +# Generate client code +# +# USAGE: cluster::codegen::gen_client [FLAGS] +# +# +# The root package under which to search for Go files which request clients +# to be generated. This must be a local path, not a Go package. +# +# See note at the top about package structure below that. +# +# FLAGS: +# --one-input-api +# A specific API (a directory) under the input-dir for which to generate a +# client. If this is not set, clients for all APIs under the input-dir +# will be generated (under the --output-pkg). +# +# --boilerplate +# An optional override for the header file to insert into generated files. +# +# --output-dir +# The root directory under which to emit code. Each aspect of client +# generation will make one or more subdirectories unless an explicit +# directory for that aspect is configured also. +# +# --output-pkg +# The Go package path (import path) of the --output-dir. Each aspect of +# client generation will make one or more sub-packages unless an explicit +# package for that aspect is configured also. +# +# --versioned-clientset-dir +# The root directory under which to emit the generated cluster-aware clientset. +# Overwrites the automatic detection based on --output-dir. +# +# --versioned-clientset-pkg +# The Go package path (import path) of the --versioned-clientset-dir. +# Overwrites the automatic detection based on --output-dir. +# +# --informers-dir +# The root directory under which to emit the generated cluster-aware informers. +# Overwrites the automatic detection based on --output-dir. +# +# --informers-pkg +# The Go package path (import path) of the --informers-dir. +# Overwrites the automatic detection based on --output-dir. +# +# --listers-dir +# The root directory under which to emit the generated cluster-aware listers. +# Overwrites the automatic detection based on --output-dir. +# +# --listers-pkg +# The Go package path (import path) of the --listers-dir. +# Overwrites the automatic detection based on --output-dir. +# +# --single-cluster-versioned-clientset-pkg +# The package name of the generated versioned Kubernetes clientset, e.g. +# "acme.corp/sdk/generated/clientset/versioned". This has to have already been +# generated by k8s.io/code-generator. +# +# --single-cluster-applyconfigurations-pkg +# The name of the generated Kubernetes applyconfiguration package, e.g. +# "acme.corp/sdk/generated/applyconfigurations". This has to have already been +# generated by k8s.io/code-generator. +# +# --single-cluster-informers-pkg +# The optional name of the generated Kubernetes informers package, e.g. +# "acme.corp/sdk/generated/informers". This has to have already been +# generated by k8s.io/code-generator. If not specified, the generated cluster +# informers will include the necessary interfaces themselves. +# +# --single-cluster-listers-pkg +# The optional name of the generated Kubernetes listers package, e.g. +# "acme.corp/sdk/generated/listers". This has to have already been +# generated by k8s.io/code-generator. If not specified, the generated cluster +# listers will include the necessary interfaces themselves. +# +# --with-watch +# Enables generation of listers and informers for APIs which support WATCH. +# +# --plural-exceptions +# An optional list of comma separated plural exception definitions in Type:PluralizedType form. +# +# --exclude-group-versions +# An optional list of comma separate group versions to exclude from +# client generation. +# +function cluster::codegen::gen_client() { + local in_dir="" + local one_input_api="" + local boilerplate="${CLUSTER_CODEGEN_ROOT}/hack/boilerplate.go.txt" + local out_dir="" + local out_pkg="" + local versioned_clientset_dir="" + local versioned_clientset_pkg="" + local informers_dir="" + local informers_pkg="" + local listers_dir="" + local listers_pkg="" + local single_cluster_versioned_clientset_pkg="" + local single_cluster_applyconfigurations_pkg="" + local single_cluster_informers_pkg="" + local single_cluster_listers_pkg="" + local watchable="false" + local plural_exceptions="" + local exclude_group_versions="" + local v="${KUBE_VERBOSE:-0}" + + while [ "$#" -gt 0 ]; do + case "$1" in + "--one-input-api") + one_input_api="/$2" + shift 2 + ;; + "--boilerplate") + boilerplate="$2" + shift 2 + ;; + "--output-dir") + out_dir="$2" + shift 2 + ;; + "--output-pkg") + out_pkg="$2" + shift 2 + ;; + "--versioned-clientset-dir") + versioned_clientset_dir="$2" + shift 2 + ;; + "--versioned-clientset-pkg") + versioned_clientset_pkg="$2" + shift 2 + ;; + "--informers-dir") + informers_dir="$2" + shift 2 + ;; + "--informers-pkg") + informers_pkg="$2" + shift 2 + ;; + "--listers-dir") + listers_dir="$2" + shift 2 + ;; + "--listers-pkg") + listers_pkg="$2" + shift 2 + ;; + "--single-cluster-versioned-clientset-pkg") + single_cluster_versioned_clientset_pkg="$2" + shift 2 + ;; + "--single-cluster-applyconfigurations-pkg") + single_cluster_applyconfigurations_pkg="$2" + shift 2 + ;; + "--single-cluster-informers-pkg") + single_cluster_informers_pkg="$2" + shift 2 + ;; + "--single-cluster-listers-pkg") + single_cluster_listers_pkg="$2" + shift 2 + ;; + "--with-watch") + watchable="true" + shift + ;; + "--plural-exceptions") + plural_exceptions="$2" + shift 2 + ;; + "--exclude-group-versions") + exclude_group_versions="$2" + shift 2 + ;; + *) + if [[ "$1" =~ ^-- ]]; then + echo "unknown argument: $1" >&2 + return 1 + fi + if [ -n "$in_dir" ]; then + echo "too many arguments: $1 (already have $in_dir)" >&2 + return 1 + fi + in_dir="$1" + shift + ;; + esac + done + + if [ -z "${in_dir}" ]; then + echo "input-dir argument is required" >&2 + return 1 + fi + if [ -z "${single_cluster_versioned_clientset_pkg}" ]; then + echo "--single-cluster-versioned-clientset-pkg is required" >&2 + return 1 + fi + if [ -z "${single_cluster_applyconfigurations_pkg}" ]; then + echo "--single-cluster-applyconfigurations-pkg is required" >&2 + return 1 + fi + + ( + # To support running this from anywhere, first cd into this directory, + # and then install with forced module mode on and fully qualified name. + cd "${CLUSTER_CODEGEN_ROOT}" + BINS=( + cluster-client-gen"${CLUSTER_CODEGEN_VERSION_SPEC}" + cluster-informer-gen"${CLUSTER_CODEGEN_VERSION_SPEC}" + cluster-lister-gen"${CLUSTER_CODEGEN_VERSION_SPEC}" + ) + # shellcheck disable=2046 # printf word-splitting is intentional + GO111MODULE=on go install $(printf "github.com/kcp-dev/code-generator/v3/cmd/%s " "${BINS[@]}") + ) + # Go installs in $GOBIN if defined, and $GOPATH/bin otherwise + gobin="${GOBIN:-$(go env GOPATH)/bin}" + + local group_versions=() + local input_pkgs=() + while read -r dir; do + pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)" + leaf="$(basename "${dir}")" + if grep -E -q '^v[0-9]+((alpha|beta)[0-9]+)?$' <<< "${leaf}"; then + input_pkgs+=("${pkg}") + + dir2="$(dirname "${dir}")" + leaf2="$(basename "${dir2}")" + gv="${leaf2}/${leaf}" + + if [[ " ${exclude_group_versions} " == *" ${gv} "* ]]; then + continue + fi + + group_versions+=("${gv}") + fi + done < <( + ( cluster::codegen::internal::grep -l --null \ + -e '^\s*//\s*+genclient' \ + -r "${in_dir}${one_input_api}" \ + --include '*.go' \ + || true \ + ) | while read -r -d $'\0' F; do dirname "${F}"; done \ + | LC_ALL=C sort -u + ) + + if [ "${#group_versions[@]}" == 0 ]; then + return 0 + fi + + echo "Generating cluster client code for ${#group_versions[@]} targets" + + if [[ -z "${versioned_clientset_dir}" ]]; then + if [ -z "${out_dir}" ]; then + echo "--output-dir is required when no --versioned-clientset-dir is provided" >&2 + return 1 + fi + versioned_clientset_dir="${out_dir}/clientset/versioned" + fi + + if [[ -z "${versioned_clientset_pkg}" ]]; then + if [ -z "${out_pkg}" ]; then + echo "--output-pkg is required when no --versioned-clientset-pkg is provided" >&2 + return 1 + fi + versioned_clientset_pkg="${out_pkg}/clientset/versioned" + fi + + ( cluster::codegen::internal::grep -l --null \ + -e '^// Code generated by cluster-client-gen. DO NOT EDIT.$' \ + -r "${versioned_clientset_dir}" \ + --include '*.go' \ + || true \ + ) | xargs -0 rm -f + + local inputs=() + for arg in "${group_versions[@]}"; do + inputs+=("--input" "$arg") + done + "${gobin}/cluster-client-gen" \ + -v "${v}" \ + --go-header-file "${boilerplate}" \ + --output-dir "${versioned_clientset_dir}" \ + --output-pkg "${versioned_clientset_pkg}" \ + --input-base "$(cd "${in_dir}" && pwd -P)" `# must be absolute path or Go import path"` \ + --single-cluster-versioned-clientset-pkg "${single_cluster_versioned_clientset_pkg}" \ + --single-cluster-applyconfigurations-pkg "${single_cluster_applyconfigurations_pkg}" \ + --plural-exceptions "${plural_exceptions}" \ + "${inputs[@]}" + + if [ "${watchable}" == "true" ]; then + echo "Generating cluster lister code for ${#input_pkgs[@]} targets" + + if [[ -z "${listers_dir}" ]]; then + if [ -z "${out_dir}" ]; then + echo "--output-dir is required when no --listers-dir is provided" >&2 + return 1 + fi + listers_dir="${out_dir}/listers" + fi + + if [[ -z "${listers_pkg}" ]]; then + if [ -z "${out_pkg}" ]; then + echo "--output-pkg is required when no --listers-pkg is provided" >&2 + return 1 + fi + listers_pkg="${out_pkg}/listers" + fi + + ( cluster::codegen::internal::grep -l --null \ + -e '^// Code generated by cluster-lister-gen. DO NOT EDIT.$' \ + -r "${listers_dir}" \ + --include '*.go' \ + || true \ + ) | xargs -0 rm -f + + "${gobin}/cluster-lister-gen" \ + -v "${v}" \ + --go-header-file "${boilerplate}" \ + --output-dir "${listers_dir}" \ + --output-pkg "${listers_pkg}" \ + --single-cluster-listers-pkg "${single_cluster_listers_pkg}" \ + --plural-exceptions "${plural_exceptions}" \ + "${input_pkgs[@]}" + + echo "Generating cluster informer code for ${#input_pkgs[@]} targets" + + if [[ -z "${informers_dir}" ]]; then + if [ -z "${out_dir}" ]; then + echo "--output-dir is required when no --informers-dir is provided" >&2 + return 1 + fi + informers_dir="${out_dir}/informers" + fi + + if [[ -z "${informers_pkg}" ]]; then + if [ -z "${out_pkg}" ]; then + echo "--output-pkg is required when no --informers-pkg is provided" >&2 + return 1 + fi + informers_pkg="${out_pkg}/informers" + fi + + ( cluster::codegen::internal::grep -l --null \ + -e '^// Code generated by cluster-informer-gen. DO NOT EDIT.$' \ + -r "${informers_dir}" \ + --include '*.go' \ + || true \ + ) | xargs -0 rm -f + + "${gobin}/cluster-informer-gen" \ + -v "${v}" \ + --go-header-file "${boilerplate}" \ + --output-dir "${informers_dir}" \ + --output-pkg "${informers_pkg}" \ + --versioned-clientset-pkg "${versioned_clientset_pkg}" \ + --listers-pkg "${listers_pkg}" \ + --single-cluster-listers-pkg "${single_cluster_listers_pkg}" \ + --single-cluster-informers-pkg "${single_cluster_informers_pkg}" \ + --single-cluster-versioned-clientset-pkg "${single_cluster_versioned_clientset_pkg}" \ + --plural-exceptions "${plural_exceptions}" \ + "${input_pkgs[@]}" + fi +} diff --git a/cmd/cluster-client-gen/README.md b/cmd/cluster-client-gen/README.md new file mode 100644 index 000000000..b8206127f --- /dev/null +++ b/cmd/cluster-client-gen/README.md @@ -0,0 +1,2 @@ +See [generating-clientset.md](https://git.k8s.io/community/contributors/devel/sig-api-machinery/generating-clientset.md) + diff --git a/cmd/cluster-client-gen/args/args.go b/cmd/cluster-client-gen/args/args.go new file mode 100644 index 000000000..81e698bb9 --- /dev/null +++ b/cmd/cluster-client-gen/args/args.go @@ -0,0 +1,128 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "fmt" + + "github.com/spf13/pflag" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" +) + +type Args struct { + // The directory for the generated results. + OutputDir string + + // The Go import-path of the generated results. + OutputPkg string + + // The boilerplate header for Go files. + GoHeaderFile string + + // A sorted list of group versions to generate. For each of them the package path is found + // in GroupVersionToInputPath. + Groups []types.GroupVersions + + // Overrides for which types should be included in the client. + IncludedTypesOverrides map[types.GroupVersion][]string + + // ClientsetAPIPath is the default API HTTP path for generated clients. + ClientsetAPIPath string + // ClientsetOnly determines if we should generate the clients for groups and + // types along with the clientset. It's populated from command-line + // arguments. + ClientsetOnly bool + // FakeClient determines if client-gen generates the fake clients. + FakeClient bool + // PluralExceptions specify list of exceptions used when pluralizing certain types. + // For example 'Endpoints:Endpoints', otherwise the pluralizer will generate 'Endpointes'. + PluralExceptions []string + + // Path to the generated Kubernetes single-cluster clientset package. + SingleClusterClientPackage string + // Path to the generated Kubernetes single-cluster applyconfigurations package. + SingleClusterApplyConfigurationsPackage string +} + +func New() *Args { + return &Args{ + ClientsetAPIPath: "/apis", + ClientsetOnly: false, + FakeClient: true, + } +} + +func (args *Args) AddFlags(fs *pflag.FlagSet, inputBase string) { + gvsBuilder := NewGroupVersionsBuilder(&args.Groups) + fs.StringVar(&args.OutputDir, "output-dir", "", + "the base directory under which to generate results") + fs.StringVar(&args.OutputPkg, "output-pkg", args.OutputPkg, + "the Go import-path of the generated results") + fs.StringVar(&args.GoHeaderFile, "go-header-file", "", + "the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year") + fs.Var(NewGVPackagesValue(gvsBuilder, nil), "input", + `group/versions that client-gen will generate clients for. At most one version per group is allowed. Specified in the format "group1/version1,group2/version2...".`) + fs.Var(NewGVTypesValue(&args.IncludedTypesOverrides, []string{}), "included-types-overrides", + "list of group/version/type for which client should be generated. By default, client is generated for all types which have genclient in types.go. This overrides that. For each groupVersion in this list, only the types mentioned here will be included. The default check of genclient will be used for other group versions.") + fs.Var(NewInputBasePathValue(gvsBuilder, inputBase), "input-base", + "base path to look for the api group.") + fs.StringVarP(&args.ClientsetAPIPath, "clientset-api-path", "", args.ClientsetAPIPath, + "the value of default API HTTP path, starting with / and without trailing /.") + fs.BoolVar(&args.ClientsetOnly, "clientset-only", args.ClientsetOnly, + "when set, client-gen only generates the clientset shell, without generating the individual typed clients") + fs.BoolVar(&args.FakeClient, "fake-clientset", args.FakeClient, + "when set, client-gen will generate the fake clientset that can be used in tests") + fs.StringSliceVar(&args.PluralExceptions, "plural-exceptions", args.PluralExceptions, + "list of comma separated plural exception definitions in Type:PluralizedType form") + fs.StringVar(&args.SingleClusterClientPackage, "single-cluster-versioned-clientset-pkg", args.SingleClusterClientPackage, + "package path to the generated Kubernetes single-cluster clientset package") + fs.StringVar(&args.SingleClusterApplyConfigurationsPackage, "single-cluster-applyconfigurations-pkg", args.SingleClusterApplyConfigurationsPackage, + "package path to the generated Kubernetes single-cluster applyconfigurations package") +} + +func (args *Args) Validate() error { + if len(args.OutputDir) == 0 { + return fmt.Errorf("--output-dir must be specified") + } + if len(args.OutputPkg) == 0 { + return fmt.Errorf("--output-pkg must be specified") + } + if len(args.ClientsetAPIPath) == 0 { + return fmt.Errorf("--clientset-api-path cannot be empty") + } + if len(args.SingleClusterClientPackage) == 0 { + return fmt.Errorf("--single-cluster-versioned-clientset-pkg cannot be empty") + } + if len(args.SingleClusterApplyConfigurationsPackage) == 0 { + return fmt.Errorf("--single-cluster-applyconfigurations-pkg cannot be empty") + } + + return nil +} + +// GroupVersionPackages returns a map from GroupVersion to the package with the types.go. +func (args *Args) GroupVersionPackages() map[types.GroupVersion]string { + res := map[types.GroupVersion]string{} + for _, pkg := range args.Groups { + for _, v := range pkg.Versions { + res[types.GroupVersion{Group: pkg.Group, Version: v.Version}] = v.Package + } + } + return res +} diff --git a/cmd/cluster-client-gen/args/gvpackages.go b/cmd/cluster-client-gen/args/gvpackages.go new file mode 100644 index 000000000..16ffdf442 --- /dev/null +++ b/cmd/cluster-client-gen/args/gvpackages.go @@ -0,0 +1,178 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "bytes" + "encoding/csv" + "flag" + "path" + "sort" + "strings" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/util" + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" +) + +type inputBasePathValue struct { + builder *groupVersionsBuilder +} + +var _ flag.Value = &inputBasePathValue{} + +func NewInputBasePathValue(builder *groupVersionsBuilder, def string) *inputBasePathValue { + v := &inputBasePathValue{ + builder: builder, + } + if err := v.Set(def); err != nil { + panic(err) + } + return v +} + +func (s *inputBasePathValue) Set(val string) error { + s.builder.importBasePath = val + return s.builder.update() +} + +func (s *inputBasePathValue) Type() string { + return "string" +} + +func (s *inputBasePathValue) String() string { + return s.builder.importBasePath +} + +type gvPackagesValue struct { + builder *groupVersionsBuilder + groups []string + changed bool +} + +func NewGVPackagesValue(builder *groupVersionsBuilder, def []string) *gvPackagesValue { + gvp := new(gvPackagesValue) + gvp.builder = builder + if def != nil { + if err := gvp.set(def); err != nil { + panic(err) + } + } + return gvp +} + +var _ flag.Value = &gvPackagesValue{} + +func (s *gvPackagesValue) set(vs []string) error { + if s.changed { + s.groups = append(s.groups, vs...) + } else { + s.groups = append([]string(nil), vs...) + } + + s.builder.groups = s.groups + return s.builder.update() +} + +func (s *gvPackagesValue) Set(val string) error { + vs, err := readAsCSV(val) + if err != nil { + return err + } + if err := s.set(vs); err != nil { + return err + } + s.changed = true + return nil +} + +func (s *gvPackagesValue) Type() string { + return "stringSlice" +} + +func (s *gvPackagesValue) String() string { + str, _ := writeAsCSV(s.groups) + return "[" + str + "]" +} + +type groupVersionsBuilder struct { + value *[]types.GroupVersions + groups []string + importBasePath string +} + +func NewGroupVersionsBuilder(groups *[]types.GroupVersions) *groupVersionsBuilder { + return &groupVersionsBuilder{ + value: groups, + } +} + +func (p *groupVersionsBuilder) update() error { + var seenGroups = make(map[types.Group]*types.GroupVersions) + for _, v := range p.groups { + pth, gvString := util.ParsePathGroupVersion(v) + gv, err := types.ToGroupVersion(gvString) + if err != nil { + return err + } + + versionPkg := types.PackageVersion{Package: path.Join(p.importBasePath, pth, gv.Group.NonEmpty(), gv.Version.String()), Version: gv.Version} + if group, ok := seenGroups[gv.Group]; ok { + vers := group.Versions + vers = append(vers, versionPkg) + seenGroups[gv.Group].Versions = vers + } else { + seenGroups[gv.Group] = &types.GroupVersions{ + PackageName: gv.Group.NonEmpty(), + Group: gv.Group, + Versions: []types.PackageVersion{versionPkg}, + } + } + } + + groupNames := make([]string, 0, len(seenGroups)) + for groupName := range seenGroups { + groupNames = append(groupNames, groupName.String()) + } + sort.Strings(groupNames) + *p.value = []types.GroupVersions{} + for _, groupName := range groupNames { + *p.value = append(*p.value, *seenGroups[types.Group(groupName)]) + } + + return nil +} + +func readAsCSV(val string) ([]string, error) { + if val == "" { + return []string{}, nil + } + stringReader := strings.NewReader(val) + csvReader := csv.NewReader(stringReader) + return csvReader.Read() +} + +func writeAsCSV(vals []string) (string, error) { + b := &bytes.Buffer{} + w := csv.NewWriter(b) + err := w.Write(vals) + if err != nil { + return "", err + } + w.Flush() + return strings.TrimSuffix(b.String(), "\n"), nil +} diff --git a/cmd/cluster-client-gen/args/gvpackages_test.go b/cmd/cluster-client-gen/args/gvpackages_test.go new file mode 100644 index 000000000..d153fd0ba --- /dev/null +++ b/cmd/cluster-client-gen/args/gvpackages_test.go @@ -0,0 +1,117 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "fmt" + "reflect" + "strings" + "testing" + + "github.com/spf13/pflag" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" +) + +func TestGVPackageFlag(t *testing.T) { + tests := []struct { + args []string + def []string + importBasePath string + expected map[types.GroupVersion]string + expectedGroups []types.GroupVersions + parseError string + }{ + { + args: []string{}, + expected: map[types.GroupVersion]string{}, + expectedGroups: []types.GroupVersions{}, + }, + { + args: []string{"foo/bar/v1", "foo/bar/v2", "foo/bar/", "foo/v1"}, + expectedGroups: []types.GroupVersions{ + {PackageName: "bar", Group: types.Group("bar"), Versions: []types.PackageVersion{ + {Version: "v1", Package: "foo/bar/v1"}, + {Version: "v2", Package: "foo/bar/v2"}, + {Version: "", Package: "foo/bar"}, + }}, + {PackageName: "foo", Group: types.Group("foo"), Versions: []types.PackageVersion{ + {Version: "v1", Package: "foo/v1"}, + }}, + }, + }, + { + args: []string{"foo/bar/v1", "foo/bar/v2", "foo/bar/", "foo/v1"}, + def: []string{"foo/bar/v1alpha1", "foo/v1"}, + expectedGroups: []types.GroupVersions{ + {PackageName: "bar", Group: types.Group("bar"), Versions: []types.PackageVersion{ + {Version: "v1", Package: "foo/bar/v1"}, + {Version: "v2", Package: "foo/bar/v2"}, + {Version: "", Package: "foo/bar"}, + }}, + {PackageName: "foo", Group: types.Group("foo"), Versions: []types.PackageVersion{ + {Version: "v1", Package: "foo/v1"}, + }}, + }, + }, + { + args: []string{"api/v1", "api"}, + expectedGroups: []types.GroupVersions{ + {PackageName: "api", Group: types.Group("api"), Versions: []types.PackageVersion{ + {Version: "v1", Package: "api/v1"}, + {Version: "", Package: "api"}, + }}, + }, + }, + { + args: []string{"foo/v1"}, + importBasePath: "k8s.io/api", + expectedGroups: []types.GroupVersions{ + {PackageName: "foo", Group: types.Group("foo"), Versions: []types.PackageVersion{ + {Version: "v1", Package: "k8s.io/api/foo/v1"}, + }}, + }, + }, + } + for i, test := range tests { + fs := pflag.NewFlagSet("testGVPackage", pflag.ContinueOnError) + groups := []types.GroupVersions{} + builder := NewGroupVersionsBuilder(&groups) + fs.Var(NewGVPackagesValue(builder, test.def), "input", "usage") + fs.Var(NewInputBasePathValue(builder, test.importBasePath), "input-base-path", "usage") + + args := []string{} + for _, a := range test.args { + args = append(args, fmt.Sprintf("--input=%s", a)) + } + + err := fs.Parse(args) + if test.parseError != "" { + if err == nil { + t.Errorf("%d: expected error %q, got nil", i, test.parseError) + } else if !strings.Contains(err.Error(), test.parseError) { + t.Errorf("%d: expected error %q, got %q", i, test.parseError, err) + } + } else if err != nil { + t.Errorf("%d: expected nil error, got %v", i, err) + } + if !reflect.DeepEqual(groups, test.expectedGroups) { + t.Errorf("%d: expected groups %+v, got groups %+v", i, test.expectedGroups, groups) + } + } +} diff --git a/cmd/cluster-client-gen/args/gvtype.go b/cmd/cluster-client-gen/args/gvtype.go new file mode 100644 index 000000000..a96d4aeb6 --- /dev/null +++ b/cmd/cluster-client-gen/args/gvtype.go @@ -0,0 +1,111 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "flag" + "fmt" + "strings" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" +) + +type gvTypeValue struct { + gvToTypes *map[types.GroupVersion][]string + changed bool +} + +func NewGVTypesValue(gvToTypes *map[types.GroupVersion][]string, def []string) *gvTypeValue { //nolint:gocritic + gvt := new(gvTypeValue) + gvt.gvToTypes = gvToTypes + if def != nil { + if err := gvt.set(def); err != nil { + panic(err) + } + } + return gvt +} + +var _ flag.Value = &gvTypeValue{} + +func (s *gvTypeValue) set(vs []string) error { + if !s.changed { + *s.gvToTypes = map[types.GroupVersion][]string{} + } + + for _, input := range vs { + gvString, typeStr, err := parseGroupVersionType(input) + if err != nil { + return err + } + gv, err := types.ToGroupVersion(gvString) + if err != nil { + return err + } + types, ok := (*s.gvToTypes)[gv] + if !ok { + types = []string{} + } + types = append(types, typeStr) + (*s.gvToTypes)[gv] = types + } + + return nil +} + +func (s *gvTypeValue) Set(val string) error { + vs, err := readAsCSV(val) + if err != nil { + return err + } + if err := s.set(vs); err != nil { + return err + } + s.changed = true + return nil +} + +func (s *gvTypeValue) Type() string { + return "stringSlice" +} + +func (s *gvTypeValue) String() string { + strs := make([]string, 0, len(*s.gvToTypes)) + for gv, ts := range *s.gvToTypes { + for _, t := range ts { + strs = append(strs, gv.Group.String()+"/"+gv.Version.String()+"/"+t) + } + } + str, _ := writeAsCSV(strs) + return "[" + str + "]" +} + +func parseGroupVersionType(gvtString string) (gvString string, typeStr string, err error) { + invalidFormatErr := fmt.Errorf("invalid value: %s, should be of the form group/version/type", gvtString) + subs := strings.Split(gvtString, "/") + length := len(subs) + switch length { + case 2: + // gvtString of the form group/type, e.g. api/Service,extensions/ReplicaSet + return subs[0] + "/", subs[1], nil + case 3: + return strings.Join(subs[:length-1], "/"), subs[length-1], nil + default: + return "", "", invalidFormatErr + } +} diff --git a/cmd/cluster-client-gen/generators/client_generator.go b/cmd/cluster-client-gen/generators/client_generator.go new file mode 100644 index 000000000..718455d7f --- /dev/null +++ b/cmd/cluster-client-gen/generators/client_generator.go @@ -0,0 +1,441 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package generators has the generators for the client-gen utility. +package generators + +import ( + "fmt" + "path" + "path/filepath" + "strings" + + codegennamer "k8s.io/code-generator/pkg/namer" + "k8s.io/gengo/v2" + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + "k8s.io/klog/v2" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/args" + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/fake" + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/scheme" + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/util" + clientgentypes "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" + "github.com/kcp-dev/code-generator/v3/pkg/imports" +) + +// NameSystems returns the name system used by the generators in this package. +func NameSystems(pluralExceptions map[string]string) namer.NameSystems { + lowercaseNamer := namer.NewAllLowercasePluralNamer(pluralExceptions) + + publicNamer := &ExceptionNamer{ + Exceptions: map[string]string{ + // these exceptions are used to deconflict the generated code + // you can put your fully qualified package like + // to generate a name that doesn't conflict with your group. + // "k8s.io/apis/events/v1beta1.Event": "EventResource" + }, + KeyFunc: func(t *types.Type) string { + return t.Name.Package + "." + t.Name.Name + }, + Delegate: namer.NewPublicNamer(0), + } + privateNamer := &ExceptionNamer{ + Exceptions: map[string]string{ + // these exceptions are used to deconflict the generated code + // you can put your fully qualified package like + // to generate a name that doesn't conflict with your group. + // "k8s.io/apis/events/v1beta1.Event": "eventResource" + }, + KeyFunc: func(t *types.Type) string { + return t.Name.Package + "." + t.Name.Name + }, + Delegate: namer.NewPrivateNamer(0), + } + publicPluralNamer := &ExceptionNamer{ + Exceptions: map[string]string{ + // these exceptions are used to deconflict the generated code + // you can put your fully qualified package like + // to generate a name that doesn't conflict with your group. + // "k8s.io/apis/events/v1beta1.Event": "EventResource" + }, + KeyFunc: func(t *types.Type) string { + return t.Name.Package + "." + t.Name.Name + }, + Delegate: namer.NewPublicPluralNamer(pluralExceptions), + } + privatePluralNamer := &ExceptionNamer{ + Exceptions: map[string]string{ + // you can put your fully qualified package like + // to generate a name that doesn't conflict with your group. + // "k8s.io/apis/events/v1beta1.Event": "eventResource" + // these exceptions are used to deconflict the generated code + "k8s.io/apis/events/v1beta1.Event": "eventResources", + "k8s.io/kubernetes/pkg/apis/events.Event": "eventResources", + }, + KeyFunc: func(t *types.Type) string { + return t.Name.Package + "." + t.Name.Name + }, + Delegate: namer.NewPrivatePluralNamer(pluralExceptions), + } + + return namer.NameSystems{ + "singularKind": namer.NewPublicNamer(0), + "public": publicNamer, + "private": privateNamer, + "raw": namer.NewRawNamer("", nil), + "publicPlural": publicPluralNamer, + "privatePlural": privatePluralNamer, + "allLowercasePlural": lowercaseNamer, + "resource": codegennamer.NewTagOverrideNamer("resourceName", lowercaseNamer), + } +} + +// ExceptionNamer allows you specify exceptional cases with exact names. This allows you to have control +// for handling various conflicts, like group and resource names for instance. +type ExceptionNamer struct { + Exceptions map[string]string + KeyFunc func(*types.Type) string + + Delegate namer.Namer +} + +// Name provides the requested name for a type. +func (n *ExceptionNamer) Name(t *types.Type) string { + key := n.KeyFunc(t) + if exception, ok := n.Exceptions[key]; ok { + return exception + } + return n.Delegate.Name(t) +} + +// DefaultNameSystem returns the default name system for ordering the types to be +// processed by the generators in this package. +func DefaultNameSystem() string { + return "public" +} + +func targetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clientsetDir, clientsetPkg string, groupPkgName string, groupGoName string, apiPath string, inputPkg string, applyBuilderPkg string, singleClusterClientPkg string, boilerplate []byte) generator.Target { + subdir := []string{"typed", strings.ToLower(groupPkgName), strings.ToLower(gv.Version.NonEmpty())} + gvDir := filepath.Join(clientsetDir, filepath.Join(subdir...)) + gvPkg := path.Join(clientsetPkg, path.Join(subdir...)) + + return &generator.SimpleTarget{ + PkgName: strings.ToLower(gv.Version.NonEmpty()), + PkgPath: gvPkg, + PkgDir: gvDir, + HeaderComment: boilerplate, + PkgDocComment: []byte("// This package has the automatically generated typed clients.\n"), + // GeneratorsFunc returns a list of generators. Each generator makes a + // single file. + GeneratorsFunc: func(c *generator.Context) (generators []generator.Generator) { + generators = []generator.Generator{ + // Always generate a "doc.go" file. + generator.GoGenerator{OutputFilename: "doc.go"}, + } + // Since we want a file per type that we generate a client for, we + // have to provide a function for this. + for _, t := range typeList { + generators = append(generators, &genClientForType{ + GoGenerator: generator.GoGenerator{ + OutputFilename: strings.ToLower(c.Namers["private"].Name(t)) + ".go", + }, + outputPackage: gvPkg, + inputPackage: inputPkg, + clientsetPackage: clientsetPkg, + applyConfigurationPackage: applyBuilderPkg, + group: gv.Group.NonEmpty(), + version: gv.Version.String(), + groupGoName: groupGoName, + typeToMatch: t, + imports: imports.NewImportTrackerForPackage(gvPkg), + singleClusterClientPackage: singleClusterClientPkg, + }) + } + + generators = append(generators, &genGroup{ + GoGenerator: generator.GoGenerator{ + OutputFilename: groupPkgName + "_client.go", + }, + outputPackage: gvPkg, + inputPackage: inputPkg, + clientsetPackage: clientsetPkg, + group: gv.Group.NonEmpty(), + version: gv.Version.String(), + groupGoName: groupGoName, + apiPath: apiPath, + types: typeList, + imports: imports.NewImportTrackerForPackage(gvPkg), + singleClusterClientPkg: singleClusterClientPkg, + }) + + expansionFileName := "generated_expansion.go" + generators = append(generators, &genExpansion{ + groupPackagePath: gvDir, + GoGenerator: generator.GoGenerator{ + OutputFilename: expansionFileName, + }, + types: typeList, + }) + + return generators + }, + FilterFunc: func(c *generator.Context, t *types.Type) bool { + return util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient + }, + } +} + +func targetForClientset(args *args.Args, clientsetDir, clientsetPkg string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Target { + return &generator.SimpleTarget{ + PkgName: path.Base(clientsetPkg), + PkgPath: clientsetPkg, + PkgDir: clientsetDir, + HeaderComment: boilerplate, + // GeneratorsFunc returns a list of generators. Each generator generates a + // single file. + GeneratorsFunc: func(c *generator.Context) (generators []generator.Generator) { + generators = []generator.Generator{ + &genClientset{ + GoGenerator: generator.GoGenerator{ + OutputFilename: "clientset.go", + }, + groups: args.Groups, + groupGoNames: groupGoNames, + clientsetPackage: clientsetPkg, + imports: imports.NewImportTrackerForPackage(clientsetPkg), + singleClusterClientPkg: args.SingleClusterClientPackage, + }, + } + return generators + }, + } +} + +func targetForScheme(args *args.Args, clientsetDir, clientsetPkg string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Target { + schemeDir := filepath.Join(clientsetDir, "scheme") + schemePkg := path.Join(clientsetPkg, "scheme") + + // create runtime.Registry for internal client because it has to know about group versions + internalClient := false +NextGroup: + for _, group := range args.Groups { + for _, v := range group.Versions { + if v.String() == "" { + internalClient = true + break NextGroup + } + } + } + + return &generator.SimpleTarget{ + PkgName: "scheme", + PkgPath: schemePkg, + PkgDir: schemeDir, + HeaderComment: boilerplate, + PkgDocComment: []byte("// This package contains the scheme of the automatically generated clientset.\n"), + // GeneratorsFunc returns a list of generators. Each generator generates a + // single file. + GeneratorsFunc: func(c *generator.Context) (generators []generator.Generator) { + generators = []generator.Generator{ + // Always generate a "doc.go" file. + generator.GoGenerator{OutputFilename: "doc.go"}, + + &scheme.GenScheme{ + GoGenerator: generator.GoGenerator{ + OutputFilename: "register.go", + }, + InputPackages: args.GroupVersionPackages(), + OutputPkg: schemePkg, + OutputPath: schemeDir, + Groups: args.Groups, + GroupGoNames: groupGoNames, + ImportTracker: imports.NewImportTrackerForPackage(schemePkg), + CreateRegistry: internalClient, + }, + } + return generators + }, + } +} + +// applyGroupOverrides applies group name overrides to each package, if applicable. If there is a +// comment of the form "// +groupName=somegroup" or "// +groupName=somegroup.foo.bar.io", use the +// first field (somegroup) as the name of the group in Go code, e.g. as the func name in a clientset. +// +// If the first field of the groupName is not unique within the clientset, use "// +groupName=unique". +func applyGroupOverrides(universe types.Universe, args *args.Args) { + // Create a map from "old GV" to "new GV" so we know what changes we need to make. + changes := make(map[clientgentypes.GroupVersion]clientgentypes.GroupVersion) + for gv, inputDir := range args.GroupVersionPackages() { + p := universe.Package(inputDir) + if override := gengo.ExtractCommentTags("+", p.Comments)["groupName"]; override != nil { //nolint:staticcheck + newGV := clientgentypes.GroupVersion{ + Group: clientgentypes.Group(override[0]), + Version: gv.Version, + } + changes[gv] = newGV + } + } + + // Modify args.Groups based on the groupName overrides. + newGroups := make([]clientgentypes.GroupVersions, 0, len(args.Groups)) + for _, gvs := range args.Groups { + gv := clientgentypes.GroupVersion{ + Group: gvs.Group, + Version: gvs.Versions[0].Version, // we only need a version, and the first will do + } + if newGV, ok := changes[gv]; ok { + // There's an override, so use it. + newGVS := clientgentypes.GroupVersions{ + PackageName: gvs.PackageName, + Group: newGV.Group, + Versions: gvs.Versions, + } + newGroups = append(newGroups, newGVS) + } else { + // No override. + newGroups = append(newGroups, gvs) + } + } + args.Groups = newGroups +} + +// Because we try to assemble inputs from an input-base and a set of +// group-version arguments, sometimes that comes in as a filesystem path. This +// function rewrites them all as their canonical Go import-paths. +// +// TODO: Change this tool to just take inputs as Go "patterns" like every other +// gengo tool, then extract GVs from those. +func sanitizePackagePaths(context *generator.Context, args *args.Args) error { + for i := range args.Groups { + pkg := &args.Groups[i] + for j := range pkg.Versions { + ver := &pkg.Versions[j] + input := ver.Package + p := context.Universe[input] + if p == nil || p.Name == "" { + pkgs, err := context.FindPackages(input) + if err != nil { + return fmt.Errorf("can't find input package %q: %w", input, err) + } + p = context.Universe[pkgs[0]] + if p == nil { + return fmt.Errorf("can't find input package %q in universe", input) + } + ver.Package = p.Path + } + } + } + return nil +} + +// GetTargets makes the client target definition. +func GetTargets(context *generator.Context, args *args.Args) []generator.Target { + boilerplate, err := gengo.GoBoilerplate(args.GoHeaderFile, "", gengo.StdGeneratedBy) + if err != nil { + klog.Fatalf("Failed loading boilerplate: %v", err) + } + + includedTypesOverrides := args.IncludedTypesOverrides + + if err := sanitizePackagePaths(context, args); err != nil { + klog.Fatalf("cannot sanitize inputs: %v", err) + } + applyGroupOverrides(context.Universe, args) + + gvToTypes := map[clientgentypes.GroupVersion][]*types.Type{} + groupGoNames := make(map[clientgentypes.GroupVersion]string) + for gv, inputDir := range args.GroupVersionPackages() { + p := context.Universe.Package(inputDir) + + // If there's a comment of the form "// +groupGoName=SomeUniqueShortName", use that as + // the Go group identifier in CamelCase. It defaults + groupGoNames[gv] = namer.IC(strings.Split(gv.Group.NonEmpty(), ".")[0]) + if override := gengo.ExtractCommentTags("+", p.Comments)["groupGoName"]; override != nil { //nolint:staticcheck + groupGoNames[gv] = namer.IC(override[0]) + } + + for n, t := range p.Types { + // filter out types which are not included in user specified overrides. + typesOverride, ok := includedTypesOverrides[gv] + if ok { + found := false + for _, typeStr := range typesOverride { + if typeStr == n { + found = true + break + } + } + if !found { + continue + } + } else { + // User has not specified any override for this group version. + // filter out types which don't have genclient. + if tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)); !tags.GenerateClient { + continue + } + } + if _, found := gvToTypes[gv]; !found { + gvToTypes[gv] = []*types.Type{} + } + gvToTypes[gv] = append(gvToTypes[gv], t) + } + } + + clientsetDir := args.OutputDir + clientsetPkg := args.OutputPkg + + var targetList []generator.Target + + targetList = append(targetList, + targetForClientset(args, clientsetDir, clientsetPkg, groupGoNames, boilerplate), + targetForScheme(args, clientsetDir, clientsetPkg, groupGoNames, boilerplate)) + if args.FakeClient { + targetList = append(targetList, + fake.TargetForClientset(args, clientsetDir, clientsetPkg, args.SingleClusterClientPackage, args.SingleClusterApplyConfigurationsPackage, groupGoNames, boilerplate)) + } + + // If --clientset-only=true, we don't regenerate the individual typed clients. + if args.ClientsetOnly { + return targetList + } + + orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)} + gvPackages := args.GroupVersionPackages() + for _, group := range args.Groups { + for _, version := range group.Versions { + gv := clientgentypes.GroupVersion{Group: group.Group, Version: version.Version} + types := gvToTypes[gv] + inputPath := gvPackages[gv] + singleClusterClientPkg := path.Join(args.SingleClusterClientPackage, "typed", group.PackageName, version.String()) + targetList = append(targetList, + targetForGroup( + gv, orderer.OrderTypes(types), clientsetDir, clientsetPkg, + group.PackageName, groupGoNames[gv], args.ClientsetAPIPath, + inputPath, args.SingleClusterApplyConfigurationsPackage, singleClusterClientPkg, boilerplate)) + if args.FakeClient { + targetList = append(targetList, + fake.TargetForGroup(gv, orderer.OrderTypes(types), clientsetDir, clientsetPkg, group.PackageName, groupGoNames[gv], inputPath, args.SingleClusterApplyConfigurationsPackage, singleClusterClientPkg, boilerplate)) + } + } + } + + return targetList +} diff --git a/cmd/cluster-client-gen/generators/fake/fake_client_generator.go b/cmd/cluster-client-gen/generators/fake/fake_client_generator.go new file mode 100644 index 000000000..8f9212639 --- /dev/null +++ b/cmd/cluster-client-gen/generators/fake/fake_client_generator.go @@ -0,0 +1,137 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package fake + +import ( + "path" + "path/filepath" + "strings" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/types" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/args" + scheme "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/scheme" + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/util" + clientgentypes "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" + "github.com/kcp-dev/code-generator/v3/pkg/imports" +) + +func TargetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clientsetDir, clientsetPkg string, groupPkgName string, groupGoName string, inputPkg string, applyBuilderPackage string, singleClusterClientPkg string, boilerplate []byte) generator.Target { + // TODO: should make this a function, called by here and in client-generator.go + subdir := []string{"typed", strings.ToLower(groupPkgName), strings.ToLower(gv.Version.NonEmpty())} + outputDir := filepath.Join(clientsetDir, filepath.Join(subdir...), "fake") + outputPkg := path.Join(clientsetPkg, path.Join(subdir...), "fake") + realClientPkg := path.Join(clientsetPkg, path.Join(subdir...)) + + return &generator.SimpleTarget{ + PkgName: "fake", + PkgPath: outputPkg, + PkgDir: outputDir, + HeaderComment: boilerplate, + PkgDocComment: []byte("// Package fake has the automatically generated cluster clients.\n"), + // GeneratorsFunc returns a list of generators. Each generator makes a + // single file. + GeneratorsFunc: func(c *generator.Context) (generators []generator.Generator) { + generators = []generator.Generator{ + // Always generate a "doc.go" file. + generator.GoGenerator{OutputFilename: "doc.go"}, + } + // Since we want a file per type that we generate a client for, we + // have to provide a function for this. + for _, t := range typeList { + generators = append(generators, &genFakeForType{ + GoGenerator: generator.GoGenerator{ + OutputFilename: strings.ToLower(c.Namers["private"].Name(t)) + ".go", + }, + outputPackage: outputPkg, + realClientPackage: realClientPkg, + inputPackage: inputPkg, + version: gv.Version.String(), + groupGoName: groupGoName, + typeToMatch: t, + imports: imports.NewImportTrackerForPackage(outputPkg), + applyConfigurationPackage: applyBuilderPackage, + singleClusterClientPackage: singleClusterClientPkg, + }) + } + + generators = append(generators, &genFakeForGroup{ + GoGenerator: generator.GoGenerator{ + OutputFilename: groupPkgName + "_client.go", + }, + outputPackage: outputPkg, + realClientPackage: realClientPkg, + version: gv.Version.String(), + groupGoName: groupGoName, + types: typeList, + imports: imports.NewImportTrackerForPackage(outputPkg), + singleClusterClientPackage: singleClusterClientPkg, + }) + return generators + }, + FilterFunc: func(_ *generator.Context, t *types.Type) bool { + return util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient + }, + } +} + +func TargetForClientset(args *args.Args, clientsetDir, clientsetPkg string, singleClusterClientPkg string, applyConfigurationPkg string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Target { + return &generator.SimpleTarget{ + // TODO: we'll generate fake clientset for different release in the future. + // Package name and path are hard coded for now. + PkgName: "fake", + PkgPath: path.Join(clientsetPkg, "fake"), + PkgDir: filepath.Join(clientsetDir, "fake"), + HeaderComment: boilerplate, + PkgDocComment: []byte("// This package has the automatically generated fake clientset.\n"), + // GeneratorsFunc returns a list of generators. Each generator generates a + // single file. + GeneratorsFunc: func(_ *generator.Context) (generators []generator.Generator) { + generators = []generator.Generator{ + // Always generate a "doc.go" file. + generator.GoGenerator{OutputFilename: "doc.go"}, + + &genClientset{ + GoGenerator: generator.GoGenerator{ + OutputFilename: "clientset.go", + }, + groups: args.Groups, + groupGoNames: groupGoNames, + fakeClientsetPackage: clientsetPkg, + imports: imports.NewImportTrackerForPackage(clientsetPkg), + realClientsetPackage: clientsetPkg, + singleClusterClientPackage: singleClusterClientPkg, + applyConfigurationPackage: applyConfigurationPkg, + }, + &scheme.GenScheme{ + GoGenerator: generator.GoGenerator{ + OutputFilename: "register.go", + }, + InputPackages: args.GroupVersionPackages(), + OutputPkg: clientsetPkg, + Groups: args.Groups, + GroupGoNames: groupGoNames, + ImportTracker: imports.NewImportTrackerForPackage(clientsetPkg), + PrivateScheme: true, + }, + } + return generators + }, + } +} diff --git a/cmd/cluster-client-gen/generators/fake/generator_fake_for_clientset.go b/cmd/cluster-client-gen/generators/fake/generator_fake_for_clientset.go new file mode 100644 index 000000000..268a432be --- /dev/null +++ b/cmd/cluster-client-gen/generators/fake/generator_fake_for_clientset.go @@ -0,0 +1,253 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package fake + +import ( + "fmt" + "io" + "path" + "strings" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + + clientgentypes "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" +) + +// genClientset generates a package for a clientset. +type genClientset struct { + generator.GoGenerator + groups []clientgentypes.GroupVersions + groupGoNames map[clientgentypes.GroupVersion]string + fakeClientsetPackage string // must be a Go import-path + imports namer.ImportTracker + clientsetGenerated bool + // the import path of the generated real clientset. + realClientsetPackage string // must be a Go import-path + singleClusterClientPackage string + applyConfigurationPackage string +} + +var _ generator.Generator = &genClientset{} + +func (g *genClientset) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.fakeClientsetPackage, g.imports), + } +} + +// We only want to call GenerateType() once. +func (g *genClientset) Filter(_ *generator.Context, _ *types.Type) bool { + ret := !g.clientsetGenerated + g.clientsetGenerated = true + return ret +} + +func (g *genClientset) Imports(_ *generator.Context) (imports []string) { + imports = append(imports, g.imports.ImportLines()...) + for _, group := range g.groups { + for _, version := range group.Versions { + groupClientPackage := path.Join(g.fakeClientsetPackage, "typed", strings.ToLower(group.PackageName), strings.ToLower(version.NonEmpty())) + singleClusterGroupClientPackage := path.Join(g.singleClusterClientPackage, "typed", strings.ToLower(group.PackageName), strings.ToLower(version.NonEmpty())) + fakeGroupClientPackage := path.Join(groupClientPackage, "fake") + + groupAlias := strings.ToLower(g.groupGoNames[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}]) + imports = append(imports, fmt.Sprintf("%s%s %q", groupAlias, strings.ToLower(version.NonEmpty()), singleClusterGroupClientPackage), + fmt.Sprintf("kcp%s%s %q", groupAlias, strings.ToLower(version.NonEmpty()), groupClientPackage), + fmt.Sprintf("kcpfake%s%s %q", groupAlias, strings.ToLower(version.NonEmpty()), fakeGroupClientPackage)) + } + } + + // the package that has the clientset Interface and imports for the code in commonTemplate + imports = append(imports, + fmt.Sprintf("clientset %q", g.singleClusterClientPackage), + fmt.Sprintf("kcpclientset %q", g.realClientsetPackage), + fmt.Sprintf("kcpclientscheme %q", path.Join(g.realClientsetPackage, "scheme")), + + "github.com/kcp-dev/logicalcluster/v3", + "kcptesting \"github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing\"", + "kcpfakediscovery \"github.com/kcp-dev/client-go/third_party/k8s.io/client-go/discovery/fake\"", + "k8s.io/client-go/discovery", + "k8s.io/apimachinery/pkg/runtime", + ) + + return +} + +func (g *genClientset) GenerateType(c *generator.Context, _ *types.Type, w io.Writer) error { + generateApply := len(g.applyConfigurationPackage) > 0 + + // TODO: We actually don't need any type information to generate the clientset, + // perhaps we can adapt the go2ild framework to this kind of usage. + sw := generator.NewSnippetWriter(w, c, "$", "$") + + allGroups := clientgentypes.ToGroupVersionInfo(g.groups, g.groupGoNames) + + sw.Do(clusterCommon, nil) + + for _, group := range allGroups { + m := map[string]interface{}{ + "group": group.Group, + "version": group.Version, + "PackageAlias": group.PackageAlias, + "GroupGoName": group.GroupGoName, + "Version": namer.IC(group.Version.String()), + } + + sw.Do(clusterClientsetInterfaceImplTemplate, m) + } + + sw.Do(singleCommon, nil) + + if generateApply { + sw.Do(managedFieldsClientset, map[string]any{ + "newTypeConverter": types.Ref(g.applyConfigurationPackage, "NewTypeConverter"), + }) + } + + for _, group := range allGroups { + m := map[string]interface{}{ + "group": group.Group, + "version": group.Version, + "PackageAlias": group.PackageAlias, + "GroupGoName": group.GroupGoName, + "Version": namer.IC(group.Version.String()), + } + + sw.Do(clientsetInterfaceImplTemplate, m) + } + + return sw.Error() +} + +// This part of code is version-independent, unchanging. + +var managedFieldsClientset = ` +// NewClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewClientset(objects ...runtime.Object) *ClusterClientset { + o := kcptesting.NewFieldManagedObjectTracker( + kcpclientscheme.Scheme, + kcpclientscheme.Codecs.UniversalDecoder(), + $.newTypeConverter|raw$(kcpclientscheme.Scheme), + ) + o.AddAll(objects...) + + cs := &ClusterClientset{Fake: kcptesting.Fake{}, tracker: o} + cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: &cs.Fake, ClusterPath: logicalcluster.Wildcard} + cs.AddReactor("*", "*", kcptesting.ObjectReaction(o)) + cs.AddWatchReactor("*", kcptesting.WatchReaction(o)) + + return cs +} +` + +var clusterCommon = ` +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +// +// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves +// server side apply testing. NewClientset is only available when apply configurations are generated (e.g. +// via --with-applyconfig). +func NewSimpleClientset(objects ...runtime.Object) *ClusterClientset { + o := kcptesting.NewObjectTracker(kcpclientscheme.Scheme, kcpclientscheme.Codecs.UniversalDecoder()) + o.AddAll(objects...) + + cs := &ClusterClientset{Fake: kcptesting.Fake{}, tracker: o} + cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: &cs.Fake, ClusterPath: logicalcluster.Wildcard} + cs.AddReactor("*", "*", kcptesting.ObjectReaction(o)) + cs.AddWatchReactor("*", kcptesting.WatchReaction(o)) + + return cs +} + +// ClusterClientset contains the clients for groups. +type ClusterClientset struct { + kcptesting.Fake + discovery *kcpfakediscovery.FakeDiscovery + tracker kcptesting.ObjectTracker +} + +var _ kcpclientset.ClusterInterface = (*ClusterClientset)(nil) + +// Discovery retrieves the DiscoveryClient +func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *ClusterClientset) Tracker() kcptesting.ObjectTracker { + return c.tracker +} + +// Cluster scopes this clientset to one cluster. +func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) clientset.Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &Clientset{ + Fake: &c.Fake, + discovery: &kcpfakediscovery.FakeDiscovery{Fake: &c.Fake, ClusterPath: clusterPath}, + tracker: c.tracker.Cluster(clusterPath), + clusterPath: clusterPath, + } +} +` + +var clusterClientsetInterfaceImplTemplate = ` +// $.GroupGoName$$.Version$ retrieves the $.GroupGoName$$.Version$ClusterClient +func (c *ClusterClientset) $.GroupGoName$$.Version$() kcp$.PackageAlias$.$.GroupGoName$$.Version$ClusterInterface { + return &kcpfake$.PackageAlias$.$.GroupGoName$$.Version$ClusterClient{Fake: &c.Fake} +} +` + +var singleCommon = ` +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + *kcptesting.Fake + discovery *kcpfakediscovery.FakeDiscovery + tracker kcptesting.ScopedObjectTracker + clusterPath logicalcluster.Path +} + +var ( + _ clientset.Interface = &Clientset{} + _ kcptesting.FakeScopedClient = &Clientset{} +) + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { + return c.tracker +} +` + +var clientsetInterfaceImplTemplate = ` +// $.GroupGoName$$.Version$ retrieves the $.GroupGoName$$.Version$Client +func (c *Clientset) $.GroupGoName$$.Version$() $.PackageAlias$.$.GroupGoName$$.Version$Interface { + return &kcpfake$.PackageAlias$.$.GroupGoName$$.Version$Client{Fake: c.Fake, ClusterPath: c.clusterPath} +} +` diff --git a/cmd/cluster-client-gen/generators/fake/generator_fake_for_group.go b/cmd/cluster-client-gen/generators/fake/generator_fake_for_group.go new file mode 100644 index 000000000..a662d0ba8 --- /dev/null +++ b/cmd/cluster-client-gen/generators/fake/generator_fake_for_group.go @@ -0,0 +1,182 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package fake + +import ( + "fmt" + "io" + "path" + "strings" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/util" +) + +// genFakeForGroup produces a file for a group client, e.g. ExtensionsClient for the extension group. +type genFakeForGroup struct { + generator.GoGenerator + outputPackage string // must be a Go import-path + realClientPackage string // must be a Go import-path + version string + groupGoName string + // types in this group + types []*types.Type + imports namer.ImportTracker + // If the genGroup has been called. This generator should only execute once. + called bool + singleClusterClientPackage string +} + +var _ generator.Generator = &genFakeForGroup{} + +// We only want to call GenerateType() once per group. +func (g *genFakeForGroup) Filter(_ *generator.Context, _ *types.Type) bool { + if !g.called { + g.called = true + return true + } + return false +} + +func (g *genFakeForGroup) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.outputPackage, g.imports), + } +} + +func groupVersionFromPackage(pkg string) string { + version := path.Base(pkg) + group := path.Base(path.Dir(pkg)) + + return strings.ToLower(group + version) +} + +func (g *genFakeForGroup) Imports(_ *generator.Context) (imports []string) { + imports = g.imports.ImportLines() + if len(g.types) != 0 { + imports = append(imports, + "github.com/kcp-dev/logicalcluster/v3", + fmt.Sprintf("%s %q", groupVersionFromPackage(g.singleClusterClientPackage), g.singleClusterClientPackage), + fmt.Sprintf("kcp%s %q", groupVersionFromPackage(g.realClientPackage), g.realClientPackage), + ) + } + return imports +} + +func (g *genFakeForGroup) GenerateType(c *generator.Context, _ *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "$", "$") + gv := groupVersionFromPackage(g.realClientPackage) + + m := map[string]interface{}{ + "GroupGoName": g.groupGoName, + "Version": namer.IC(g.version), + "Fake": c.Universe.Type(types.Name{Package: "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing", Name: "Fake"}), + "RESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}), + "RESTClient": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "RESTClient"}), + "FakeClient": c.Universe.Type(types.Name{Package: "k8s.io/client-go/gentype", Name: "FakeClient"}), + "NewFakeClient": c.Universe.Function(types.Name{Package: "k8s.io/client-go/gentype", Name: "NewFakeClient"}), + "realClientPackage": gv, + "kcpClientPackage": "kcp" + gv, + } + + sw.Do(groupClusterClientTemplate, m) + for _, t := range g.types { + wrapper := map[string]interface{}{ + "type": t, + "GroupGoName": g.groupGoName, + "Version": namer.IC(g.version), + "realClientPackage": gv, + "kcpClientPackage": "kcp" + gv, + } + sw.Do(clusterGetterImpl, wrapper) + } + + sw.Do(groupClientTemplate, m) + for _, t := range g.types { + tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) + if err != nil { + return err + } + wrapper := map[string]interface{}{ + "type": t, + "GroupGoName": g.groupGoName, + "Version": namer.IC(g.version), + "realClientPackage": gv, + "kcpClientPackage": "kcp" + gv, + } + if tags.NonNamespaced { + sw.Do(getterImplNonNamespaced, wrapper) + continue + } + sw.Do(getterImplNamespaced, wrapper) + } + sw.Do(getRESTClient, m) + return sw.Error() +} + +var groupClusterClientTemplate = ` +var _ $.kcpClientPackage$.$.GroupGoName$$.Version$ClusterInterface = (*$.GroupGoName$$.Version$ClusterClient)(nil) + +type $.GroupGoName$$.Version$ClusterClient struct { + *$.Fake|raw$ +} + +func (c *$.GroupGoName$$.Version$ClusterClient) Cluster(clusterPath logicalcluster.Path) $.realClientPackage$.$.GroupGoName$$.Version$Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &$.GroupGoName$$.Version$Client{Fake: c.Fake, ClusterPath: clusterPath} +} +` + +var clusterGetterImpl = ` +func (c *$.GroupGoName$$.Version$ClusterClient) $.type|publicPlural$() $.kcpClientPackage$.$.type|public$ClusterInterface { + return newFake$.type|public$ClusterClient(c) +} +` + +var groupClientTemplate = ` +type $.GroupGoName$$.Version$Client struct { + *$.Fake|raw$ + ClusterPath logicalcluster.Path +} +` + +var getterImplNamespaced = ` +func (c *$.GroupGoName$$.Version$Client) $.type|publicPlural$(namespace string) $.realClientPackage$.$.type|public$Interface { + return newFake$.type|public$Client(c.Fake, namespace, c.ClusterPath) +} +` + +var getterImplNonNamespaced = ` +func (c *$.GroupGoName$$.Version$Client) $.type|publicPlural$() $.realClientPackage$.$.type|public$Interface { + return newFake$.type|public$Client(c.Fake, c.ClusterPath) +} +` + +var getRESTClient = ` +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *$.GroupGoName$$.Version$Client) RESTClient() $.RESTClientInterface|raw$ { + var ret *$.RESTClient|raw$ + return ret +} +` diff --git a/cmd/cluster-client-gen/generators/fake/generator_fake_for_type.go b/cmd/cluster-client-gen/generators/fake/generator_fake_for_type.go new file mode 100644 index 000000000..2d295a37d --- /dev/null +++ b/cmd/cluster-client-gen/generators/fake/generator_fake_for_type.go @@ -0,0 +1,681 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package fake + +import ( + "fmt" + "io" + "path" + "strings" + + "golang.org/x/text/cases" + "golang.org/x/text/language" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/util" +) + +// genFakeForType produces a file for each top-level type. +type genFakeForType struct { + generator.GoGenerator + outputPackage string // Must be a Go import-path + realClientPackage string // Must be a Go import-path + version string + groupGoName string + inputPackage string + typeToMatch *types.Type + imports namer.ImportTracker + applyConfigurationPackage string + singleClusterClientPackage string +} + +var _ generator.Generator = &genFakeForType{} + +var titler = cases.Title(language.Und) + +// Filter ignores all but one type because we're making a single file per type. +func (g *genFakeForType) Filter(_ *generator.Context, t *types.Type) bool { + return t == g.typeToMatch +} + +func (g *genFakeForType) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.outputPackage, g.imports), + } +} + +func (g *genFakeForType) Imports(_ *generator.Context) (imports []string) { + gvAlias := util.GroupVersionAliasFromPackage(g.realClientPackage) + + imports = append(imports, g.imports.ImportLines()...) + imports = append(imports, + `"github.com/kcp-dev/logicalcluster/v3"`, + `kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype"`, + `kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing"`, + fmt.Sprintf(`%s %q`, gvAlias, g.typeToMatch.Name.Package), + fmt.Sprintf(`typedkcp%s %q`, gvAlias, g.realClientPackage), + fmt.Sprintf(`typed%s %q`, gvAlias, g.singleClusterClientPackage), + ) + + return imports +} + +// GenerateType makes the body of a file implementing the individual typed client for type t. +func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "$", "$") + tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) + if err != nil { + return err + } + + publicName := c.Namers["public"].Name(t) + typedListName := publicName + "List" + + typedInterfaceName := publicName + "Interface" + typedInterfacePkg := g.singleClusterClientPackage + if !tags.NonNamespaced { + typedInterfaceName = publicName + "Namespacer" + typedInterfacePkg = g.realClientPackage + } + + // const pkgClientGoTesting = "k8s.io/client-go/testing" + const pkgClientGoTesting = "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + m := map[string]interface{}{ + "type": t, + "inputType": t, + "resultType": t, + "subresourcePath": "", + "namespaced": !tags.NonNamespaced, + "group": t.Name.Package, + "GroupGoName": g.groupGoName, + "Version": namer.IC(g.version), + "groupVersion": util.GroupVersionAliasFromPackage(g.realClientPackage), + "realClientInterface": c.Universe.Type(types.Name{Package: g.realClientPackage, Name: t.Name.Name + "Interface"}), + "SchemeGroupVersion": c.Universe.Type(types.Name{Package: t.Name.Package, Name: "SchemeGroupVersion"}), + "CreateOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "CreateOptions"}), + "DeleteOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "DeleteOptions"}), + "GetOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GetOptions"}), + "ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}), + "PatchOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "PatchOptions"}), + "ApplyOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ApplyOptions"}), + "UpdateOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "UpdateOptions"}), + "labelsEverything": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/labels", Name: "Everything"}), + "labelsSet": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/labels", Name: "Set"}), + "PatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "PatchType"}), + "ApplyPatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "ApplyPatchType"}), + "watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}), + "jsonMarshal": c.Universe.Type(types.Name{Package: "encoding/json", Name: "Marshal"}), + "fmtErrorf": c.Universe.Type(types.Name{Package: "fmt", Name: "Errorf"}), + "contextContext": c.Universe.Type(types.Name{Package: "context", Name: "Context"}), + + "NewRootListAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootListAction"}), + "NewListAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewListAction"}), + "NewRootGetAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootGetAction"}), + "NewGetAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewGetAction"}), + "NewRootDeleteActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteActionWithOptions"}), + "NewDeleteActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteActionWithOptions"}), + "NewRootUpdateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootUpdateAction"}), + "NewUpdateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewUpdateAction"}), + "NewRootCreateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootCreateAction"}), + "NewCreateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewCreateAction"}), + "NewRootWatchAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootWatchAction"}), + "NewWatchAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewWatchAction"}), + "NewCreateSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewCreateSubresourceAction"}), + "NewRootCreateSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootCreateSubresourceAction"}), + "NewUpdateSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewUpdateSubresourceAction"}), + "NewGetSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewGetSubresourceAction"}), + "NewRootGetSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootGetSubresourceAction"}), + "NewRootUpdateSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootUpdateSubresourceAction"}), + "NewRootPatchSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootPatchSubresourceAction"}), + "NewPatchSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewPatchSubresourceAction"}), + "ToPointerSlice": c.Universe.Type(types.Name{Package: "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype", Name: "ToPointerSlice"}), + "FromPointerSlice": c.Universe.Function(types.Name{Package: "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype", Name: "FromPointerSlice"}), + "FakeClient": c.Universe.Type(types.Name{Package: "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype", Name: "FakeClient"}), + "NewFakeClient": c.Universe.Function(types.Name{Package: "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype", Name: "NewFakeClient"}), + "FakeClientWithApply": c.Universe.Type(types.Name{Package: "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype", Name: "FakeClientWithApply"}), + "NewFakeClientWithApply": c.Universe.Function(types.Name{Package: "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype", Name: "NewFakeClientWithApply"}), + "FakeClientWithList": c.Universe.Type(types.Name{Package: "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype", Name: "FakeClientWithList"}), + "NewFakeClientWithList": c.Universe.Function(types.Name{Package: "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype", Name: "NewFakeClientWithList"}), + "FakeClientWithListAndApply": c.Universe.Type(types.Name{Package: "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype", Name: "FakeClientWithListAndApply"}), + "NewFakeClientWithListAndApply": c.Universe.Function(types.Name{Package: "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype", Name: "NewFakeClientWithListAndApply"}), + "typedInterfaceReference": c.Universe.Type(types.Name{Package: typedInterfacePkg, Name: typedInterfaceName}), + "typedTypeReference": c.Universe.Type(types.Name{Package: g.inputPackage, Name: publicName}), + "typedListTypeReference": c.Universe.Type(types.Name{Package: g.inputPackage, Name: typedListName}), + "inputSchemeKind": c.Universe.Type(types.Name{Package: g.inputPackage, Name: "Kind"}), + "inputSchemeResource": c.Universe.Type(types.Name{Package: g.inputPackage, Name: "Resource"}), + } + + generateApply := len(g.applyConfigurationPackage) > 0 + if generateApply { + // Generated apply builder type references required for generated Apply function + _, gvString := util.ParsePathGroupVersion(g.inputPackage) + m["inputApplyConfig"] = types.Ref(path.Join(g.applyConfigurationPackage, gvString), t.Name.Name+"ApplyConfiguration") + } + + listableOrAppliable := noList | noApply + var clusterListable bool + + if !tags.NoVerbs && tags.HasVerb("list") { + listableOrAppliable |= withList + clusterListable = true + } + + if !tags.NoVerbs && tags.HasVerb("apply") && generateApply { + listableOrAppliable |= withApply + } + + if clusterListable { + sw.Do(listableClusterClientType, m) + sw.Do(newListableClusterClient, m) + } else { + sw.Do(noVerbsClusterClientType, m) + sw.Do(newNoVerbsClusterClient, m) + } + + if tags.NonNamespaced { + sw.Do(rootClientScoper, m) + } else { + sw.Do(namespacedClientScoper, m) + } + + sw.Do(clientStructType[listableOrAppliable], m) + sw.Do(newClientStruct[listableOrAppliable], m) + + if tags.NoVerbs { + return sw.Error() + } + + _, typeGVString := util.ParsePathGroupVersion(g.inputPackage) + + // generate extended client methods + for _, e := range tags.Extensions { + if e.HasVerb("apply") && !generateApply { + continue + } + inputType := *t + resultType := *t + inputGVString := typeGVString + if len(e.InputTypeOverride) > 0 { + if name, pkg := e.Input(); len(pkg) > 0 { + _, inputGVString = util.ParsePathGroupVersion(pkg) + newType := c.Universe.Type(types.Name{Package: pkg, Name: name}) + inputType = *newType + } else { + inputType.Name.Name = e.InputTypeOverride + } + } + if len(e.ResultTypeOverride) > 0 { + if name, pkg := e.Result(); len(pkg) > 0 { + newType := c.Universe.Type(types.Name{Package: pkg, Name: name}) + resultType = *newType + } else { + resultType.Name.Name = e.ResultTypeOverride + } + } + m["inputType"] = &inputType + m["resultType"] = &resultType + m["subresourcePath"] = e.SubResourcePath + if e.HasVerb("apply") { + m["inputApplyConfig"] = types.Ref(path.Join(g.applyConfigurationPackage, inputGVString), inputType.Name.Name+"ApplyConfiguration") + } + + if e.HasVerb("get") { + if e.IsSubresource() { + sw.Do(adjustTemplate(e.VerbName, e.VerbType, getSubresourceTemplate), m) + } else { + sw.Do(adjustTemplate(e.VerbName, e.VerbType, getTemplate), m) + } + } + + if e.HasVerb("list") { + sw.Do(adjustTemplate(e.VerbName, e.VerbType, listTemplate), m) + } + + // TODO: Figure out schemantic for watching a sub-resource. + if e.HasVerb("watch") { + sw.Do(adjustTemplate(e.VerbName, e.VerbType, watchTemplate), m) + } + + if e.HasVerb("create") { + if e.IsSubresource() { + sw.Do(adjustTemplate(e.VerbName, e.VerbType, createSubresourceTemplate), m) + } else { + sw.Do(adjustTemplate(e.VerbName, e.VerbType, createTemplate), m) + } + } + + if e.HasVerb("update") { + if e.IsSubresource() { + sw.Do(adjustTemplate(e.VerbName, e.VerbType, updateSubresourceTemplate), m) + } else { + sw.Do(adjustTemplate(e.VerbName, e.VerbType, updateTemplate), m) + } + } + + // TODO: Figure out schemantic for deleting a sub-resource (what arguments + // are passed, does it need two names? etc. + if e.HasVerb("delete") { + sw.Do(adjustTemplate(e.VerbName, e.VerbType, deleteTemplate), m) + } + + if e.HasVerb("patch") { + sw.Do(adjustTemplate(e.VerbName, e.VerbType, patchTemplate), m) + } + + if e.HasVerb("apply") && generateApply { + if e.IsSubresource() { + sw.Do(adjustTemplate(e.VerbName, e.VerbType, applySubresourceTemplate), m) + } else { + sw.Do(adjustTemplate(e.VerbName, e.VerbType, applyTemplate), m) + } + } + } + + return sw.Error() +} + +// adjustTemplate adjust the origin verb template using the expansion name. +// TODO: Make the verbs in templates parametrized so the strings.Replace() is +// not needed. +func adjustTemplate(name, verbType, template string) string { + return strings.ReplaceAll(template, " "+titler.String(verbType), " "+name) +} + +// struct and constructor variants. +const ( + // The following values are bits in a bitmask. + // The values which can be set indicate list support and apply support; + // to make the declarations easier to read (like a truth table), corresponding zero-values + // are also declared. + noList = 0 + noApply = 0 + withList = 1 << iota + withApply +) + +// The following string slices are similar to maps, but with combinable keys used as indices. +// Each entry defines whether it supports lists and/or apply; each bit is then toggled: +// * noList, noApply: index 0; +// * withList, noApply: index 1; +// * noList, withApply: index 2; +// * withList, withApply: index 3. +// Go enforces index unicity in these kinds of declarations. + +// cluster struct declarations. +var listableClusterClientType = ` +// $.type|private$ClusterClient implements $.type|singularKind$ClusterInterface +type $.type|private$ClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*$.groupVersion$.$.type|singularKind$, *$.groupVersion$.$.type|singularKind$List] + Fake *kcptesting.Fake +} +` + +var noVerbsClusterClientType = ` +// $.type|private$ClusterClient implements $.type|singularKind$ClusterInterface +type $.type|private$ClusterClient struct { + *kcpgentype.FakeClusterClient[*$.groupVersion$.$.type|singularKind$] + Fake *kcptesting.Fake +} +` + +// Constructors for the cluster struct, in all variants. +var newListableClusterClient = ` +func newFake$.type|public$ClusterClient(fake *$.GroupGoName$$.Version$ClusterClient) typedkcp$.groupVersion$.$.type|singularKind$ClusterInterface { + return &$.type|private$ClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*$.groupVersion$.$.type|singularKind$, *$.groupVersion$.$.type|singularKind$List]( + fake.Fake, + $.groupVersion$.SchemeGroupVersion.WithResource("$.type|resource$"), + $.groupVersion$.SchemeGroupVersion.WithKind("$.type|singularKind$"), + func() *$.groupVersion$.$.type|singularKind$ { return &$.groupVersion$.$.type|singularKind${} }, + func() *$.groupVersion$.$.type|singularKind$List { return &$.groupVersion$.$.type|singularKind$List{} }, + func(dst, src *$.groupVersion$.$.type|singularKind$List) { dst.ListMeta = src.ListMeta }, + func(list *$.groupVersion$.$.type|singularKind$List) []*$.groupVersion$.$.type|singularKind$ { return $.ToPointerSlice|raw$(list.Items) }, + func(list *$.groupVersion$.$.type|singularKind$List, items []*$.groupVersion$.$.type|singularKind$) { list.Items = $.FromPointerSlice|raw$(items) }, + ), + fake.Fake, + } +} +` + +var newNoVerbsClusterClient = ` +func newFake$.type|public$ClusterClient(fake *$.GroupGoName$$.Version$ClusterClient) typedkcp$.groupVersion$.$.type|singularKind$ClusterInterface { + return &$.type|private$ClusterClient{ + kcpgentype.NewFakeClusterClient[*$.groupVersion$.$.type|singularKind$]( + fake.Fake, + $.groupVersion$.SchemeGroupVersion.WithResource("$.type|resource$"), + $.groupVersion$.SchemeGroupVersion.WithKind("$.type|singularKind$"), + func() *$.groupVersion$.$.type|singularKind$ { return &$.groupVersion$.$.type|singularKind${} }, + ), + fake.Fake, + } +} +` + +var rootClientScoper = ` +func (c *$.type|private$ClusterClient) Cluster(cluster logicalcluster.Path) typed$.groupVersion$.$.type|singularKind$Interface { + return newFake$.type|public$Client(c.Fake, cluster) +} +` + +var namespacedClientScoper = ` +func (c *$.type|private$ClusterClient) Cluster(cluster logicalcluster.Path) typedkcp$.groupVersion$.$.type|publicPlural$Namespacer { + return &$.type|private$Namespacer{Fake: c.Fake, ClusterPath: cluster} +} + +type $.type|private$Namespacer struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (n *$.type|private$Namespacer) Namespace(namespace string) typed$.groupVersion$.$.type|singularKind$Interface { + return newFake$.type|public$Client(n.Fake, namespace, n.ClusterPath) +} +` + +// scoped struct declarations. +var clientStructType = []string{ + noList | noApply: ` + // $.type|private$ScopedClient implements $.type|public$Interface + type $.type|private$ScopedClient struct { + *$.FakeClient|raw$[*$.groupVersion$.$.type|singularKind$] + Fake *kcptesting.Fake + ClusterPath logicalcluster.Path + } + `, + withList | noApply: ` + // $.type|private$ScopedClient implements $.type|public$Interface + type $.type|private$ScopedClient struct { + *$.FakeClientWithList|raw$[*$.groupVersion$.$.type|singularKind$, *$.groupVersion$.$.type|singularKind$List] + Fake *kcptesting.Fake + ClusterPath logicalcluster.Path + } + `, + noList | withApply: ` + // $.type|private$ScopedClient implements $.type|public$Interface + type $.type|private$ScopedClient struct { + *$.FakeClientWithApply|raw$[*$.groupVersion$.$.type|singularKind$, *$.inputApplyConfig|raw$] + Fake *kcptesting.Fake + ClusterPath logicalcluster.Path + } + `, + withList | withApply: ` + // $.type|private$ScopedClient implements $.type|public$Interface + type $.type|private$ScopedClient struct { + *$.FakeClientWithListAndApply|raw$[*$.groupVersion$.$.type|singularKind$, *$.groupVersion$.$.type|singularKind$List, *$.inputApplyConfig|raw$] + Fake *kcptesting.Fake + ClusterPath logicalcluster.Path + } + `, +} + +// Constructors for the scoped struct, in all variants. +var newClientStruct = []string{ + noList | noApply: ` + func newFake$.type|public$Client(fake *kcptesting.Fake$if .namespaced$, namespace string$end$, clusterPath logicalcluster.Path) typed$.groupVersion$.$.type|singularKind$Interface { + return &$.type|private$ScopedClient{ + $.NewFakeClient|raw$[*$.groupVersion$.$.type|singularKind$]( + fake, + clusterPath, + $if .namespaced$namespace$else$""$end$, + $.groupVersion$.SchemeGroupVersion.WithResource("$.type|resource$"), + $.groupVersion$.SchemeGroupVersion.WithKind("$.type|singularKind$"), + func() *$.groupVersion$.$.type|singularKind$ {return &$.groupVersion$.$.type|singularKind${}}, + ), + fake, + clusterPath, + } + } + `, + noList | withApply: ` + func newFake$.type|public$Client(fake *kcptesting.Fake$if .namespaced$, namespace string$end$, clusterPath logicalcluster.Path) typed$.groupVersion$.$.type|singularKind$Interface { + return &$.type|private$ScopedClient{ + $.NewFakeClientWithApply|raw$[*$.groupVersion$.$.type|singularKind$, *$.inputApplyConfig|raw$]( + fake, + clusterPath, + $if .namespaced$namespace$else$""$end$, + $.groupVersion$.SchemeGroupVersion.WithResource("$.type|resource$"), + $.groupVersion$.SchemeGroupVersion.WithKind("$.type|singularKind$"), + func() *$.groupVersion$.$.type|singularKind$ {return &$.groupVersion$.$.type|singularKind${}}, + ), + fake, + clusterPath, + } + } + `, + withList | noApply: ` + func newFake$.type|public$Client(fake *kcptesting.Fake$if .namespaced$, namespace string$end$, clusterPath logicalcluster.Path) typed$.groupVersion$.$.type|singularKind$Interface { + return &$.type|private$ScopedClient{ + $.NewFakeClientWithList|raw$[*$.groupVersion$.$.type|singularKind$, *$.groupVersion$.$.type|singularKind$List]( + fake, + clusterPath, + $if .namespaced$namespace$else$""$end$, + $.groupVersion$.SchemeGroupVersion.WithResource("$.type|resource$"), + $.groupVersion$.SchemeGroupVersion.WithKind("$.type|singularKind$"), + func() *$.groupVersion$.$.type|singularKind$ {return &$.groupVersion$.$.type|singularKind${}}, + func() *$.groupVersion$.$.type|singularKind$List {return &$.groupVersion$.$.type|singularKind$List{}}, + func(dst, src *$.groupVersion$.$.type|singularKind$List) {dst.ListMeta = src.ListMeta}, + func(list *$.groupVersion$.$.type|singularKind$List) []*$.groupVersion$.$.type|singularKind$ {return $.ToPointerSlice|raw$(list.Items)}, + func(list *$.groupVersion$.$.type|singularKind$List, items []*$.groupVersion$.$.type|singularKind$) {list.Items = $.FromPointerSlice|raw$(items)}, + ), + fake, + clusterPath, + } + } + `, + withList | withApply: ` + func newFake$.type|public$Client(fake *kcptesting.Fake$if .namespaced$, namespace string$end$, clusterPath logicalcluster.Path) typed$.groupVersion$.$.type|singularKind$Interface { + return &$.type|private$ScopedClient{ + $.NewFakeClientWithListAndApply|raw$[*$.groupVersion$.$.type|singularKind$, *$.groupVersion$.$.type|singularKind$List, *$.inputApplyConfig|raw$]( + fake, + clusterPath, + $if .namespaced$namespace$else$""$end$, + $.groupVersion$.SchemeGroupVersion.WithResource("$.type|resource$"), + $.groupVersion$.SchemeGroupVersion.WithKind("$.type|singularKind$"), + func() *$.groupVersion$.$.type|singularKind$ {return &$.groupVersion$.$.type|singularKind${}}, + func() *$.groupVersion$.$.type|singularKind$List {return &$.groupVersion$.$.type|singularKind$List{}}, + func(dst, src *$.groupVersion$.$.type|singularKind$List) {dst.ListMeta = src.ListMeta}, + func(list *$.groupVersion$.$.type|singularKind$List) []*$.groupVersion$.$.type|singularKind$ {return $.ToPointerSlice|raw$(list.Items)}, + func(list *$.groupVersion$.$.type|singularKind$List, items []*$.groupVersion$.$.type|singularKind$) {list.Items = $.FromPointerSlice|raw$(items)}, + ), + fake, + clusterPath, + } + } + `, +} + +var listTemplate = ` +// List takes label and field selectors, and returns the list of $.type|publicPlural$ that match those selectors. +func (c *$.type|private$ScopedClient) List(ctx $.contextContext|raw$, opts $.ListOptions|raw$) (result *$.type|raw$List, err error) { + emptyResult := &$.type|raw$List{} + obj, err := c.Fake. + $- if .namespaced$Invokes($.NewListAction|raw$(c.Resource(), c.ClusterPath, c.Kind(), c.Namespace(), opts), emptyResult) + $- else$Invokes($.NewRootListAction|raw$(c.Resource(), c.ClusterPath, c.Kind(), opts), emptyResult)$end$ + if obj == nil { + return emptyResult, err + } + return obj.(*$.type|raw$List), err +} +` + +var getTemplate = ` +// Get takes name of the $.type|private$, and returns the corresponding $.resultType|private$ object, and an error if there is any. +func (c *$.type|private$ScopedClient) Get(ctx $.contextContext|raw$, name string, _ $.GetOptions|raw$) (result *$.resultType|raw$, err error) { + emptyResult := &$.resultType|raw${} + obj, err := c.Fake. + $- if .namespaced$Invokes($.NewGetAction|raw$(c.Resource(), c.ClusterPath, c.Namespace(), name), emptyResult) + $- else$Invokes($.NewRootGetAction|raw$(c.Resource(), c.ClusterPath, name), emptyResult)$end$ + if obj == nil { + return emptyResult, err + } + return obj.(*$.resultType|raw$), err +} +` + +var getSubresourceTemplate = ` +// Get takes name of the $.type|private$, and returns the corresponding $.resultType|private$ object, and an error if there is any. +func (c *$.type|private$ScopedClient) Get(ctx $.contextContext|raw$, $.type|private$Name string, _ $.GetOptions|raw$) (result *$.resultType|raw$, err error) { + emptyResult := &$.resultType|raw${} + obj, err := c.Fake. + $- if .namespaced$Invokes($.NewGetSubresourceAction|raw$(c.Resource(), c.ClusterPath, c.Namespace(), "$.subresourcePath$", $.type|private$Name), emptyResult) + $- else$Invokes($.NewRootGetSubresourceAction|raw$(c.Resource(), c.ClusterPath, "$.subresourcePath$", $.type|private$Name), emptyResult)$end $ + if obj == nil { + return emptyResult, err + } + return obj.(*$.resultType|raw$), err +} +` + +var deleteTemplate = ` +// Delete takes name of the $.type|private$ and deletes it. Returns an error if one occurs. +func (c *$.type|private$ScopedClient) Delete(ctx $.contextContext|raw$, name string, opts $.DeleteOptions|raw$) error { + _, err := c.Fake. + $- if .namespaced$Invokes($.NewDeleteActionWithOptions|raw$(c.Resource(), c.ClusterPath, c.Namespace(), name, opts), &$.type|raw${}) + $- else$Invokes($.NewRootDeleteActionWithOptions|raw$(c.Resource(), c.ClusterPath, name, opts), &$.type|raw${})$end$ + return err +} +` + +var createTemplate = ` +// Create takes the representation of a $.inputType|private$ and creates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any. +func (c *$.type|private$ScopedClient) Create(ctx $.contextContext|raw$, $.inputType|private$ *$.inputType|raw$, _ $.CreateOptions|raw$) (result *$.resultType|raw$, err error) { + emptyResult := &$.resultType|raw${} + obj, err := c.Fake. + $- if .namespaced$Invokes($.NewCreateAction|raw$(c.Resource(), c.ClusterPath, c.Namespace(), $.inputType|private$), emptyResult) + $- else$Invokes($.NewRootCreateAction|raw$(c.Resource(), c.ClusterPath, $.inputType|private$), emptyResult)$end$ + if obj == nil { + return emptyResult, err + } + return obj.(*$.resultType|raw$), err +} +` + +var createSubresourceTemplate = ` +// Create takes the representation of a $.inputType|private$ and creates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any. +func (c *$.type|private$ScopedClient) Create(ctx $.contextContext|raw$, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, _ $.CreateOptions|raw$) (result *$.resultType|raw$, err error) { + emptyResult := &$.resultType|raw${} + obj, err := c.Fake. + $- if .namespaced$Invokes($.NewCreateSubresourceAction|raw$(c.Resource(), c.ClusterPath, $.type|private$Name, "$.subresourcePath$", c.Namespace(), $.inputType|private$), emptyResult) + $- else$Invokes($.NewRootCreateSubresourceAction|raw$(c.Resource(), c.ClusterPath, $.type|private$Name, "$.subresourcePath$", $.inputType|private$), emptyResult)$end$ + if obj == nil { + return emptyResult, err + } + return obj.(*$.resultType|raw$), err +} +` + +var updateTemplate = ` +// Update takes the representation of a $.inputType|private$ and updates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any. +func (c *$.type|private$ScopedClient) Update(ctx $.contextContext|raw$, $.inputType|private$ *$.inputType|raw$, _ $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) { + emptyResult := &$.resultType|raw${} + obj, err := c.Fake. + $- if .namespaced$Invokes($.NewUpdateAction|raw$(c.Resource(), c.ClusterPath, c.Namespace(), $.inputType|private$), emptyResult) + $- else$Invokes($.NewRootUpdateAction|raw$(c.Resource(), c.ClusterPath, $.inputType|private$), emptyResult)$end$ + if obj == nil { + return emptyResult, err + } + return obj.(*$.resultType|raw$), err +} +` + +var updateSubresourceTemplate = ` +// Update takes the representation of a $.inputType|private$ and updates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any. +func (c *$.type|private$ScopedClient) Update(ctx $.contextContext|raw$, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, _ $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) { + emptyResult := &$.resultType|raw${} + obj, err := c.Fake. + $- if .namespaced$Invokes($.NewUpdateSubresourceAction|raw$(c.Resource(), c.ClusterPath, "$.subresourcePath$", c.Namespace(), $.inputType|private$), &$.inputType|raw${}) + $- else$Invokes($.NewRootUpdateSubresourceAction|raw$(c.Resource(), c.ClusterPath, "$.subresourcePath$", $.inputType|private$), emptyResult)$end$ + if obj == nil { + return emptyResult, err + } + return obj.(*$.resultType|raw$), err +} +` + +var watchTemplate = ` +// Watch returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$. +func (c *$.type|private$ScopedClient) Watch(ctx $.contextContext|raw$, opts $.ListOptions|raw$) ($.watchInterface|raw$, error) { + return c.Fake. + $- if .namespaced$InvokesWatch($.NewWatchAction|raw$(c.Resource(), c.ClusterPath, c.Namespace(), opts)) + $- else$InvokesWatch($.NewRootWatchAction|raw$(c.Resource(), c.ClusterPath, opts))$end$ +} +` + +var patchTemplate = ` +// Patch applies the patch and returns the patched $.resultType|private$. +func (c *$.type|private$ScopedClient) Patch(ctx $.contextContext|raw$, name string, pt $.PatchType|raw$, data []byte, _ $.PatchOptions|raw$, subresources ...string) (result *$.resultType|raw$, err error) { + emptyResult := &$.resultType|raw${} + obj, err := c.Fake. + $- if .namespaced$Invokes($.NewPatchSubresourceAction|raw$(c.Resource(), c.ClusterPath, c.Namespace(), name, pt, data, subresources... ), emptyResult) + $- else$Invokes($.NewRootPatchSubresourceAction|raw$(c.Resource(), c.ClusterPath, name, pt, data, subresources...), emptyResult)$end$ + if obj == nil { + return emptyResult, err + } + return obj.(*$.resultType|raw$), err +} +` + +var applyTemplate = ` +// Apply takes the given apply declarative configuration, applies it and returns the applied $.resultType|private$. +func (c *$.type|private$ScopedClient) Apply(ctx $.contextContext|raw$, $.inputType|private$ *$.inputApplyConfig|raw$, _ $.ApplyOptions|raw$) (result *$.resultType|raw$, err error) { + if $.inputType|private$ == nil { + return nil, $.fmtErrorf|raw$("$.inputType|private$ provided to Apply must not be nil") + } + data, err := $.jsonMarshal|raw$($.inputType|private$) + if err != nil { + return nil, err + } + name := $.inputType|private$.Name + if name == nil { + return nil, $.fmtErrorf|raw$("$.inputType|private$.Name must be provided to Apply") + } + emptyResult := &$.resultType|raw${} + obj, err := c.Fake. + $- if .namespaced$Invokes($.NewPatchSubresourceAction|raw$(c.Resource(), c.ClusterPath, c.Namespace(), *name, $.ApplyPatchType|raw$, data), emptyResult) + $- else$Invokes($.NewRootPatchSubresourceAction|raw$(c.Resource(), c.ClusterPath, *name, $.ApplyPatchType|raw$, data), emptyResult)$end$ + if obj == nil { + return emptyResult, err + } + return obj.(*$.resultType|raw$), err +} +` + +var applySubresourceTemplate = ` +// Apply takes top resource name and the apply declarative configuration for $.subresourcePath$, +// applies it and returns the applied $.resultType|private$, and an error, if there is any. +func (c *$.type|private$ScopedClient) Apply(ctx $.contextContext|raw$, $.type|private$Name string, $.inputType|private$ *$.inputApplyConfig|raw$, _ $.ApplyOptions|raw$) (result *$.resultType|raw$, err error) { + if $.inputType|private$ == nil { + return nil, $.fmtErrorf|raw$("$.inputType|private$ provided to Apply must not be nil") + } + data, err := $.jsonMarshal|raw$($.inputType|private$) + if err != nil { + return nil, err + } + emptyResult := &$.resultType|raw${} + obj, err := c.Fake. + $- if .namespaced$Invokes($.NewPatchSubresourceAction|raw$(c.Resource(), c.ClusterPath, c.Namespace(), $.type|private$Name, $.ApplyPatchType|raw$, data, "$.inputType|private$"), emptyResult) + $- else$Invokes($.NewRootPatchSubresourceAction|raw$(c.Resource(), c.ClusterPath, $.type|private$Name, $.ApplyPatchType|raw$, data, "$.inputType|private$"), emptyResult)$end$ + if obj == nil { + return emptyResult, err + } + return obj.(*$.resultType|raw$), err +} +` diff --git a/cmd/cluster-client-gen/generators/generator_for_clientset.go b/cmd/cluster-client-gen/generators/generator_for_clientset.go new file mode 100644 index 000000000..11fd6dfb4 --- /dev/null +++ b/cmd/cluster-client-gen/generators/generator_for_clientset.go @@ -0,0 +1,239 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "fmt" + "io" + "path" + "strings" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + + clientgentypes "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" +) + +// genClientset generates a package for a clientset. +type genClientset struct { + generator.GoGenerator + groups []clientgentypes.GroupVersions + groupGoNames map[clientgentypes.GroupVersion]string + clientsetPackage string // must be a Go import-path + imports namer.ImportTracker + clientsetGenerated bool + singleClusterClientPkg string +} + +var _ generator.Generator = &genClientset{} + +func (g *genClientset) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.clientsetPackage, g.imports), + } +} + +// We only want to call GenerateType() once. +func (g *genClientset) Filter(_ *generator.Context, _ *types.Type) bool { + ret := !g.clientsetGenerated + g.clientsetGenerated = true + return ret +} + +func (g *genClientset) Imports(c *generator.Context) (imports []string) { + imports = append(imports, g.imports.ImportLines()...) + imports = append(imports, + fmt.Sprintf("client %q", g.singleClusterClientPkg), + "github.com/kcp-dev/logicalcluster/v3", + ) + for _, group := range g.groups { + for _, version := range group.Versions { + typedClientPath := path.Join(g.clientsetPackage, "typed", strings.ToLower(group.PackageName), strings.ToLower(version.NonEmpty())) + groupAlias := strings.ToLower(g.groupGoNames[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}]) + imports = append(imports, fmt.Sprintf("%s%s %q", groupAlias, strings.ToLower(version.NonEmpty()), typedClientPath)) + } + } + return +} + +func (g *genClientset) GenerateType(c *generator.Context, _ *types.Type, w io.Writer) error { + // TODO: We actually don't need any type information to generate the clientset, + // perhaps we can adapt the go2ild framework to this kind of usage. + sw := generator.NewSnippetWriter(w, c, "$", "$") + + allGroups := clientgentypes.ToGroupVersionInfo(g.groups, g.groupGoNames) + m := map[string]any{ + "allGroups": allGroups, + "fmtErrorf": c.Universe.Type(types.Name{Package: "fmt", Name: "Errorf"}), + "Config": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Config"}), + "DefaultKubernetesUserAgent": c.Universe.Function(types.Name{Package: "k8s.io/client-go/rest", Name: "DefaultKubernetesUserAgent"}), + "RESTConfig": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Config"}), + "RESTHTTPClientFor": c.Universe.Function(types.Name{Package: "k8s.io/client-go/rest", Name: "HTTPClientFor"}), + "DiscoveryInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/discovery", Name: "DiscoveryInterface"}), + "DiscoveryClient": c.Universe.Type(types.Name{Package: "k8s.io/client-go/discovery", Name: "DiscoveryClient"}), + "httpClient": c.Universe.Type(types.Name{Package: "net/http", Name: "Client"}), + "NewDiscoveryClientForConfigAndClient": c.Universe.Function(types.Name{Package: "k8s.io/client-go/discovery", Name: "NewDiscoveryClientForConfigAndClient"}), + "NewDiscoveryClientForConfigOrDie": c.Universe.Function(types.Name{Package: "k8s.io/client-go/discovery", Name: "NewDiscoveryClientForConfigOrDie"}), + "flowcontrolNewTokenBucketRateLimiter": c.Universe.Function(types.Name{Package: "k8s.io/client-go/util/flowcontrol", Name: "NewTokenBucketRateLimiter"}), + "kcpclientCache": c.Universe.Type(types.Name{Package: "github.com/kcp-dev/apimachinery/v2/pkg/client", Name: "Cache"}), + } + + sw.Do(clientsetInterface, m) + sw.Do(clientsetTemplate, m) + sw.Do(getDiscoveryTemplate, m) + for _, g := range allGroups { + sw.Do(clientsetInterfaceImplTemplate, g) + } + sw.Do(getClusterTemplate, m) + sw.Do(newClientsetForConfigTemplate, m) + sw.Do(newClientsetForConfigAndClientTemplate, m) + sw.Do(newClientsetForConfigOrDieTemplate, m) + sw.Do(newClientsetForRESTClientTemplate, m) + + return sw.Error() +} + +var clientsetInterface = ` +type ClusterInterface interface { + Cluster(logicalcluster.Path) client.Interface + Discovery() $.DiscoveryInterface|raw$ + $range .allGroups$$.GroupGoName$$.Version$() $.PackageAlias$.$.GroupGoName$$.Version$ClusterInterface + $end$ +} +` + +var clientsetTemplate = ` +// ClusterClientset contains the cluster clients for groups. +type ClusterClientset struct { + *$.DiscoveryClient|raw$ + clientCache $.kcpclientCache|raw$[*client.Clientset] + $range .allGroups$$.LowerCaseGroupGoName$$.Version$ *$.PackageAlias$.$.GroupGoName$$.Version$ClusterClient + $end$ +} +` + +var clientsetInterfaceImplTemplate = ` +// $.GroupGoName$$.Version$ retrieves the $.GroupGoName$$.Version$ClusterClient. +func (c *ClusterClientset) $.GroupGoName$$.Version$() $.PackageAlias$.$.GroupGoName$$.Version$ClusterInterface { + return c.$.LowerCaseGroupGoName$$.Version$ +} +` + +var getDiscoveryTemplate = ` +// Discovery retrieves the DiscoveryClient. +func (c *ClusterClientset) Discovery() $.DiscoveryInterface|raw$ { + if c == nil { + return nil + } + return c.DiscoveryClient +} +` + +var getClusterTemplate = ` +// Cluster scopes this clientset to one cluster. +func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} +` + +var newClientsetForConfigTemplate = ` +// NewForConfig creates a new ClusterClientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *$.Config|raw$) (*ClusterClientset, error) { + configShallowCopy := *c + + if configShallowCopy.UserAgent == "" { + configShallowCopy.UserAgent = $.DefaultKubernetesUserAgent|raw$() + } + + // share the transport between all clients + httpClient, err := $.RESTHTTPClientFor|raw$(&configShallowCopy) + if err != nil { + return nil, err + } + + return NewForConfigAndClient(&configShallowCopy, httpClient) +} +` + +var newClientsetForConfigAndClientTemplate = ` +// NewForConfigAndClient creates a new ClusterClientset for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfigAndClient will generate a rate-limiter in configShallowCopy. +func NewForConfigAndClient(c *$.Config|raw$, httpClient *$.httpClient|raw$) (*ClusterClientset, error) { + configShallowCopy := *c + if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, $.fmtErrorf|raw$("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } + configShallowCopy.RateLimiter = $.flowcontrolNewTokenBucketRateLimiter|raw$(configShallowCopy.QPS, configShallowCopy.Burst) + } + + cache := kcpclient.NewCache(c, httpClient, &kcpclient.Constructor[*client.Clientset]{ + NewForConfigAndClient: client.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + + var cs ClusterClientset + cs.clientCache = cache + var err error +$range .allGroups$ cs.$.LowerCaseGroupGoName$$.Version$, err =$.PackageAlias$.NewForConfigAndClient(&configShallowCopy, httpClient) + if err!=nil { + return nil, err + } +$end$ + cs.DiscoveryClient, err = $.NewDiscoveryClientForConfigAndClient|raw$(&configShallowCopy, httpClient) + if err!=nil { + return nil, err + } + return &cs, nil +} +` + +var newClientsetForConfigOrDieTemplate = ` +// NewForConfigOrDie creates a new ClusterClientset for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *$.Config|raw$) *ClusterClientset { + cs, err := NewForConfig(c) + if err!=nil { + panic(err) + } + return cs +} +` + +var newClientsetForRESTClientTemplate = ` +// New creates a new ClusterClientset for the given RESTClient. +func New(c *$.RESTConfig|raw$) *ClusterClientset { + var cs ClusterClientset +$range .allGroups$ cs.$.LowerCaseGroupGoName$$.Version$ = $.PackageAlias$.NewForConfigOrDie(c) +$end$ + cs.DiscoveryClient = $.NewDiscoveryClientForConfigOrDie|raw$(c) + return &cs +} +` diff --git a/cmd/cluster-client-gen/generators/generator_for_expansion.go b/cmd/cluster-client-gen/generators/generator_for_expansion.go new file mode 100644 index 000000000..d08aad94d --- /dev/null +++ b/cmd/cluster-client-gen/generators/generator_for_expansion.go @@ -0,0 +1,55 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "io" + "os" + "path/filepath" + "strings" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/types" +) + +// genExpansion produces a file for a group client, e.g. ExtensionsClient for the extension group. +type genExpansion struct { + generator.GoGenerator + groupPackagePath string + // types in a group + types []*types.Type +} + +// We only want to call GenerateType() once per group. +func (g *genExpansion) Filter(_ *generator.Context, t *types.Type) bool { + return len(g.types) == 0 || t == g.types[0] +} + +func (g *genExpansion) GenerateType(c *generator.Context, _ *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "$", "$") + for _, t := range g.types { + if _, err := os.Stat(filepath.Join(g.groupPackagePath, strings.ToLower(t.Name.Name+"_expansion.go"))); os.IsNotExist(err) { + sw.Do(expansionInterfaceTemplate, t) + } + } + return sw.Error() +} + +var expansionInterfaceTemplate = ` +type $.|public$ClusterExpansion interface {} +` diff --git a/cmd/cluster-client-gen/generators/generator_for_group.go b/cmd/cluster-client-gen/generators/generator_for_group.go new file mode 100644 index 000000000..43fd81148 --- /dev/null +++ b/cmd/cluster-client-gen/generators/generator_for_group.go @@ -0,0 +1,249 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "io" + "path" + + "k8s.io/gengo/v2" + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" +) + +// genGroup produces a file for a group client, e.g. ExtensionsClient for the extension group. +type genGroup struct { + generator.GoGenerator + outputPackage string + group string + version string + groupGoName string + apiPath string + // types in this group + types []*types.Type + imports namer.ImportTracker + inputPackage string + clientsetPackage string // must be a Go import-path + singleClusterClientPkg string + // If the genGroup has been called. This generator should only execute once. + called bool +} + +var _ generator.Generator = &genGroup{} + +// We only want to call GenerateType() once per group. +func (g *genGroup) Filter(_ *generator.Context, _ *types.Type) bool { + if !g.called { + g.called = true + return true + } + return false +} + +func (g *genGroup) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.outputPackage, g.imports), + } +} + +func (g *genGroup) Imports(_ *generator.Context) (imports []string) { + imports = append(imports, g.imports.ImportLines()...) + imports = append(imports, + "github.com/kcp-dev/logicalcluster/v3", + ) + return imports +} + +func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "$", "$") + + // allow user to define a group name that's different from the one parsed from the directory. + p := c.Universe.Package(g.inputPackage) + groupName := g.group + if override := gengo.ExtractCommentTags("+", p.Comments)["groupName"]; override != nil { //nolint:staticcheck + groupName = override[0] + } + + apiPath := `"` + g.apiPath + `"` + if groupName == "" { + apiPath = `"/api"` + } + schemePackage := path.Join(g.clientsetPackage, "scheme") + typedClientName := g.groupGoName + namer.IC(g.version) + "Client" + typedInterfaceName := g.groupGoName + namer.IC(g.version) + "Interface" + + m := map[string]interface{}{ + "version": g.version, + "groupName": groupName, + "GroupGoName": g.groupGoName, + "Version": namer.IC(g.version), + "types": g.types, + "apiPath": apiPath, + "httpClient": c.Universe.Type(types.Name{Package: "net/http", Name: "Client"}), + "schemaGroupVersion": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersion"}), + "runtimeAPIVersionInternal": c.Universe.Variable(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "APIVersionInternal"}), + "restConfig": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Config"}), + "restDefaultKubernetesUserAgent": c.Universe.Function(types.Name{Package: "k8s.io/client-go/rest", Name: "DefaultKubernetesUserAgent"}), + "restRESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}), + "RESTHTTPClientFor": c.Universe.Function(types.Name{Package: "k8s.io/client-go/rest", Name: "HTTPClientFor"}), + "restRESTClientFor": c.Universe.Function(types.Name{Package: "k8s.io/client-go/rest", Name: "RESTClientFor"}), + "restRESTClientForConfigAndClient": c.Universe.Function(types.Name{Package: "k8s.io/client-go/rest", Name: "RESTClientForConfigAndClient"}), + "restCodecFactoryForGeneratedClient": c.Universe.Function(types.Name{Package: "k8s.io/client-go/rest", Name: "CodecFactoryForGeneratedClient"}), + "SchemeGroupVersion": c.Universe.Variable(types.Name{Package: g.inputPackage, Name: "SchemeGroupVersion"}), + "SchemePrioritizedVersionsForGroup": c.Universe.Variable(types.Name{Package: schemePackage, Name: "Scheme.PrioritizedVersionsForGroup"}), + "Codecs": c.Universe.Variable(types.Name{Package: schemePackage, Name: "Codecs"}), + "Scheme": c.Universe.Variable(types.Name{Package: schemePackage, Name: "Scheme"}), + "kcpNewCache": c.Universe.Function(types.Name{Package: "github.com/kcp-dev/apimachinery/v2/pkg/client", Name: "NewCache"}), + "kcpClientConstructor": c.Universe.Type(types.Name{Package: "github.com/kcp-dev/apimachinery/v2/pkg/client", Name: "Constructor"}), + "typedClientReference": c.Universe.Type(types.Name{Package: g.singleClusterClientPkg, Name: typedClientName}), + "typedInterfaceReference": c.Universe.Type(types.Name{Package: g.singleClusterClientPkg, Name: typedInterfaceName}), + "NewForConfigAndClient": c.Universe.Type(types.Name{Package: g.singleClusterClientPkg, Name: "NewForConfigAndClient"}), + } + sw.Do(groupInterfaceTemplate, m) + sw.Do(clusterScoperTemplate, m) + sw.Do(groupClientTemplate, m) + for _, t := range g.types { + wrapper := map[string]interface{}{ + "type": t, + "GroupGoName": g.groupGoName, + "Version": namer.IC(g.version), + } + sw.Do(getterImpl, wrapper) + } + sw.Do(newClientForConfigTemplate, m) + sw.Do(newClientForConfigAndClientTemplate, m) + sw.Do(newClientForConfigOrDieTemplate, m) + if g.version == "" { + sw.Do(setInternalVersionClientDefaultsTemplate, m) + } else { + sw.Do(setClientDefaultsTemplate, m) + } + + return sw.Error() +} + +var groupInterfaceTemplate = ` +type $.GroupGoName$$.Version$ClusterInterface interface { + $.GroupGoName$$.Version$ClusterScoper + $range .types$ $.|publicPlural$ClusterGetter + $end$ +} +` + +var clusterScoperTemplate = ` +type $.GroupGoName$$.Version$ClusterScoper interface { + Cluster(logicalcluster.Path) $.typedInterfaceReference|raw$ +} +` + +var groupClientTemplate = ` +// $.GroupGoName$$.Version$ClusterClient is used to interact with features provided by the $.groupName$ group. +type $.GroupGoName$$.Version$ClusterClient struct { + clientCache kcpclient.Cache[*$.typedClientReference|raw$] +} + +func (c *$.GroupGoName$$.Version$ClusterClient) Cluster(clusterPath logicalcluster.Path) $.typedInterfaceReference|raw$ { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} +` + +var getterImpl = ` +func (c *$.GroupGoName$$.Version$ClusterClient) $.type|publicPlural$() $.type|public$ClusterInterface { + return &$.type|privatePlural$ClusterInterface{clientCache: c.clientCache} +} +` + +var newClientForConfigTemplate = ` +// NewForConfig creates a new $.GroupGoName$$.Version$ClusterClient for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *$.restConfig|raw$) (*$.GroupGoName$$.Version$ClusterClient, error) { + config := *c + setConfigDefaults(&config) + httpClient, err := $.RESTHTTPClientFor|raw$(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} +` + +var newClientForConfigAndClientTemplate = ` +// NewForConfigAndClient creates a new $.GroupGoName$$.Version$ClusterClient for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +func NewForConfigAndClient(c *$.restConfig|raw$, h *$.httpClient|raw$) (*$.GroupGoName$$.Version$ClusterClient, error) { + cache := $.kcpNewCache|raw$(c, h, &$.kcpClientConstructor|raw$[*$.typedClientReference|raw$]{ + NewForConfigAndClient: $.NewForConfigAndClient|raw$, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + + return &$.GroupGoName$$.Version$ClusterClient{clientCache: cache}, nil +} +` + +var newClientForConfigOrDieTemplate = ` +// NewForConfigOrDie creates a new $.GroupGoName$$.Version$ClusterClient for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *$.restConfig|raw$) *$.GroupGoName$$.Version$ClusterClient { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} +` + +var setInternalVersionClientDefaultsTemplate = ` +func setConfigDefaults(config *$.restConfig|raw$) { + config.APIPath = $.apiPath$ + if config.UserAgent == "" { + config.UserAgent = $.restDefaultKubernetesUserAgent|raw$() + } + if config.GroupVersion == nil || config.GroupVersion.Group != $.SchemePrioritizedVersionsForGroup|raw$("$.groupName$")[0].Group { + gv := $.SchemePrioritizedVersionsForGroup|raw$("$.groupName$")[0] + config.GroupVersion = &gv + } + config.NegotiatedSerializer = $.restCodecFactoryForGeneratedClient|raw$($.Scheme|raw$, $.Codecs|raw$) + + if config.QPS == 0 { + config.QPS = 5 + } + if config.Burst == 0 { + config.Burst = 10 + } +} +` + +var setClientDefaultsTemplate = ` +func setConfigDefaults(config *$.restConfig|raw$) { + gv := $.SchemeGroupVersion|raw$ + config.GroupVersion = &gv + config.APIPath = $.apiPath$ + config.NegotiatedSerializer = $.restCodecFactoryForGeneratedClient|raw$($.Scheme|raw$, $.Codecs|raw$).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = $.restDefaultKubernetesUserAgent|raw$() + } +} +` diff --git a/cmd/cluster-client-gen/generators/generator_for_type.go b/cmd/cluster-client-gen/generators/generator_for_type.go new file mode 100644 index 000000000..8f50e1763 --- /dev/null +++ b/cmd/cluster-client-gen/generators/generator_for_type.go @@ -0,0 +1,263 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "io" + "path" + "strings" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/util" +) + +// genClientForType produces a file for each top-level type. +type genClientForType struct { + generator.GoGenerator + outputPackage string // must be a Go import-path + inputPackage string + clientsetPackage string // must be a Go import-path + applyConfigurationPackage string // must be a Go import-path + singleClusterClientPackage string + group string + version string + groupGoName string + typeToMatch *types.Type + imports namer.ImportTracker +} + +var _ generator.Generator = &genClientForType{} + +// Filter ignores all but one type because we're making a single file per type. +func (g *genClientForType) Filter(_ *generator.Context, t *types.Type) bool { + return t == g.typeToMatch +} + +func (g *genClientForType) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.outputPackage, g.imports), + } +} + +func (g *genClientForType) Imports(_ *generator.Context) (imports []string) { + imports = append(imports, g.imports.ImportLines()...) + imports = append(imports, + "github.com/kcp-dev/logicalcluster/v3", + ) + return +} + +// GenerateType makes the body of a file implementing the individual typed client for type t. +func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { + generateApply := len(g.applyConfigurationPackage) > 0 + defaultVerbTemplates := buildDefaultVerbTemplates() + sw := generator.NewSnippetWriter(w, c, "$", "$") + pkg := path.Base(t.Name.Package) + tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) + if err != nil { + return err + } + + typedInterfaceName := c.Namers["public"].Name(t) + "Interface" + typedClientName := g.groupGoName + namer.IC(g.version) + "Client" + + m := map[string]interface{}{ + "type": t, + "inputType": t, + "resultType": t, + "package": pkg, + "Package": namer.IC(pkg), + "namespaced": !tags.NonNamespaced, + "noVerbs": tags.NoVerbs, + "Group": namer.IC(g.group), + "subresource": false, + "subresourcePath": "", + "GroupGoName": g.groupGoName, + "Version": namer.IC(g.version), + "GetOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GetOptions"}), + "ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}), + "NamespaceAll": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "NamespaceAll"}), + "watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}), + "RESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}), + "schemeParameterCodec": c.Universe.Variable(types.Name{Package: path.Join(g.clientsetPackage, "scheme"), Name: "ParameterCodec"}), + "fmtErrorf": c.Universe.Function(types.Name{Package: "fmt", Name: "Errorf"}), + "klogWarningf": c.Universe.Function(types.Name{Package: "k8s.io/klog/v2", Name: "Warningf"}), + "context": c.Universe.Type(types.Name{Package: "context", Name: "Context"}), + "timeDuration": c.Universe.Type(types.Name{Package: "time", Name: "Duration"}), + "timeSecond": c.Universe.Type(types.Name{Package: "time", Name: "Second"}), + "resourceVersionMatchNotOlderThan": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ResourceVersionMatchNotOlderThan"}), + "CheckListFromCacheDataConsistencyIfRequested": c.Universe.Function(types.Name{Package: "k8s.io/client-go/util/consistencydetector", Name: "CheckListFromCacheDataConsistencyIfRequested"}), + "CheckWatchListFromCacheDataConsistencyIfRequested": c.Universe.Function(types.Name{Package: "k8s.io/client-go/util/consistencydetector", Name: "CheckWatchListFromCacheDataConsistencyIfRequested"}), + "PrepareWatchListOptionsFromListOptions": c.Universe.Function(types.Name{Package: "k8s.io/client-go/util/watchlist", Name: "PrepareWatchListOptionsFromListOptions"}), + "applyNewRequest": c.Universe.Function(types.Name{Package: "k8s.io/client-go/util/apply", Name: "NewRequest"}), + "Client": c.Universe.Type(types.Name{Package: "k8s.io/client-go/gentype", Name: "Client"}), + "ClientWithList": c.Universe.Type(types.Name{Package: "k8s.io/client-go/gentype", Name: "ClientWithList"}), + "ClientWithApply": c.Universe.Type(types.Name{Package: "k8s.io/client-go/gentype", Name: "ClientWithApply"}), + "ClientWithListAndApply": c.Universe.Type(types.Name{Package: "k8s.io/client-go/gentype", Name: "ClientWithListAndApply"}), + "NewClient": c.Universe.Function(types.Name{Package: "k8s.io/client-go/gentype", Name: "NewClient"}), + "NewClientWithApply": c.Universe.Function(types.Name{Package: "k8s.io/client-go/gentype", Name: "NewClientWithApply"}), + "NewClientWithList": c.Universe.Function(types.Name{Package: "k8s.io/client-go/gentype", Name: "NewClientWithList"}), + "NewClientWithListAndApply": c.Universe.Function(types.Name{Package: "k8s.io/client-go/gentype", Name: "NewClientWithListAndApply"}), + "kcpCache": c.Universe.Function(types.Name{Package: "github.com/kcp-dev/apimachinery/v2/pkg/client", Name: "Cache"}), + "typedInterfaceReference": c.Universe.Type(types.Name{Package: g.singleClusterClientPackage, Name: typedInterfaceName}), + "typedClientReference": c.Universe.Type(types.Name{Package: g.singleClusterClientPackage, Name: typedClientName}), + } + + if generateApply { + // Generated apply configuration type references required for generated Apply function + _, gvString := util.ParsePathGroupVersion(g.inputPackage) + m["inputApplyConfig"] = types.Ref(path.Join(g.applyConfigurationPackage, gvString), t.Name.Name+"ApplyConfiguration") + } + + sw.Do(getterInterface, m) + + sw.Do(interfaceTemplate1, m) + if !tags.NoVerbs { + tags.SkipVerbs = append(tags.SkipVerbs, "updateStatus", "applyStatus") + sw.Do(generateInterface(defaultVerbTemplates, tags), m) + } + sw.Do(interfaceTemplate4, m) + + sw.Do(clusterInterfaceImpl, m) + + if !tags.NonNamespaced { + sw.Do(namespacedClusterInterfaceImpl, m) + } else { + sw.Do(nonNamespacedClusterInterfaceImpl, m) + } + + if !tags.NoVerbs && tags.HasVerb("list") { + sw.Do(listClusterInterfaceImpl, m) + } + + if !tags.NoVerbs && tags.HasVerb("watch") { + sw.Do(watchClusterInterfaceImpl, m) + } + + if !tags.NonNamespaced { + sw.Do(namespacer, m) + } + + return sw.Error() +} + +func generateInterface(defaultVerbTemplates map[string]string, tags util.Tags) string { + // need an ordered list here to guarantee order of generated methods. + out := []string{} + for _, m := range util.SupportedVerbs { + if tags.HasVerb(m) && len(defaultVerbTemplates[m]) > 0 { + out = append(out, defaultVerbTemplates[m]) + } + } + return strings.Join(out, "\n") +} + +func buildDefaultVerbTemplates() map[string]string { + m := map[string]string{ + "list": `List(ctx $.context|raw$, opts $.ListOptions|raw$) (*$.resultType|raw$List, error)`, + "watch": `Watch(ctx $.context|raw$, opts $.ListOptions|raw$) ($.watchInterface|raw$, error)`, + } + return m +} + +// group client will implement this interface. +var getterInterface = ` +// $.type|publicPlural$ClusterGetter has a method to return a $.type|public$ClusterInterface. +// A group's cluster client should implement this interface. +type $.type|publicPlural$ClusterGetter interface { + $.type|publicPlural$() $.type|public$ClusterInterface +} +` + +// this type's interface, typed client will implement this interface. +var interfaceTemplate1 = ` +$- if .noVerbs $ +// $.type|public$ClusterInterface can scope down to one cluster and return a $if .namespaced$$.type|publicPlural$Namespacer$else$$.typedInterfaceReference|raw$$end$. +$ else $ +// $.type|public$ClusterInterface can operate on $.type|publicPlural$ across all clusters, +// or scope down to one cluster and return a $if .namespaced$$.type|publicPlural$Namespacer$else$$.typedInterfaceReference|raw$$end$. +$ end -$ +type $.type|public$ClusterInterface interface { + Cluster(logicalcluster.Path) $if .namespaced$$.type|publicPlural$Namespacer$else$$.typedInterfaceReference|raw$$end$ +` + +var interfaceTemplate4 = ` + $.type|public$ClusterExpansion +} +` + +var clusterInterfaceImpl = ` +type $.type|privatePlural$ClusterInterface struct { + clientCache $.kcpCache|raw$[*$.typedClientReference|raw$] +} +` + +var namespacedClusterInterfaceImpl = ` +// Cluster scopes the client down to a particular cluster. +func (c *$.type|privatePlural$ClusterInterface) Cluster(clusterPath logicalcluster.Path) $if .namespaced$$.type|publicPlural$Namespacer$else$$.typedInterfaceReference|raw$$end$ { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &$.type|privatePlural$Namespacer{clientCache: c.clientCache, clusterPath: clusterPath} +} +` + +var nonNamespacedClusterInterfaceImpl = ` +// Cluster scopes the client down to a particular cluster. +func (c *$.type|privatePlural$ClusterInterface) Cluster(clusterPath logicalcluster.Path) $if .namespaced$$.type|publicPlural$Namespacer$else$$.typedInterfaceReference|raw$$end$ { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return c.clientCache.ClusterOrDie(clusterPath).$.type|publicPlural$() +} +` + +var listClusterInterfaceImpl = ` +// List returns the entire collection of all $.type|publicPlural$ across all clusters. +func (c *$.type|privatePlural$ClusterInterface) List(ctx context.Context, opts $.ListOptions|raw$) (*$.resultType|raw$List, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).$.type|publicPlural$($if .namespaced$$.NamespaceAll|raw$$end$).List(ctx, opts) +} +` + +var watchClusterInterfaceImpl = ` +// Watch begins to watch all $.type|publicPlural$ across all clusters. +func (c *$.type|privatePlural$ClusterInterface) Watch(ctx context.Context, opts $.ListOptions|raw$) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).$.type|publicPlural$($if .namespaced$$.NamespaceAll|raw$$end$).Watch(ctx, opts) +} +` + +var namespacer = ` +// $.type|publicPlural$Namespacer can scope to objects within a namespace, returning a $.typedInterfaceReference|raw$. +type $.type|publicPlural$Namespacer interface { + Namespace(string) $.typedInterfaceReference|raw$ +} + +type $.type|privatePlural$Namespacer struct { + clientCache $.kcpCache|raw$[*$.typedClientReference|raw$] + clusterPath logicalcluster.Path +} + +func (n *$.type|privatePlural$Namespacer) Namespace(namespace string) $.typedInterfaceReference|raw$ { + return n.clientCache.ClusterOrDie(n.clusterPath).$.type|publicPlural$(namespace) +} +` diff --git a/cmd/cluster-client-gen/generators/scheme/generator_for_scheme.go b/cmd/cluster-client-gen/generators/scheme/generator_for_scheme.go new file mode 100644 index 000000000..429dd336a --- /dev/null +++ b/cmd/cluster-client-gen/generators/scheme/generator_for_scheme.go @@ -0,0 +1,189 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package scheme + +import ( + "fmt" + "io" + "os" + "path" + "path/filepath" + "strings" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + + clientgentypes "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" +) + +// GenScheme produces a package for a clientset with the scheme, codecs and parameter codecs. +type GenScheme struct { + generator.GoGenerator + OutputPkg string // Must be a Go import-path + OutputPath string // optional + Groups []clientgentypes.GroupVersions + GroupGoNames map[clientgentypes.GroupVersion]string + InputPackages map[clientgentypes.GroupVersion]string + ImportTracker namer.ImportTracker + PrivateScheme bool + CreateRegistry bool + schemeGenerated bool +} + +func (g *GenScheme) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.OutputPkg, g.ImportTracker), + } +} + +// We only want to call GenerateType() once. +func (g *GenScheme) Filter(_ *generator.Context, _ *types.Type) bool { + ret := !g.schemeGenerated + g.schemeGenerated = true + return ret +} + +func (g *GenScheme) Imports(_ *generator.Context) (imports []string) { + imports = append(imports, g.ImportTracker.ImportLines()...) + for _, group := range g.Groups { + for _, version := range group.Versions { + packagePath := g.InputPackages[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}] + groupAlias := strings.ToLower(g.GroupGoNames[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}]) + if g.CreateRegistry { + // import the install package for internal clientsets instead of the type package with register.go + if version.Version != "" { + packagePath = path.Dir(packagePath) + } + packagePath = path.Join(packagePath, "install") + + imports = append(imports, fmt.Sprintf("%s %q", groupAlias, packagePath)) + break + } + + imports = append(imports, fmt.Sprintf("%s%s %q", groupAlias, strings.ToLower(version.Version.NonEmpty()), packagePath)) + } + } + return +} + +func (g *GenScheme) GenerateType(c *generator.Context, _ *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "$", "$") + + allGroupVersions := clientgentypes.ToGroupVersionInfo(g.Groups, g.GroupGoNames) + allInstallGroups := clientgentypes.ToGroupInstallPackages(g.Groups, g.GroupGoNames) + + m := map[string]interface{}{ + "publicScheme": !g.PrivateScheme, + "allGroupVersions": allGroupVersions, + "allInstallGroups": allInstallGroups, + "customRegister": false, + "runtimeNewParameterCodec": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "NewParameterCodec"}), + "runtimeNewScheme": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "NewScheme"}), + "serializerNewCodecFactory": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/serializer", Name: "NewCodecFactory"}), + "runtimeScheme": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "Scheme"}), + "runtimeSchemeBuilder": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "SchemeBuilder"}), + "runtimeUtilMust": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/util/runtime", Name: "Must"}), + "schemaGroupVersion": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersion"}), + "metav1AddToGroupVersion": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "AddToGroupVersion"}), + } + globals := map[string]string{ + "Scheme": "Scheme", + "Codecs": "Codecs", + "ParameterCodec": "ParameterCodec", + "Registry": "Registry", + } + for k, v := range globals { + if g.PrivateScheme { + m[k] = strings.ToLower(v[0:1]) + v[1:] + } else { + m[k] = v + } + } + + sw.Do(globalsTemplate, m) + + if g.OutputPath != "" { + if _, err := os.Stat(filepath.Join(g.OutputPath, strings.ToLower("register_custom.go"))); err == nil { + m["customRegister"] = true + } + } + + if g.CreateRegistry { + sw.Do(registryRegistration, m) + } else { + sw.Do(simpleRegistration, m) + } + + return sw.Error() +} + +var globalsTemplate = ` +var $.Scheme$ = $.runtimeNewScheme|raw$() +var $.Codecs$ = $.serializerNewCodecFactory|raw$($.Scheme$) +$if .publicScheme$var $.ParameterCodec$ = $.runtimeNewParameterCodec|raw$($.Scheme$)$end -$` + +var registryRegistration = ` + +func init() { + $.metav1AddToGroupVersion|raw$($.Scheme$, $.schemaGroupVersion|raw${Version: "v1"}) + Install($.Scheme$) +} + +// Install registers the API group and adds types to a scheme +func Install(scheme *$.runtimeScheme|raw$) { + $- range .allInstallGroups$ + $.InstallPackageAlias$.Install(scheme) + $- end$ + $if .customRegister$ + ExtraInstall(scheme) + $end -$ +} +` + +var simpleRegistration = ` +var localSchemeBuilder = $.runtimeSchemeBuilder|raw${ + $- range .allGroupVersions$ + $.PackageAlias$.AddToScheme, + $- end$ + $if .customRegister$ + ExtraAddToScheme, + $end -$ +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + $.metav1AddToGroupVersion|raw$($.Scheme$, $.schemaGroupVersion|raw${Version: "v1"}) + $.runtimeUtilMust|raw$(AddToScheme($.Scheme$)) +} +` diff --git a/cmd/cluster-client-gen/generators/util/gvpackages.go b/cmd/cluster-client-gen/generators/util/gvpackages.go new file mode 100644 index 000000000..ce5972f40 --- /dev/null +++ b/cmd/cluster-client-gen/generators/util/gvpackages.go @@ -0,0 +1,42 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "path" + "strings" +) + +func ParsePathGroupVersion(pgvString string) (gvPath string, gvString string) { + subs := strings.Split(pgvString, "/") + length := len(subs) + switch length { + case 0, 1, 2: + return "", pgvString + default: + return strings.Join(subs[:length-2], "/"), strings.Join(subs[length-2:], "/") + } +} + +// GroupVersionAliasFromPackage turns "acme.corp/pkg/apis/example/v2" into "examplev2". +func GroupVersionAliasFromPackage(pkgName string) string { + version := path.Base(pkgName) + group := path.Base(path.Dir(pkgName)) + + return group + version +} diff --git a/cmd/cluster-client-gen/generators/util/tags.go b/cmd/cluster-client-gen/generators/util/tags.go new file mode 100644 index 000000000..630846f02 --- /dev/null +++ b/cmd/cluster-client-gen/generators/util/tags.go @@ -0,0 +1,345 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "errors" + "fmt" + "strings" + + "k8s.io/gengo/v2" +) + +var supportedTags = []string{ + "genclient", + "genclient:nonNamespaced", + "genclient:noVerbs", + "genclient:onlyVerbs", + "genclient:skipVerbs", + "genclient:noStatus", + "genclient:readonly", + "genclient:method", +} + +// SupportedVerbs is a list of supported verbs for +onlyVerbs and +skipVerbs. +var SupportedVerbs = []string{ + "create", + "update", + "updateStatus", + "delete", + "deleteCollection", + "get", + "list", + "watch", + "patch", + "apply", + "applyStatus", +} + +// ReadonlyVerbs represents a list of read-only verbs. +var ReadonlyVerbs = []string{ + "get", + "list", + "watch", +} + +// genClientPrefix is the default prefix for all genclient tags. +const genClientPrefix = "genclient:" + +// unsupportedExtensionVerbs is a list of verbs we don't support generating +// extension client functions for. +var unsupportedExtensionVerbs = []string{ + "updateStatus", + "deleteCollection", + "watch", + "delete", +} + +// inputTypeSupportedVerbs is a list of verb types that supports overriding the +// input argument type. +var inputTypeSupportedVerbs = []string{ + "create", + "update", + "apply", +} + +// resultTypeSupportedVerbs is a list of verb types that supports overriding the +// resulting type. +var resultTypeSupportedVerbs = []string{ + "create", + "update", + "get", + "list", + "patch", + "apply", +} + +// Extensions allows to extend the default set of client verbs +// (CRUD+watch+patch+list+deleteCollection) for a given type with custom defined +// verbs. Custom verbs can have custom input and result types and also allow to +// use a sub-resource in a request instead of top-level resource type. +// +// Example: +// +// +genclient:method=UpdateScale,verb=update,subresource=scale,input=Scale,result=Scale +// +// type ReplicaSet struct { ... } +// +// The 'method=UpdateScale' is the name of the client function. +// The 'verb=update' here means the client function will use 'PUT' action. +// The 'subresource=scale' means we will use SubResource template to generate this client function. +// The 'input' is the input type used for creation (function argument). +// The 'result' (not needed in this case) is the result type returned from the +// client function. +type extension struct { + // VerbName is the name of the custom verb (Scale, Instantiate, etc..) + VerbName string + // VerbType is the type of the verb (only verbs from SupportedVerbs are + // supported) + VerbType string + // SubResourcePath defines a path to a sub-resource to use in the request. + // (optional) + SubResourcePath string + // InputTypeOverride overrides the input parameter type for the verb. By + // default the original type is used. Overriding the input type only works for + // "create" and "update" verb types. The given type must exists in the same + // package as the original type. + // (optional) + InputTypeOverride string + // ResultTypeOverride overrides the resulting object type for the verb. By + // default the original type is used. Overriding the result type works. + // (optional) + ResultTypeOverride string +} + +// IsSubresource indicates if this extension should generate the sub-resource. +func (e *extension) IsSubresource() bool { + return len(e.SubResourcePath) > 0 +} + +// HasVerb checks if the extension matches the given verb. +func (e *extension) HasVerb(verb string) bool { + return e.VerbType == verb +} + +// Input returns the input override package path and the type. +func (e *extension) Input() (string, string) { + parts := strings.Split(e.InputTypeOverride, ".") + return parts[len(parts)-1], strings.Join(parts[0:len(parts)-1], ".") +} + +// Result returns the result override package path and the type. +func (e *extension) Result() (string, string) { + parts := strings.Split(e.ResultTypeOverride, ".") + return parts[len(parts)-1], strings.Join(parts[0:len(parts)-1], ".") +} + +// Tags represents a genclient configuration for a single type. +type Tags struct { + // +genclient + GenerateClient bool + // +genclient:nonNamespaced + NonNamespaced bool + // +genclient:noStatus + NoStatus bool + // +genclient:noVerbs + NoVerbs bool + // +genclient:skipVerbs=get,update + // +genclient:onlyVerbs=create,delete + SkipVerbs []string + // +genclient:method=UpdateScale,verb=update,subresource=scale,input=Scale,result=Scale + Extensions []extension +} + +// HasVerb returns true if we should include the given verb in final client interface and +// generate the function for it. +func (t Tags) HasVerb(verb string) bool { + if len(t.SkipVerbs) == 0 { + return true + } + for _, s := range t.SkipVerbs { + if verb == s { + return false + } + } + return true +} + +// MustParseClientGenTags calls ParseClientGenTags but instead of returning error it panics. +func MustParseClientGenTags(lines []string) Tags { + tags, err := ParseClientGenTags(lines) + if err != nil { + panic(err.Error()) + } + return tags +} + +// ParseClientGenTags parse the provided genclient tags and validates that no unknown +// tags are provided. +func ParseClientGenTags(lines []string) (Tags, error) { + ret := Tags{} + values := gengo.ExtractCommentTags("+", lines) //nolint:staticcheck + var value []string + value, ret.GenerateClient = values["genclient"] + // Check the old format and error when used to avoid generating client when //+genclient=false + if len(value) > 0 && len(value[0]) > 0 { + return ret, fmt.Errorf("+genclient=%s is invalid, use //+genclient if you want to generate client or omit it when you want to disable generation", value) + } + _, ret.NonNamespaced = values[genClientPrefix+"nonNamespaced"] + // Check the old format and error when used + if value := values["nonNamespaced"]; len(value) > 0 && len(value[0]) > 0 { + return ret, fmt.Errorf("+nonNamespaced=%s is invalid, use //+genclient:nonNamespaced instead", value[0]) + } + _, ret.NoVerbs = values[genClientPrefix+"noVerbs"] + _, ret.NoStatus = values[genClientPrefix+"noStatus"] + onlyVerbs := []string{} + if _, isReadonly := values[genClientPrefix+"readonly"]; isReadonly { + onlyVerbs = ReadonlyVerbs + } + // Check the old format and error when used + if value := values["readonly"]; len(value) > 0 && len(value[0]) > 0 { + return ret, fmt.Errorf("+readonly=%s is invalid, use //+genclient:readonly instead", value[0]) + } + if v, exists := values[genClientPrefix+"skipVerbs"]; exists { + ret.SkipVerbs = strings.Split(v[0], ",") + } + if v, exists := values[genClientPrefix+"onlyVerbs"]; exists || len(onlyVerbs) > 0 { + if len(v) > 0 { + onlyVerbs = append(onlyVerbs, strings.Split(v[0], ",")...) + } + skipVerbs := []string{} + for _, m := range SupportedVerbs { + skip := true + for _, o := range onlyVerbs { + if o == m { + skip = false + break + } + } + // Check for conflicts + for _, v := range skipVerbs { + if v == m { + return ret, fmt.Errorf("verb %q used both in genclient:skipVerbs and genclient:onlyVerbs", v) + } + } + if skip { + skipVerbs = append(skipVerbs, m) + } + } + ret.SkipVerbs = skipVerbs + } + var err error + if ret.Extensions, err = parseClientExtensions(values); err != nil { + return ret, err + } + return ret, validateClientGenTags(values) +} + +func parseClientExtensions(tags map[string][]string) ([]extension, error) { + var ret []extension + for name, values := range tags { + if !strings.HasPrefix(name, genClientPrefix+"method") { + continue + } + for _, value := range values { + // the value comes in this form: "Foo,verb=create" + ext := extension{} + parts := strings.Split(value, ",") + if len(parts) == 0 { + return nil, fmt.Errorf("invalid of empty extension verb name: %q", value) + } + // The first part represents the name of the extension + ext.VerbName = parts[0] + if len(ext.VerbName) == 0 { + return nil, fmt.Errorf("must specify a verb name (// +genclient:method=Foo,verb=create)") + } + // Parse rest of the arguments + params := parts[1:] + for _, p := range params { + parts := strings.Split(p, "=") + if len(parts) != 2 { + return nil, fmt.Errorf("invalid extension tag specification %q", p) + } + key, val := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]) + if len(val) == 0 { + return nil, fmt.Errorf("empty value of %q for %q extension", key, ext.VerbName) + } + switch key { + case "verb": + ext.VerbType = val + case "subresource": + ext.SubResourcePath = val + case "input": + ext.InputTypeOverride = val + case "result": + ext.ResultTypeOverride = val + default: + return nil, fmt.Errorf("unknown extension configuration key %q", key) + } + } + // Validate resulting extension configuration + if len(ext.VerbType) == 0 { + return nil, fmt.Errorf("verb type must be specified (use '// +genclient:method=%s,verb=create')", ext.VerbName) + } + if len(ext.ResultTypeOverride) > 0 { + supported := false + for _, v := range resultTypeSupportedVerbs { + if ext.VerbType == v { + supported = true + break + } + } + if !supported { + return nil, fmt.Errorf("%s: result type is not supported for %q verbs (supported verbs: %#v)", ext.VerbName, ext.VerbType, resultTypeSupportedVerbs) + } + } + if len(ext.InputTypeOverride) > 0 { + supported := false + for _, v := range inputTypeSupportedVerbs { + if ext.VerbType == v { + supported = true + break + } + } + if !supported { + return nil, fmt.Errorf("%s: input type is not supported for %q verbs (supported verbs: %#v)", ext.VerbName, ext.VerbType, inputTypeSupportedVerbs) + } + } + for _, t := range unsupportedExtensionVerbs { + if ext.VerbType == t { + return nil, fmt.Errorf("verb %q is not supported by extension generator", ext.VerbType) + } + } + ret = append(ret, ext) + } + } + return ret, nil +} + +// validateTags validates that only supported genclient tags were provided. +func validateClientGenTags(values map[string][]string) error { + for _, k := range supportedTags { + delete(values, k) + } + for key := range values { + if strings.HasPrefix(key, strings.TrimSuffix(genClientPrefix, ":")) { + return errors.New("unknown tag detected: " + key) + } + } + return nil +} diff --git a/cmd/cluster-client-gen/generators/util/tags_test.go b/cmd/cluster-client-gen/generators/util/tags_test.go new file mode 100644 index 000000000..f069f5617 --- /dev/null +++ b/cmd/cluster-client-gen/generators/util/tags_test.go @@ -0,0 +1,149 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "reflect" + "testing" +) + +func TestParseTags(t *testing.T) { + testCases := map[string]struct { + lines []string + expectTags Tags + expectError bool + }{ + "genclient": { + lines: []string{`+genclient`}, + expectTags: Tags{GenerateClient: true}, + }, + "genclient=true": { + lines: []string{`+genclient=true`}, + expectError: true, + }, + "nonNamespaced=true": { + lines: []string{`+genclient=true`, `+nonNamespaced=true`}, + expectError: true, + }, + "readonly=true": { + lines: []string{`+genclient=true`, `+readonly=true`}, + expectError: true, + }, + "genclient:nonNamespaced": { + lines: []string{`+genclient`, `+genclient:nonNamespaced`}, + expectTags: Tags{GenerateClient: true, NonNamespaced: true}, + }, + "genclient:noVerbs": { + lines: []string{`+genclient`, `+genclient:noVerbs`}, + expectTags: Tags{GenerateClient: true, NoVerbs: true}, + }, + "genclient:noStatus": { + lines: []string{`+genclient`, `+genclient:noStatus`}, + expectTags: Tags{GenerateClient: true, NoStatus: true}, + }, + "genclient:onlyVerbs": { + lines: []string{`+genclient`, `+genclient:onlyVerbs=create,delete`}, + expectTags: Tags{GenerateClient: true, SkipVerbs: []string{"update", "updateStatus", "deleteCollection", "get", "list", "watch", "patch", "apply", "applyStatus"}}, + }, + "genclient:readonly": { + lines: []string{`+genclient`, `+genclient:readonly`}, + expectTags: Tags{GenerateClient: true, SkipVerbs: []string{"create", "update", "updateStatus", "delete", "deleteCollection", "patch", "apply", "applyStatus"}}, + }, + "genclient:conflict": { + lines: []string{`+genclient`, `+genclient:onlyVerbs=create`, `+genclient:skipVerbs=create`}, + expectError: true, + }, + "genclient:invalid": { + lines: []string{`+genclient`, `+genclient:invalid`}, + expectError: true, + }, + } + for key, c := range testCases { + result, err := ParseClientGenTags(c.lines) + if err != nil && !c.expectError { + t.Fatalf("unexpected error: %v", err) + } + if !c.expectError && !reflect.DeepEqual(result, c.expectTags) { + t.Errorf("[%s] expected %#v to be %#v", key, result, c.expectTags) + } + } +} + +func TestParseTagsExtension(t *testing.T) { + testCases := map[string]struct { + lines []string + expectedExtensions []extension + expectError bool + }{ + "simplest extension": { + lines: []string{`+genclient:method=Foo,verb=create`}, + expectedExtensions: []extension{{VerbName: "Foo", VerbType: "create"}}, + }, + "multiple extensions": { + lines: []string{`+genclient:method=Foo,verb=create`, `+genclient:method=Bar,verb=get`}, + expectedExtensions: []extension{{VerbName: "Foo", VerbType: "create"}, {VerbName: "Bar", VerbType: "get"}}, + }, + "extension without verb": { + lines: []string{`+genclient:method`}, + expectError: true, + }, + "extension without verb type": { + lines: []string{`+genclient:method=Foo`}, + expectError: true, + }, + "sub-resource extension": { + lines: []string{`+genclient:method=Foo,verb=create,subresource=bar`}, + expectedExtensions: []extension{{VerbName: "Foo", VerbType: "create", SubResourcePath: "bar"}}, + }, + "output type extension": { + lines: []string{`+genclient:method=Foos,verb=list,result=Bars`}, + expectedExtensions: []extension{{VerbName: "Foos", VerbType: "list", ResultTypeOverride: "Bars"}}, + }, + "input type extension": { + lines: []string{`+genclient:method=Foo,verb=update,input=Bar`}, + expectedExtensions: []extension{{VerbName: "Foo", VerbType: "update", InputTypeOverride: "Bar"}}, + }, + "unknown verb type extension": { + lines: []string{`+genclient:method=Foo,verb=explode`}, + expectedExtensions: nil, + expectError: true, + }, + "invalid verb extension": { + lines: []string{`+genclient:method=Foo,unknown=bar`}, + expectedExtensions: nil, + expectError: true, + }, + "empty verb extension subresource": { + lines: []string{`+genclient:method=Foo,verb=get,subresource=`}, + expectedExtensions: nil, + expectError: true, + }, + } + for key, c := range testCases { + result, err := ParseClientGenTags(c.lines) + if err != nil && !c.expectError { + t.Fatalf("[%s] unexpected error: %v", key, err) + } + if err != nil && c.expectError { + t.Logf("[%s] got expected error: %+v", key, err) + } + if !c.expectError && !reflect.DeepEqual(result.Extensions, c.expectedExtensions) { + t.Errorf("[%s] expected %#+v to be %#+v", key, result.Extensions, c.expectedExtensions) + } + } +} diff --git a/cmd/cluster-client-gen/main.go b/cmd/cluster-client-gen/main.go new file mode 100644 index 000000000..bbb1fb620 --- /dev/null +++ b/cmd/cluster-client-gen/main.go @@ -0,0 +1,72 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// client-gen makes the individual typed clients using gengo. +package main + +import ( + "flag" + "slices" + + "github.com/spf13/pflag" + + "k8s.io/gengo/v2" + "k8s.io/gengo/v2/generator" + "k8s.io/klog/v2" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/args" + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators" + "github.com/kcp-dev/code-generator/v3/pkg/util" +) + +func main() { + klog.InitFlags(nil) + args := args.New() + + args.AddFlags(pflag.CommandLine, "k8s.io/kubernetes/pkg/apis") // TODO: move this input path out of client-gen + _ = flag.Set("logtostderr", "true") + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + + // add group version package as input dirs for gengo + inputPkgs := []string{} + for _, pkg := range args.Groups { + for _, v := range pkg.Versions { + inputPkgs = append(inputPkgs, v.Package) + } + } + // ensure stable code generation output + slices.Sort(inputPkgs) + + if err := args.Validate(); err != nil { + klog.Fatalf("Error: %v", err) + } + + myTargets := func(context *generator.Context) []generator.Target { + return generators.GetTargets(context, args) + } + + if err := gengo.Execute( + generators.NameSystems(util.PluralExceptionListToMapOrDie(args.PluralExceptions)), + generators.DefaultNameSystem(), + myTargets, + gengo.StdBuildTag, + inputPkgs, + ); err != nil { + klog.Fatalf("Error: %v", err) + } +} diff --git a/cmd/cluster-client-gen/types/helpers.go b/cmd/cluster-client-gen/types/helpers.go new file mode 100644 index 000000000..08b746397 --- /dev/null +++ b/cmd/cluster-client-gen/types/helpers.go @@ -0,0 +1,122 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package types + +import ( + "fmt" + "regexp" + "sort" + "strings" + + "k8s.io/gengo/v2/namer" +) + +// ToGroupVersion turns "group/version" string into a GroupVersion struct. It reports error +// if it cannot parse the string. +func ToGroupVersion(gv string) (GroupVersion, error) { + // this can be the internal version for the legacy kube types + // TODO once we've cleared the last uses as strings, this special case should be removed. + if (len(gv) == 0) || (gv == "/") { + return GroupVersion{}, nil + } + + switch strings.Count(gv, "/") { + case 0: + return GroupVersion{Group(gv), ""}, nil + case 1: + i := strings.Index(gv, "/") + return GroupVersion{Group(gv[:i]), Version(gv[i+1:])}, nil + default: + return GroupVersion{}, fmt.Errorf("unexpected GroupVersion string: %v", gv) + } +} + +type sortableSliceOfVersions []string + +func (a sortableSliceOfVersions) Len() int { return len(a) } +func (a sortableSliceOfVersions) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a sortableSliceOfVersions) Less(i, j int) bool { + vi, vj := strings.TrimLeft(a[i], "v"), strings.TrimLeft(a[j], "v") + major := regexp.MustCompile(`^\d+`) + viMajor, vjMajor := major.FindString(vi), major.FindString(vj) + viRemaining, vjRemaining := strings.TrimLeft(vi, viMajor), strings.TrimLeft(vj, vjMajor) + switch { + case len(viRemaining) == 0 && len(vjRemaining) == 0: + return viMajor < vjMajor + case len(viRemaining) == 0 && len(vjRemaining) != 0: + // stable version is greater than unstable version + return false + case len(viRemaining) != 0 && len(vjRemaining) == 0: + // stable version is greater than unstable version + return true + } + // neither are stable versions + if viMajor != vjMajor { + return viMajor < vjMajor + } + // assuming at most we have one alpha or one beta version, so if vi contains "alpha", it's the lesser one. + return strings.Contains(viRemaining, "alpha") +} + +// Determine the default version among versions. If a user calls a group client +// without specifying the version (e.g., c.CoreV1(), instead of c.CoreV1()), the +// default version will be returned. +func defaultVersion(versions []PackageVersion) Version { + versionStrings := make([]string, 0, len(versions)) + for _, version := range versions { + versionStrings = append(versionStrings, version.Version.String()) + } + sort.Sort(sortableSliceOfVersions(versionStrings)) + return Version(versionStrings[len(versionStrings)-1]) +} + +// ToGroupVersionInfo is a helper function used by generators for groups. +func ToGroupVersionInfo(groups []GroupVersions, groupGoNames map[GroupVersion]string) []GroupVersionInfo { + groupVersionPackages := make([]GroupVersionInfo, 0, len(groups)) + for _, group := range groups { + for _, version := range group.Versions { + groupGoName := groupGoNames[GroupVersion{Group: group.Group, Version: version.Version}] + groupVersionPackages = append(groupVersionPackages, GroupVersionInfo{ + Group: Group(namer.IC(group.Group.NonEmpty())), + Version: Version(namer.IC(version.Version.String())), + PackageAlias: strings.ToLower(groupGoName + version.Version.NonEmpty()), + GroupGoName: groupGoName, + LowerCaseGroupGoName: namer.IL(groupGoName), + }) + } + } + return groupVersionPackages +} + +func ToGroupInstallPackages(groups []GroupVersions, groupGoNames map[GroupVersion]string) []GroupInstallPackage { + groupInstallPackages := make([]GroupInstallPackage, 0, len(groups)) + for _, group := range groups { + defaultVersion := defaultVersion(group.Versions) + groupGoName := groupGoNames[GroupVersion{Group: group.Group, Version: defaultVersion}] + groupInstallPackages = append(groupInstallPackages, GroupInstallPackage{ + Group: Group(namer.IC(group.Group.NonEmpty())), + InstallPackageAlias: strings.ToLower(groupGoName), + }) + } + return groupInstallPackages +} + +// NormalizeGroupVersion calls normalizes the GroupVersion. +// func NormalizeGroupVersion(gv GroupVersion) GroupVersion { +// return GroupVersion{Group: gv.Group.NonEmpty(), Version: gv.Version, NonEmptyVersion: normalization.Version(gv.Version)} +// } diff --git a/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype_expansion.go b/cmd/cluster-client-gen/types/helpers_test.go similarity index 51% rename from examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype_expansion.go rename to cmd/cluster-client-gen/types/helpers_test.go index 7a36a7444..715a6447b 100644 --- a/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype_expansion.go +++ b/cmd/cluster-client-gen/types/helpers_test.go @@ -1,8 +1,6 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* -Copyright The KCP Authors. +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,12 +15,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. - -package v1beta1 - -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. -type ClusterTestTypeClusterListerExpansion interface{} - -// ClusterTestTypeListerExpansion allows custom methods to be added to ClusterTestTypeLister. -type ClusterTestTypeListerExpansion interface{} +package types + +import ( + "reflect" + "sort" + "testing" +) + +func TestVersionSort(t *testing.T) { + unsortedVersions := []string{"v4beta1", "v2beta1", "v2alpha1", "v3", "v1"} + expected := []string{"v2alpha1", "v2beta1", "v4beta1", "v1", "v3"} + sort.Sort(sortableSliceOfVersions(unsortedVersions)) + if !reflect.DeepEqual(unsortedVersions, expected) { + t.Errorf("expected %#v\ngot %#v", expected, unsortedVersions) + } +} diff --git a/cmd/cluster-client-gen/types/types.go b/cmd/cluster-client-gen/types/types.go new file mode 100644 index 000000000..1932483d1 --- /dev/null +++ b/cmd/cluster-client-gen/types/types.go @@ -0,0 +1,110 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package types + +import "strings" + +type Version string + +func (v Version) String() string { + return string(v) +} + +func (v Version) NonEmpty() string { + if v == "" { + return "internalVersion" + } + return v.String() +} + +func (v Version) PackageName() string { + return strings.ToLower(v.NonEmpty()) +} + +type Group string + +func (g Group) String() string { + return string(g) +} + +func (g Group) NonEmpty() string { + if g == "" { + return "core" + } + return string(g) +} + +func (g Group) PackageName() string { + parts := strings.Split(g.NonEmpty(), ".") + if parts[0] == "internal" && len(parts) > 1 { + return strings.ToLower(parts[1] + parts[0]) + } + return strings.ToLower(parts[0]) +} + +type Kind string + +type PackageVersion struct { + Version + // The fully qualified package, e.g. k8s.io/kubernetes/pkg/apis/apps, where the types.go is found. + Package string +} + +type GroupVersion struct { + Group Group + Version Version +} + +type GroupVersionKind struct { + Group Group + Version Version + Kind Kind +} + +func (gv GroupVersion) ToAPIVersion() string { + if len(gv.Group) > 0 && gv.Group != "" { + return gv.Group.String() + "/" + gv.Version.String() + } + + return gv.Version.String() +} + +func (gv GroupVersion) WithKind(kind Kind) GroupVersionKind { + return GroupVersionKind{Group: gv.Group, Version: gv.Version, Kind: kind} +} + +type GroupVersions struct { + // The name of the package for this group, e.g. apps. + PackageName string + Group Group + Versions []PackageVersion +} + +// GroupVersionInfo contains all the info around a group version. +type GroupVersionInfo struct { + Group Group + Version Version + PackageAlias string + GroupGoName string + LowerCaseGroupGoName string +} + +type GroupInstallPackage struct { + Group Group + InstallPackageAlias string +} diff --git a/cmd/cluster-informer-gen/args/args.go b/cmd/cluster-informer-gen/args/args.go new file mode 100644 index 000000000..95ca19d12 --- /dev/null +++ b/cmd/cluster-informer-gen/args/args.go @@ -0,0 +1,91 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "fmt" + + "github.com/spf13/pflag" +) + +// Args is used by the gengo framework to pass args specific to this generator. +type Args struct { + OutputDir string // must be a directory path + OutputPackage string // must be a Go import-path + GoHeaderFile string + VersionedClientSetPackage string // must be a Go import-path + ListersPackage string // must be a Go import-path + + // Path to the generated Kubernetes single-cluster versioned clientset package. + SingleClusterVersionedClientSetPackage string + // Path to the generated Kubernetes single-cluster informers package. + SingleClusterInformersPackage string + // Path to the generated Kubernetes single-cluster listers package. + SingleClusterListersPackage string + + // PluralExceptions define a list of pluralizer exceptions in Type:PluralType format. + // The default list is "Endpoints:Endpoints" + PluralExceptions []string +} + +// New returns default arguments for the generator. +func New() *Args { + return &Args{} +} + +// AddFlags add the generator flags to the flag set. +func (args *Args) AddFlags(fs *pflag.FlagSet) { + fs.StringVar(&args.OutputDir, "output-dir", "", + "the base directory under which to generate results") + fs.StringVar(&args.OutputPackage, "output-pkg", args.OutputPackage, + "the Go import-path of the generated results") + fs.StringVar(&args.GoHeaderFile, "go-header-file", "", + "the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year") + fs.StringVar(&args.VersionedClientSetPackage, "versioned-clientset-pkg", args.VersionedClientSetPackage, + "the Go import-path of the versioned clientset to use") + fs.StringVar(&args.ListersPackage, "listers-pkg", args.ListersPackage, + "the Go import-path of the listers to use") + fs.StringVar(&args.SingleClusterVersionedClientSetPackage, "single-cluster-versioned-clientset-pkg", args.SingleClusterVersionedClientSetPackage, + "package path to the generated Kubernetes single-cluster versioned clientset package") + fs.StringVar(&args.SingleClusterInformersPackage, "single-cluster-informers-pkg", args.SingleClusterInformersPackage, + "package path to the generated Kubernetes single-cluster informers package (optional)") + fs.StringVar(&args.SingleClusterListersPackage, "single-cluster-listers-pkg", args.SingleClusterListersPackage, + "package path to the generated Kubernetes single-cluster listers package (optional)") + fs.StringSliceVar(&args.PluralExceptions, "plural-exceptions", args.PluralExceptions, + "list of comma separated plural exception definitions in Type:PluralizedType format") +} + +// Validate checks the given arguments. +func (args *Args) Validate() error { + if len(args.OutputDir) == 0 { + return fmt.Errorf("--output-dir must be specified") + } + if len(args.OutputPackage) == 0 { + return fmt.Errorf("--output-pkg must be specified") + } + if len(args.VersionedClientSetPackage) == 0 { + return fmt.Errorf("--versioned-clientset-pkg must be specified") + } + if len(args.ListersPackage) == 0 { + return fmt.Errorf("--listers-pkg must be specified") + } + if len(args.SingleClusterVersionedClientSetPackage) == 0 { + return fmt.Errorf("--single-cluster-versioned-clientset-pkg must be specified") + } + return nil +} diff --git a/cmd/cluster-informer-gen/generators/factory.go b/cmd/cluster-informer-gen/generators/factory.go new file mode 100644 index 000000000..dcc17925c --- /dev/null +++ b/cmd/cluster-informer-gen/generators/factory.go @@ -0,0 +1,539 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "io" + "path" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + "k8s.io/klog/v2" + + clientgentypes "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" +) + +// factoryGenerator produces a file of listers for a given GroupVersion and +// type. +type factoryGenerator struct { + generator.GoGenerator + outputPackage string + imports namer.ImportTracker + groupVersions map[string]clientgentypes.GroupVersions + gvGoNames map[string]string + clientSetPackage string + internalInterfacesPackage string + filtered bool + singleClusterVersionedClientSetPackage string + singleClusterInformersPackage string +} + +var _ generator.Generator = &factoryGenerator{} + +func (g *factoryGenerator) Filter(_ *generator.Context, _ *types.Type) bool { + if !g.filtered { + g.filtered = true + return true + } + return false +} + +func (g *factoryGenerator) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.outputPackage, g.imports), + } +} + +func (g *factoryGenerator) Imports(_ *generator.Context) (imports []string) { + imports = append(imports, g.imports.ImportLines()...) + return +} + +func (g *factoryGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "{{", "}}") + + klog.V(5).Infof("processing type %v", t) + + gvInterfaces := make(map[string]*types.Type) + gvClusterInterfaces := make(map[string]*types.Type) + gvNewFuncs := make(map[string]*types.Type) + gvNewScopedFuncs := make(map[string]*types.Type) + for groupPkgName := range g.groupVersions { + gvInterfaces[groupPkgName] = c.Universe.Type(types.Name{Package: path.Join(g.outputPackage, groupPkgName), Name: "Interface"}) + gvClusterInterfaces[groupPkgName] = c.Universe.Type(types.Name{Package: path.Join(g.outputPackage, groupPkgName), Name: "ClusterInterface"}) + gvNewFuncs[groupPkgName] = c.Universe.Function(types.Name{Package: path.Join(g.outputPackage, groupPkgName), Name: "New"}) + gvNewScopedFuncs[groupPkgName] = c.Universe.Function(types.Name{Package: path.Join(g.outputPackage, groupPkgName), Name: "NewScoped"}) + } + + genericInformerPkg := g.singleClusterInformersPackage + generateScopedInformerFactory := false + if genericInformerPkg == "" { + genericInformerPkg = g.outputPackage + generateScopedInformerFactory = true + } + + m := map[string]interface{}{ + "cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer), + "scopeableCacheSharedIndexInformer": c.Universe.Type(scopeableCacheSharedIndexInformer), + "cacheTransformFunc": c.Universe.Type(cacheTransformFunc), + "groupVersions": g.groupVersions, + "gvInterfaces": gvInterfaces, + "gvClusterInterfaces": gvClusterInterfaces, + "gvNewFuncs": gvNewFuncs, + "gvNewScopedFuncs": gvNewScopedFuncs, + "gvGoNames": g.gvGoNames, + "interfacesNewInformerFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "NewInformerFunc"}), + "interfacesNewScopedInformerFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "NewScopedInformerFunc"}), + "interfacesTweakListOptionsFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "TweakListOptionsFunc"}), + "informerFactoryInterface": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedInformerFactory"}), + "informerScopedFactoryInterface": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedScopedInformerFactory"}), + "clientSetInterface": c.Universe.Type(types.Name{Package: g.singleClusterVersionedClientSetPackage, Name: "Interface"}), + "clusterClientSetInterface": c.Universe.Type(types.Name{Package: g.clientSetPackage, Name: "ClusterInterface"}), + "genericInformer": c.Universe.Type(types.Name{Package: genericInformerPkg, Name: "GenericInformer"}), + "cacheWaitForCacheSync": c.Universe.Function(cacheWaitForCacheSync), + "reflectType": c.Universe.Type(reflectType), + "reflectTypeOf": c.Universe.Type(reflectTypeOf), + "runtimeObject": c.Universe.Type(runtimeObject), + "schemaGroupVersionResource": c.Universe.Type(schemaGroupVersionResource), + "syncMutex": c.Universe.Type(syncMutex), + "syncWaitGroup": c.Universe.Type(syncWaitGroup), + "timeDuration": c.Universe.Type(timeDuration), + "namespaceAll": c.Universe.Type(metav1NamespaceAll), + "object": c.Universe.Type(metav1Object), + "logicalclusterName": c.Universe.Type(logicalclusterName), + } + + sw.Do(sharedInformerFactoryStruct, m) + sw.Do(sharedInformerFactoryInterface, m) + + if generateScopedInformerFactory { + sw.Do(sharedScopedInformerFactoryStruct, m) + } + + return sw.Error() +} + +var sharedInformerFactoryStruct = ` +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*SharedInformerOptions) *SharedInformerOptions + +type SharedInformerOptions struct { + customResync map[{{.reflectType|raw}}]{{.timeDuration|raw}} + tweakListOptions {{.interfacesTweakListOptionsFunc|raw}} + transform {{.cacheTransformFunc|raw}} + namespace string +} + +type sharedInformerFactory struct { + client {{.clusterClientSetInterface|raw}} + tweakListOptions {{.interfacesTweakListOptionsFunc|raw}} + lock {{.syncMutex|raw}} + defaultResync {{.timeDuration|raw}} + customResync map[{{.reflectType|raw}}]{{.timeDuration|raw}} + transform {{.cacheTransformFunc|raw}} + + informers map[{{.reflectType|raw}}]{{.scopeableCacheSharedIndexInformer|raw}} + // startedInformers is used for tracking which informers have been started. + // This allows Start() to be called multiple times safely. + startedInformers map[{{.reflectType|raw}}]bool + // wg tracks how many goroutines were started. + wg {{.syncWaitGroup|raw}} + // shuttingDown is true when Shutdown has been called. It may still be running + // because it needs to wait for goroutines. + shuttingDown bool +} + +// WithCustomResyncConfig sets a custom resync period for the specified informer types. +func WithCustomResyncConfig(resyncConfig map[{{.object|raw}}]{{.timeDuration|raw}}) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + for k, v := range resyncConfig { + opts.customResync[{{.reflectTypeOf|raw}}(k)] = v + } + return opts + } +} + +// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. +func WithTweakListOptions(tweakListOptions {{.interfacesTweakListOptionsFunc|raw}}) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + opts.tweakListOptions = tweakListOptions + return opts + } +} + +// WithTransform sets a transform on all informers. +func WithTransform(transform {{.cacheTransformFunc|raw}}) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + opts.transform = transform + return opts + } +} + +// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client {{.clusterClientSetInterface|raw}}, defaultResync {{.timeDuration|raw}}) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync) +} + +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +// Deprecated: Please use NewSharedInformerFactoryWithOptions instead +func NewFilteredSharedInformerFactory(client {{.clusterClientSetInterface|raw}}, defaultResync {{.timeDuration|raw}}, tweakListOptions {{.interfacesTweakListOptionsFunc|raw}}) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync, WithTweakListOptions(tweakListOptions)) +} + +// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedInformerFactoryWithOptions(client {{.clusterClientSetInterface|raw}}, defaultResync {{.timeDuration|raw}}, options ...SharedInformerOption) SharedInformerFactory { + factory := &sharedInformerFactory{ + client: client, + defaultResync: defaultResync, + informers: make(map[{{.reflectType|raw}}]{{.scopeableCacheSharedIndexInformer|raw}}), + startedInformers: make(map[{{.reflectType|raw}}]bool), + customResync: make(map[{{.reflectType|raw}}]{{.timeDuration|raw}}), + } + + opts := &SharedInformerOptions{ + customResync: make(map[{{.reflectType|raw}}]{{.timeDuration|raw}}), + } + + // Apply all options + for _, opt := range options { + opts = opt(opts) + } + + // Forward options to the factory + factory.customResync = opts.customResync + factory.tweakListOptions = opts.tweakListOptions + factory.transform = opts.transform + + return factory +} + +func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + if f.shuttingDown { + return + } + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + f.wg.Add(1) + // We need a new variable in each loop iteration, + // otherwise the goroutine would use the loop variable + // and that keeps changing. + informer := informer + go func() { + defer f.wg.Done() + informer.Run(stopCh) + }() + f.startedInformers[informerType] = true + } + } +} + +func (f *sharedInformerFactory) Shutdown() { + f.lock.Lock() + f.shuttingDown = true + f.lock.Unlock() + + // Will return immediately if there is nothing to wait for. + f.wg.Wait() +} + +func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[{{.reflectType|raw}}]bool { + informers := func()map[{{.reflectType|raw}}]{{.scopeableCacheSharedIndexInformer|raw}}{ + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[{{.reflectType|raw}}]{{.scopeableCacheSharedIndexInformer|raw}}{} + for informerType, informer := range f.informers { + if f.startedInformers[informerType] { + informers[informerType] = informer + } + } + return informers + }() + + res := map[{{.reflectType|raw}}]bool{} + for informType, informer := range informers { + res[informType] = {{.cacheWaitForCacheSync|raw}}(stopCh, informer.HasSynced) + } + + return res +} + +// InformerFor returns the ScopeableSharedIndexInformer for obj using an internal client. +func (f *sharedInformerFactory) InformerFor(obj {{.runtimeObject|raw}}, newFunc {{.interfacesNewInformerFunc|raw}}) {{.scopeableCacheSharedIndexInformer|raw}} { + f.lock.Lock() + defer f.lock.Unlock() + + informerType := {{.reflectTypeOf|raw}}(obj) + informer, exists := f.informers[informerType] + if exists { + return informer + } + + resyncPeriod, exists := f.customResync[informerType] + if !exists { + resyncPeriod = f.defaultResync + } + + informer = newFunc(f.client, resyncPeriod) + informer.SetTransform(f.transform) + f.informers[informerType] = informer + + return informer +} +` + +var sharedInformerFactoryInterface = ` +type ScopedDynamicSharedInformerFactory interface { + // ForResource gives generic access to a shared informer of the matching type. + ForResource(resource {{.schemaGroupVersionResource|raw}}) ({{.genericInformer|raw}}, error) + + // Start initializes all requested informers. They are handled in goroutines + // which run until the stop channel gets closed. + Start(stopCh <-chan struct{}) +} + +// SharedInformerFactory provides shared informers for resources in all known +// API group versions. +// +// It is typically used like this: +// +// ctx, cancel := context.Background() +// defer cancel() +// factory := NewSharedInformerFactory(client, resyncPeriod) +// defer factory.WaitForStop() // Returns immediately if nothing was started. +// genericInformer := factory.ForResource(resource) +// typedInformer := factory.SomeAPIGroup().V1().SomeType() +// factory.Start(ctx.Done()) // Start processing these informers. +// synced := factory.WaitForCacheSync(ctx.Done()) +// for v, ok := range synced { +// if !ok { +// fmt.Fprintf(os.Stderr, "caches failed to sync: %v", v) +// return +// } +// } +// +// // Creating informers can also be created after Start, but then +// // Start must be called again: +// anotherGenericInformer := factory.ForResource(resource) +// factory.Start(ctx.Done()) +type SharedInformerFactory interface { + {{.informerFactoryInterface|raw}} + + Cluster({{.logicalclusterName|raw}}) ScopedDynamicSharedInformerFactory + + // Start initializes all requested informers. They are handled in goroutines + // which run until the stop channel gets closed. + // Warning: Start does not block. When run in a go-routine, it will race with a later WaitForCacheSync. + Start(stopCh <-chan struct{}) + + // Shutdown marks a factory as shutting down. At that point no new + // informers can be started anymore and Start will return without + // doing anything. + // + // In addition, Shutdown blocks until all goroutines have terminated. For that + // to happen, the close channel(s) that they were started with must be closed, + // either before Shutdown gets called or while it is waiting. + // + // Shutdown may be called multiple times, even concurrently. All such calls will + // block until all goroutines have terminated. + Shutdown() + + // WaitForCacheSync blocks until all started informers' caches were synced + // or the stop channel gets closed. + WaitForCacheSync(stopCh <-chan struct{}) map[{{.reflectType|raw}}]bool + + // ForResource gives generic access to a shared informer of the matching type. + ForResource(resource {{.schemaGroupVersionResource|raw}}) (GenericClusterInformer, error) + + // InformerFor returns the SharedIndexInformer for obj using an internal + // client. + InformerFor(obj {{.runtimeObject|raw}}, newFunc {{.interfacesNewInformerFunc|raw}}) {{.scopeableCacheSharedIndexInformer|raw}} + + {{range $groupName, $group := .groupVersions}}{{index $.gvGoNames $groupName}}() {{index $.gvClusterInterfaces $groupName|raw}} + {{end}} +} + +{{range $groupPkgName, $group := .groupVersions}} +func (f *sharedInformerFactory) {{index $.gvGoNames $groupPkgName}}() {{index $.gvClusterInterfaces $groupPkgName|raw}} { + return {{index $.gvNewFuncs $groupPkgName|raw}}(f, f.tweakListOptions) +} +{{end}} + +func (f *sharedInformerFactory) Cluster(clusterName {{.logicalclusterName|raw}}) ScopedDynamicSharedInformerFactory { + return &scopedDynamicSharedInformerFactory{ + sharedInformerFactory: f, + clusterName: clusterName, + } +} + +type scopedDynamicSharedInformerFactory struct { + *sharedInformerFactory + clusterName {{.logicalclusterName|raw}} +} + +func (f *scopedDynamicSharedInformerFactory) ForResource(resource {{.schemaGroupVersionResource|raw}}) ({{.genericInformer|raw}}, error) { + clusterInformer, err := f.sharedInformerFactory.ForResource(resource) + if err != nil { + return nil, err + } + return clusterInformer.Cluster(f.clusterName), nil +} + +func (f *scopedDynamicSharedInformerFactory) Start(stopCh <-chan struct{}) { + f.sharedInformerFactory.Start(stopCh) +} +` + +var sharedScopedInformerFactoryStruct = ` +// WithNamespace limits the SharedInformerFactory to the specified namespace. +func WithNamespace(namespace string) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + opts.namespace = namespace + return opts + } +} + +type sharedScopedInformerFactory struct { + client {{.clientSetInterface|raw}} + tweakListOptions {{.interfacesTweakListOptionsFunc|raw}} + lock {{.syncMutex|raw}} + defaultResync {{.timeDuration|raw}} + customResync map[{{.reflectType|raw}}]{{.timeDuration|raw}} + transform {{.cacheTransformFunc|raw}} + namespace string + + informers map[{{.reflectType|raw}}]{{.cacheSharedIndexInformer|raw}} + // startedInformers is used for tracking which informers have been started. + // This allows Start() to be called multiple times safely. + startedInformers map[{{.reflectType|raw}}]bool +} + +// NewSharedScopedInformerFactory constructs a new instance of SharedInformerFactory for some or all namespaces. +func NewSharedScopedInformerFactory(client {{.clientSetInterface|raw}}, defaultResync {{.timeDuration|raw}}, namespace string) SharedScopedInformerFactory { + return NewSharedScopedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace)) +} + +// NewSharedScopedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedScopedInformerFactoryWithOptions(client {{.clientSetInterface|raw}}, defaultResync {{.timeDuration|raw}}, options ...SharedInformerOption) SharedScopedInformerFactory { + factory := &sharedScopedInformerFactory{ + client: client, + defaultResync: defaultResync, + informers: make(map[{{.reflectType|raw}}]{{.cacheSharedIndexInformer|raw}}), + startedInformers: make(map[{{.reflectType|raw}}]bool), + customResync: make(map[{{.reflectType|raw}}]{{.timeDuration|raw}}), + } + + opts := &SharedInformerOptions{ + customResync: make(map[{{.reflectType|raw}}]{{.timeDuration|raw}}), + } + + // Apply all options + for _, opt := range options { + opts = opt(opts) + } + + // Forward options to the factory + factory.customResync = opts.customResync + factory.tweakListOptions = opts.tweakListOptions + factory.namespace = opts.namespace + + return factory +} + +// Start initializes all requested informers. +func (f *sharedScopedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + go informer.Run(stopCh) + f.startedInformers[informerType] = true + } + } +} + +// WaitForCacheSync waits for all started informers' cache were synced. +func (f *sharedScopedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[{{.reflectType|raw}}]bool { + informers := func() map[{{.reflectType|raw}}]{{.cacheSharedIndexInformer|raw}} { + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[{{.reflectType|raw}}]{{.cacheSharedIndexInformer|raw}}{} + for informerType, informer := range f.informers { + if f.startedInformers[informerType] { + informers[informerType] = informer + } + } + return informers + }() + + res := map[{{.reflectType|raw}}]bool{} + for informType, informer := range informers { + res[informType] = {{.cacheWaitForCacheSync|raw}}(stopCh, informer.HasSynced) + } + return res +} + +// InformerFor returns the SharedIndexInformer for obj. +func (f *sharedScopedInformerFactory) InformerFor(obj {{.runtimeObject|raw}}, newFunc {{.interfacesNewScopedInformerFunc|raw}}) {{.cacheSharedIndexInformer|raw}} { + f.lock.Lock() + defer f.lock.Unlock() + + informerType := {{.reflectTypeOf|raw}}(obj) + informer, exists := f.informers[informerType] + if exists { + return informer + } + + resyncPeriod, exists := f.customResync[informerType] + if !exists { + resyncPeriod = f.defaultResync + } + + informer = newFunc(f.client, resyncPeriod) + informer.SetTransform(f.transform) + f.informers[informerType] = informer + + return informer +} + +// SharedScopedInformerFactory provides shared informers for resources in all known +// API group versions, scoped to one workspace. +type SharedScopedInformerFactory interface { + {{.informerScopedFactoryInterface|raw}} + ForResource(resource {{.schemaGroupVersionResource|raw}}) (GenericInformer, error) + WaitForCacheSync(stopCh <-chan struct{}) map[{{.reflectType|raw}}]bool + + {{range $groupName, $group := .groupVersions}}{{index $.gvGoNames $groupName}}() {{index $.gvInterfaces $groupName|raw}} + {{end}} +} + +{{range $groupPkgName, $group := .groupVersions}} +func (f *sharedScopedInformerFactory) {{index $.gvGoNames $groupPkgName}}() {{index $.gvInterfaces $groupPkgName|raw}} { + return {{index $.gvNewScopedFuncs $groupPkgName|raw}}(f, f.namespace, f.tweakListOptions) +} +{{end}} +` diff --git a/cmd/cluster-informer-gen/generators/factoryinterface.go b/cmd/cluster-informer-gen/generators/factoryinterface.go new file mode 100644 index 000000000..c3e180171 --- /dev/null +++ b/cmd/cluster-informer-gen/generators/factoryinterface.go @@ -0,0 +1,109 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "io" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + "k8s.io/klog/v2" +) + +// factoryInterfaceGenerator produces a file of interfaces used to break a dependency cycle for +// informer registration. +type factoryInterfaceGenerator struct { + generator.GoGenerator + outputPackage string + imports namer.ImportTracker + clientSetPackage string + filtered bool + singleClusterVersionedClientSetPackage string + singleClusterInformersPackage string +} + +var _ generator.Generator = &factoryInterfaceGenerator{} + +func (g *factoryInterfaceGenerator) Filter(_ *generator.Context, _ *types.Type) bool { + if !g.filtered { + g.filtered = true + return true + } + return false +} + +func (g *factoryInterfaceGenerator) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.outputPackage, g.imports), + } +} + +func (g *factoryInterfaceGenerator) Imports(_ *generator.Context) (imports []string) { + imports = append(imports, g.imports.ImportLines()...) + return +} + +func (g *factoryInterfaceGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "$", "$") + + klog.V(5).Infof("processing type %v", t) + + m := map[string]interface{}{ + "scopeableCacheSharedIndexInformer": c.Universe.Type(scopeableCacheSharedIndexInformer), + "cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer), + "clusterInterface": c.Universe.Type(types.Name{Package: g.clientSetPackage, Name: "ClusterInterface"}), + "interface": c.Universe.Type(types.Name{Package: g.singleClusterVersionedClientSetPackage, Name: "Interface"}), + "runtimeObject": c.Universe.Type(runtimeObject), + "timeDuration": c.Universe.Type(timeDuration), + "metav1ListOptions": c.Universe.Type(metav1ListOptions), + } + + sw.Do(externalSharedInformerFactoryInterface, m) + + if g.singleClusterInformersPackage == "" { + sw.Do(externalSharedScopedInformerFactoryInterface, m) + } + + return sw.Error() +} + +var externalSharedInformerFactoryInterface = ` +// TweakListOptionsFunc is a function that transforms a $.metav1ListOptions|raw$. +type TweakListOptionsFunc func(*$.metav1ListOptions|raw$) + +// NewInformerFunc takes $.clusterInterface|raw$ and $.timeDuration|raw$ to return a $.scopeableCacheSharedIndexInformer|raw$. +type NewInformerFunc func($.clusterInterface|raw$, $.timeDuration|raw$) $.scopeableCacheSharedIndexInformer|raw$ + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle. +type SharedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj $.runtimeObject|raw$, newFunc NewInformerFunc) $.scopeableCacheSharedIndexInformer|raw$ +} +` + +var externalSharedScopedInformerFactoryInterface = ` +// NewScopedInformerFunc takes $.interface|raw$ and $.timeDuration|raw$ to return a SharedIndexInformer. +type NewScopedInformerFunc func($.interface|raw$, $.timeDuration|raw$) $.cacheSharedIndexInformer|raw$ + +// SharedScopedInformerFactory a small interface to allow for adding an informer without an import cycle. +type SharedScopedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj $.runtimeObject|raw$, newFunc NewScopedInformerFunc) $.cacheSharedIndexInformer|raw$ +} +` diff --git a/cmd/cluster-informer-gen/generators/generic.go b/cmd/cluster-informer-gen/generators/generic.go new file mode 100644 index 000000000..ec0a696e9 --- /dev/null +++ b/cmd/cluster-informer-gen/generators/generic.go @@ -0,0 +1,260 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "io" + "slices" + "strings" + + codegennamer "k8s.io/code-generator/pkg/namer" + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + + clientgentypes "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" +) + +// genericGenerator generates the generic informer. +type genericGenerator struct { + generator.GoGenerator + outputPackage string + imports namer.ImportTracker + groupVersions map[string]clientgentypes.GroupVersions + groupGoNames map[string]string + pluralExceptions map[string]string + typesForGroupVersion map[clientgentypes.GroupVersion][]*types.Type + singleClusterInformersPkg string + filtered bool +} + +var _ generator.Generator = &genericGenerator{} + +func (g *genericGenerator) Filter(_ *generator.Context, _ *types.Type) bool { + if !g.filtered { + g.filtered = true + return true + } + return false +} + +func (g *genericGenerator) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.outputPackage, g.imports), + "allLowercasePlural": namer.NewAllLowercasePluralNamer(g.pluralExceptions), + "publicPlural": namer.NewPublicPluralNamer(g.pluralExceptions), + "resource": codegennamer.NewTagOverrideNamer("resourceName", namer.NewAllLowercasePluralNamer(g.pluralExceptions)), + } +} + +func (g *genericGenerator) Imports(_ *generator.Context) (imports []string) { + imports = append(imports, g.imports.ImportLines()...) + return +} + +type group struct { + GroupGoName string + Name string + Versions []*version +} + +func (g *group) Compare(other group) int { + return strings.Compare(strings.ToLower(g.Name), strings.ToLower(other.Name)) +} + +type version struct { + Name string + GoName string + Resources []*types.Type +} + +func (v *version) Compare(other *version) int { + return strings.Compare(strings.ToLower(v.Name), strings.ToLower(other.Name)) +} + +func (g *genericGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "{{", "}}") + + groups := []group{} + schemeGVs := make(map[*version]*types.Type) + + orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)} + for groupPackageName, groupVersions := range g.groupVersions { + group := group{ + GroupGoName: g.groupGoNames[groupPackageName], + Name: groupVersions.Group.NonEmpty(), + Versions: []*version{}, + } + + for _, v := range groupVersions.Versions { + gv := clientgentypes.GroupVersion{Group: groupVersions.Group, Version: v.Version} + version := &version{ + Name: v.Version.NonEmpty(), + GoName: namer.IC(v.Version.NonEmpty()), + Resources: orderer.OrderTypes(g.typesForGroupVersion[gv]), + } + schemeGVs[version] = c.Universe.Variable(types.Name{Package: g.typesForGroupVersion[gv][0].Name.Package, Name: "SchemeGroupVersion"}) + group.Versions = append(group.Versions, version) + } + + slices.SortFunc(group.Versions, func(a, b *version) int { return a.Compare(b) }) + groups = append(groups, group) + } + + slices.SortFunc(groups, func(a, b group) int { return a.Compare(b) }) + + genericInformerPkg := g.singleClusterInformersPkg + generateInformerInterface := false + if genericInformerPkg == "" { + genericInformerPkg = g.outputPackage + generateInformerInterface = true + } + + m := map[string]any{ + "cacheGenericLister": c.Universe.Type(cacheGenericLister), + "kcpcacheGenericClusterLister": c.Universe.Type(kcpcacheGenericClusterLister), + "kcpcacheNewGenericClusterLister": c.Universe.Type(kcpcacheNewGenericClusterLister), + "cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer), + "scopeableCacheSharedIndexInformer": c.Universe.Type(scopeableCacheSharedIndexInformer), + "fmtErrorf": c.Universe.Type(fmtErrorfFunc), + "contextContext": c.Universe.Type(contextContext), + "groups": groups, + "schemeGVs": schemeGVs, + "schemaGroupResource": c.Universe.Type(schemaGroupResource), + "schemaGroupVersionResource": c.Universe.Type(schemaGroupVersionResource), + "genericInformer": c.Universe.Type(types.Name{Package: genericInformerPkg, Name: "GenericInformer"}), + "generateInformerInterface": generateInformerInterface, + "logicalclusterName": c.Universe.Type(logicalclusterName), + } + + sw.Do(genericClusterInformer, m) + sw.Do(genericInformer, m) + sw.Do(forResource, m) + + if generateInformerInterface { + sw.Do(forScopedResource, m) + } + + return sw.Error() +} + +var genericClusterInformer = ` +type GenericClusterInformer interface { + Cluster({{.logicalclusterName|raw}}) {{.genericInformer|raw}} + ClusterWithContext({{.contextContext|raw}}, {{.logicalclusterName|raw}}) {{.genericInformer|raw}} + Informer() {{.scopeableCacheSharedIndexInformer|raw}} + Lister() {{.kcpcacheGenericClusterLister|raw}} +} +{{ if .generateInformerInterface }} + +type GenericInformer interface { + Informer() {{.cacheSharedIndexInformer|raw}} + Lister() {{.cacheGenericLister|raw}} +} +{{ end }} + +type genericClusterInformer struct { + informer {{.scopeableCacheSharedIndexInformer|raw}} + resource {{.schemaGroupResource|raw}} +} + +// Informer returns the SharedIndexInformer. +func (i *genericClusterInformer) Informer() {{.scopeableCacheSharedIndexInformer|raw}} { + return i.informer +} + +// Lister returns the GenericLister. +func (i *genericClusterInformer) Lister() {{.kcpcacheGenericClusterLister|raw}} { + return {{.kcpcacheNewGenericClusterLister|raw}}(i.Informer().GetIndexer(), i.resource) +} + +// Cluster scopes to a GenericInformer. +func (i *genericClusterInformer) Cluster(clusterName {{.logicalclusterName|raw}}) {{.genericInformer|raw}} { + return &genericInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().ByCluster(clusterName), + } +} + +// ClusterWithContext scopes to a GenericInformer and unregisters all +// handles registered through it once the provided context is canceled. +func (i *genericClusterInformer) ClusterWithContext(ctx {{.contextContext|raw}}, clusterName {{.logicalclusterName|raw}}) {{.genericInformer|raw}} { + return &genericInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().ByCluster(clusterName), + } +} +` + +var genericInformer = ` +type genericInformer struct { + informer {{.cacheSharedIndexInformer|raw}} + lister {{.cacheGenericLister|raw}} +} + +// Informer returns the SharedIndexInformer. +func (i *genericInformer) Informer() {{.cacheSharedIndexInformer|raw}} { + return i.informer +} + +// Lister returns the GenericLister. +func (i *genericInformer) Lister() {{.cacheGenericLister|raw}} { + return i.lister +} +` + +var forResource = ` +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedInformerFactory) ForResource(resource {{.schemaGroupVersionResource|raw}}) (GenericClusterInformer, error) { + switch resource { + {{range $group := .groups -}}{{$GroupGoName := .GroupGoName -}} + {{range $version := .Versions -}} + // Group={{$group.Name}}, Version={{.Name}} + {{range .Resources -}} + case {{index $.schemeGVs $version|raw}}.WithResource("{{.|resource}}"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.{{$GroupGoName}}().{{$version.GoName}}().{{.|publicPlural}}().Informer()}, nil + {{end}} + {{end}} + {{end -}} + } + + return nil, {{.fmtErrorf|raw}}("no informer found for %v", resource) +} +` + +var forScopedResource = ` +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedScopedInformerFactory) ForResource(resource {{.schemaGroupVersionResource|raw}}) ({{.genericInformer|raw}}, error) { + switch resource { + {{range $group := .groups -}}{{$GroupGoName := .GroupGoName -}} + {{range $version := .Versions -}} + // Group={{$group.Name}}, Version={{.Name}} + {{range .Resources -}} + case {{index $.schemeGVs $version|raw}}.WithResource("{{.|resource}}"): + informer := f.{{$GroupGoName}}().{{$version.GoName}}().{{.|publicPlural}}().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + {{end}} + {{end}} + {{end -}} + } + + return nil, {{.fmtErrorf|raw}}("no informer found for %v", resource) +} +` diff --git a/cmd/cluster-informer-gen/generators/groupinterface.go b/cmd/cluster-informer-gen/generators/groupinterface.go new file mode 100644 index 000000000..ef78f50d2 --- /dev/null +++ b/cmd/cluster-informer-gen/generators/groupinterface.go @@ -0,0 +1,157 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "io" + "path" + "strings" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + + clientgentypes "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" +) + +// groupInterfaceGenerator generates the per-group interface file. +type groupInterfaceGenerator struct { + generator.GoGenerator + outputPackage string + imports namer.ImportTracker + groupVersions clientgentypes.GroupVersions + filtered bool + internalInterfacesPackage string + singleClusterInformersPackage string +} + +var _ generator.Generator = &groupInterfaceGenerator{} + +func (g *groupInterfaceGenerator) Filter(_ *generator.Context, _ *types.Type) bool { + if !g.filtered { + g.filtered = true + return true + } + return false +} + +func (g *groupInterfaceGenerator) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.outputPackage, g.imports), + } +} + +func (g *groupInterfaceGenerator) Imports(_ *generator.Context) (imports []string) { + imports = append(imports, g.imports.ImportLines()...) + return +} + +type versionData struct { + Name string + Interface *types.Type + ClusterInterface *types.Type + New *types.Type + NewScoped *types.Type +} + +func (g *groupInterfaceGenerator) GenerateType(c *generator.Context, _ *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "$", "$") + + versions := make([]versionData, 0, len(g.groupVersions.Versions)) + for _, version := range g.groupVersions.Versions { + versionPackage := path.Join(g.outputPackage, strings.ToLower(version.Version.NonEmpty())) + + versions = append(versions, versionData{ + Name: namer.IC(version.Version.NonEmpty()), + Interface: c.Universe.Type(types.Name{Package: versionPackage, Name: "Interface"}), + ClusterInterface: c.Universe.Type(types.Name{Package: versionPackage, Name: "ClusterInterface"}), + New: c.Universe.Function(types.Name{Package: versionPackage, Name: "New"}), + NewScoped: c.Universe.Function(types.Name{Package: versionPackage, Name: "NewScoped"}), + }) + } + + m := map[string]any{ + "interfacesTweakListOptionsFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "TweakListOptionsFunc"}), + "interfacesSharedInformerFactory": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedInformerFactory"}), + "interfacesSharedScopedInformerFactory": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedScopedInformerFactory"}), + "versions": versions, + } + + sw.Do(clusterGroupTemplate, m) + + if g.singleClusterInformersPackage == "" { + sw.Do(groupTemplate, m) + } + + return sw.Error() +} + +var clusterGroupTemplate = ` +// ClusterInterface provides access to each of this group's versions. +type ClusterInterface interface { + $range .versions -$ + // $.Name$ provides access to shared informers for resources in $.Name$. + $.Name$() $.ClusterInterface|raw$ + $end$ +} + +type group struct { + factory $.interfacesSharedInformerFactory|raw$ + tweakListOptions $.interfacesTweakListOptionsFunc|raw$ +} + +// New returns a new ClusterInterface. +func New(f $.interfacesSharedInformerFactory|raw$, tweakListOptions $.interfacesTweakListOptionsFunc|raw$) ClusterInterface { + return &group{factory: f, tweakListOptions: tweakListOptions} +} + +$range .versions$ +// $.Name$ returns a new $.ClusterInterface|raw$. +func (g *group) $.Name$() $.ClusterInterface|raw$ { + return $.New|raw$(g.factory, g.tweakListOptions) +} +$end$ +` + +var groupTemplate = ` +// Interface provides access to each of this group's versions. +type Interface interface { + $range .versions -$ + // $.Name$ provides access to shared informers for resources in $.Name$. + $.Name$() $.Interface|raw$ + $end$ +} + +type scopedGroup struct { + factory $.interfacesSharedScopedInformerFactory|raw$ + tweakListOptions $.interfacesTweakListOptionsFunc|raw$ + namespace string +} + +// New returns a new Interface. +func NewScoped(f $.interfacesSharedScopedInformerFactory|raw$, namespace string, tweakListOptions $.interfacesTweakListOptionsFunc|raw$) Interface { + return &scopedGroup{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +$range .versions$ +// $.Name$ returns a new $.Interface|raw$. +func (g *scopedGroup) $.Name$() $.Interface|raw$ { + return $.NewScoped|raw$(g.factory, g.namespace, g.tweakListOptions) +} +$end$ +` diff --git a/cmd/cluster-informer-gen/generators/informer.go b/cmd/cluster-informer-gen/generators/informer.go new file mode 100644 index 000000000..63d18ccd3 --- /dev/null +++ b/cmd/cluster-informer-gen/generators/informer.go @@ -0,0 +1,321 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "fmt" + "io" + "path" + "strings" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + "k8s.io/klog/v2" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/util" + clientgentypes "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" +) + +// informerGenerator produces a file of listers for a given GroupVersion and +// type. +type informerGenerator struct { + generator.GoGenerator + outputPackage string + groupPkgName string + groupVersion clientgentypes.GroupVersion + groupGoName string + typeToGenerate *types.Type + imports namer.ImportTracker + clientSetPackage string + listersPackage string + internalInterfacesPackage string + singleClusterVersionedClientSetPackage string + singleClusterListersPackage string + singleClusterInformersPackage string +} + +var _ generator.Generator = &informerGenerator{} + +func (g *informerGenerator) Filter(_ *generator.Context, t *types.Type) bool { + return t == g.typeToGenerate +} + +func (g *informerGenerator) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.outputPackage, g.imports), + } +} + +func (g *informerGenerator) Imports(_ *generator.Context) (imports []string) { + imports = append(imports, g.imports.ImportLines()...) + return +} + +func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "$", "$") + + klog.V(5).Infof("processing type %v", t) + + clusterListersPkg := fmt.Sprintf("%s/%s/%s", g.listersPackage, g.groupPkgName, strings.ToLower(g.groupVersion.Version.NonEmpty())) + clientSetInterface := c.Universe.Type(types.Name{Package: g.singleClusterVersionedClientSetPackage, Name: "Interface"}) + clientSetClusterInterface := c.Universe.Type(types.Name{Package: g.clientSetPackage, Name: "ClusterInterface"}) + + informerPkg := g.outputPackage + generateScopedInformer := true + if g.singleClusterInformersPackage != "" { + informerPkg = path.Join(g.singleClusterInformersPackage, g.groupPkgName, strings.ToLower(g.groupVersion.Version.NonEmpty())) + generateScopedInformer = false + } + + listersPkg := g.listersPackage + if g.singleClusterInformersPackage != "" { + listersPkg = g.singleClusterListersPackage + } + listersPkg = path.Join(listersPkg, g.groupPkgName, strings.ToLower(g.groupVersion.Version.NonEmpty())) + + tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) + if err != nil { + return err + } + + m := map[string]interface{}{ + "type": t, + "namespaced": !tags.NonNamespaced, + "cacheIndexers": c.Universe.Type(cacheIndexers), + "cacheListWatch": c.Universe.Type(cacheListWatch), + "cacheMetaNamespaceIndexFunc": c.Universe.Function(cacheMetaNamespaceIndexFunc), + "cacheNamespaceIndex": c.Universe.Variable(cacheNamespaceIndex), + "cacheNewSharedIndexInformer": c.Universe.Function(cacheNewSharedIndexInformer), + "cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer), + "scopeableCacheSharedIndexInformer": c.Universe.Type(scopeableCacheSharedIndexInformer), + "clientSetInterface": clientSetInterface, + "clientSetClusterInterface": clientSetClusterInterface, + "contextBackground": c.Universe.Function(contextBackgroundFunc), + "contextContext": c.Universe.Type(contextContext), + "group": namer.IC(g.groupGoName), + "interfacesTweakListOptionsFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "TweakListOptionsFunc"}), + "interfacesSharedInformerFactory": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedInformerFactory"}), + "interfacesSharedScopedInformerFactory": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedScopedInformerFactory"}), + "lister": c.Universe.Type(types.Name{Package: listersPkg, Name: t.Name.Name + "Lister"}), + "clusterLister": c.Universe.Type(types.Name{Package: clusterListersPkg, Name: t.Name.Name + "ClusterLister"}), + "informerInterface": c.Universe.Type(types.Name{Package: informerPkg, Name: t.Name.Name + "Informer"}), + "newLister": c.Universe.Function(types.Name{Package: listersPkg, Name: "New" + t.Name.Name + "Lister"}), + "newClusterLister": c.Universe.Function(types.Name{Package: clusterListersPkg, Name: "New" + t.Name.Name + "ClusterLister"}), + "kcpcacheClusterIndexName": c.Universe.Function(types.Name{Package: "github.com/kcp-dev/apimachinery/v2/pkg/cache", Name: "ClusterIndexName"}), + "kcpcacheClusterIndexFunc": c.Universe.Function(types.Name{Package: "github.com/kcp-dev/apimachinery/v2/pkg/cache", Name: "ClusterIndexFunc"}), + "kcpcacheClusterAndNamespaceIndexName": c.Universe.Function(types.Name{Package: "github.com/kcp-dev/apimachinery/v2/pkg/cache", Name: "ClusterAndNamespaceIndexName"}), + "kcpcacheClusterAndNamespaceIndexFunc": c.Universe.Function(types.Name{Package: "github.com/kcp-dev/apimachinery/v2/pkg/cache", Name: "ClusterAndNamespaceIndexFunc"}), + "runtimeObject": c.Universe.Type(runtimeObject), + "timeDuration": c.Universe.Type(timeDuration), + "metav1ListOptions": c.Universe.Type(metav1ListOptions), + "version": namer.IC(g.groupVersion.Version.String()), + "watchInterface": c.Universe.Type(watchInterface), + "logicalclusterName": c.Universe.Type(logicalclusterName), + "kcpinformersNewSharedIndexInformer": c.Universe.Type(kcpinformersNewSharedIndexInformer), + } + + sw.Do(typeClusterInformerInterface, m) + sw.Do(typeClusterInformerStruct, m) + sw.Do(typeClusterInformerPublicConstructor, m) + sw.Do(typeFilteredInformerPublicConstructor, m) + sw.Do(typeInformerConstructor, m) + sw.Do(typeInformerInformer, m) + sw.Do(typeInformerLister, m) + sw.Do(typeInformerCluster, m) + sw.Do(typeInformer, m) + + if generateScopedInformer { + sw.Do(typeScopedInformer, m) + } + + return sw.Error() +} + +var typeClusterInformerInterface = ` +// $.type|public$ClusterInformer provides access to a shared informer and lister for +// $.type|publicPlural$. +type $.type|public$ClusterInformer interface { + Cluster($.logicalclusterName|raw$) $.informerInterface|raw$ + ClusterWithContext($.contextContext|raw$, $.logicalclusterName|raw$) $.informerInterface|raw$ + Informer() $.scopeableCacheSharedIndexInformer|raw$ + Lister() $.clusterLister|raw$ +} +` + +var typeClusterInformerStruct = ` +type $.type|private$ClusterInformer struct { + factory $.interfacesSharedInformerFactory|raw$ + tweakListOptions $.interfacesTweakListOptionsFunc|raw$ +} +` + +var typeClusterInformerPublicConstructor = ` +// New$.type|public$ClusterInformer constructs a new informer for $.type|public$ type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func New$.type|public$ClusterInformer(client $.clientSetClusterInterface|raw$, resyncPeriod $.timeDuration|raw$, indexers $.cacheIndexers|raw$) $.scopeableCacheSharedIndexInformer|raw$ { + return NewFiltered$.type|public$ClusterInformer(client, resyncPeriod, indexers, nil) +} +` + +var typeFilteredInformerPublicConstructor = ` +// NewFiltered$.type|public$ClusterInformer constructs a new informer for $.type|public$ type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFiltered$.type|public$ClusterInformer(client $.clientSetClusterInterface|raw$, resyncPeriod $.timeDuration|raw$, indexers $.cacheIndexers|raw$, tweakListOptions $.interfacesTweakListOptionsFunc|raw$) $.scopeableCacheSharedIndexInformer|raw$ { + return $.kcpinformersNewSharedIndexInformer|raw$( + &$.cacheListWatch|raw${ + ListFunc: func(options $.metav1ListOptions|raw$) ($.runtimeObject|raw$, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.$.group$$.version$().$.type|publicPlural$().List($.contextBackground|raw$(), options) + }, + WatchFunc: func(options $.metav1ListOptions|raw$) ($.watchInterface|raw$, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.$.group$$.version$().$.type|publicPlural$().Watch($.contextBackground|raw$(), options) + }, + }, + &$.type|raw${}, + resyncPeriod, + indexers, + ) +} +` + +var typeInformerConstructor = ` +func (i *$.type|private$ClusterInformer) defaultInformer(client $.clientSetClusterInterface|raw$, resyncPeriod $.timeDuration|raw$) $.scopeableCacheSharedIndexInformer|raw$ { + return NewFiltered$.type|public$ClusterInformer(client, resyncPeriod, $.cacheIndexers|raw${ + $.kcpcacheClusterIndexName|raw$: $.kcpcacheClusterIndexFunc|raw$, + $.kcpcacheClusterAndNamespaceIndexName|raw$: $.kcpcacheClusterAndNamespaceIndexFunc|raw$, + }, i.tweakListOptions) +} +` + +var typeInformerInformer = ` +func (i *$.type|private$ClusterInformer) Informer() $.scopeableCacheSharedIndexInformer|raw$ { + return i.factory.InformerFor(&$.type|raw${}, i.defaultInformer) +} +` + +var typeInformerLister = ` +func (i *$.type|private$ClusterInformer) Lister() $.clusterLister|raw$ { + return $.newClusterLister|raw$(i.Informer().GetIndexer()) +} +` + +var typeInformerCluster = ` +func (i *$.type|private$ClusterInformer) Cluster(clusterName $.logicalclusterName|raw$) $.informerInterface|raw$ { + return &$.type|private$Informer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +func (i *$.type|private$ClusterInformer) ClusterWithContext(ctx $.contextContext|raw$, clusterName $.logicalclusterName|raw$) $.informerInterface|raw$ { + return &$.type|private$Informer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} +` + +var typeInformer = ` +type $.type|private$Informer struct { + informer $.cacheSharedIndexInformer|raw$ + lister $.lister|raw$ +} + +func (i *$.type|private$Informer) Informer() $.cacheSharedIndexInformer|raw$ { + return i.informer +} + +func (i *$.type|private$Informer) Lister() $.lister|raw$ { + return i.lister +} +` + +var typeScopedInformer = ` +// $.informerInterface|raw$ provides access to a shared informer and lister for +// $.type|publicPlural$. +type $.informerInterface|raw$ interface { + Informer() $.cacheSharedIndexInformer|raw$ + Lister() $.lister|raw$ +} + +type $.type|private$ScopedInformer struct { + factory $.interfacesSharedScopedInformerFactory|raw$ + tweakListOptions $.interfacesTweakListOptionsFunc|raw$ + $if .namespaced -$ + namespace string + $end -$ +} + +// New$.type|public$Informer constructs a new informer for $.type|public$ type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func New$.type|public$Informer(client $.clientSetInterface|raw$, resyncPeriod $.timeDuration|raw$$if .namespaced$, namespace string$end$, indexers $.cacheIndexers|raw$) $.cacheSharedIndexInformer|raw$ { + return NewFiltered$.type|public$Informer(client, resyncPeriod$if .namespaced$, namespace$end$, indexers, nil) +} + +// NewFiltered$.type|public$Informer constructs a new informer for $.type|public$ type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFiltered$.type|public$Informer(client $.clientSetInterface|raw$, resyncPeriod $.timeDuration|raw$$if .namespaced$, namespace string$end$, indexers $.cacheIndexers|raw$, tweakListOptions $.interfacesTweakListOptionsFunc|raw$) $.cacheSharedIndexInformer|raw$ { + return $.cacheNewSharedIndexInformer|raw$( + &$.cacheListWatch|raw${ + ListFunc: func(options $.metav1ListOptions|raw$) ($.runtimeObject|raw$, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).List($.contextBackground|raw$(), options) + }, + WatchFunc: func(options $.metav1ListOptions|raw$) ($.watchInterface|raw$, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).Watch($.contextBackground|raw$(), options) + }, + }, + &$.type|raw${}, + resyncPeriod, + indexers, + ) +} + +func (i *$.type|private$ScopedInformer) Informer() $.cacheSharedIndexInformer|raw$ { + return i.factory.InformerFor(&$.type|raw${}, i.defaultInformer) +} + +func (i *$.type|private$ScopedInformer) Lister() $.lister|raw$ { + return $.newLister|raw$(i.Informer().GetIndexer()) +} + +func (i *$.type|private$ScopedInformer) defaultInformer(client $.clientSetInterface|raw$, resyncPeriod $.timeDuration|raw$) $.cacheSharedIndexInformer|raw$ { +$if .namespaced -$ + return NewFiltered$.type|public$Informer(client, resyncPeriod, i.namespace, $.cacheIndexers|raw${ + $.cacheNamespaceIndex|raw$: $.cacheMetaNamespaceIndexFunc|raw$, + }, i.tweakListOptions) +$else -$ + return NewFiltered$.type|public$Informer(client, resyncPeriod, $.cacheIndexers|raw${}, i.tweakListOptions) +$end -$ +} +` diff --git a/cmd/cluster-informer-gen/generators/targets.go b/cmd/cluster-informer-gen/generators/targets.go new file mode 100644 index 000000000..ef71b6e05 --- /dev/null +++ b/cmd/cluster-informer-gen/generators/targets.go @@ -0,0 +1,343 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "fmt" + "path" + "path/filepath" + "strings" + + "k8s.io/gengo/v2" + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + "k8s.io/klog/v2" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/util" + clientgentypes "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" + "github.com/kcp-dev/code-generator/v3/cmd/cluster-informer-gen/args" + "github.com/kcp-dev/code-generator/v3/pkg/imports" + genutil "github.com/kcp-dev/code-generator/v3/pkg/util" +) + +// NameSystems returns the name system used by the generators in this package. +func NameSystems(pluralExceptions map[string]string) namer.NameSystems { + return namer.NameSystems{ + "public": namer.NewPublicNamer(0), + "private": namer.NewPrivateNamer(0), + "raw": namer.NewRawNamer("", nil), + "publicPlural": namer.NewPublicPluralNamer(pluralExceptions), + "allLowercasePlural": namer.NewAllLowercasePluralNamer(pluralExceptions), + "lowercaseSingular": &lowercaseSingularNamer{}, + } +} + +// lowercaseSingularNamer implements Namer. +type lowercaseSingularNamer struct{} + +// Name returns t's name in all lowercase. +func (n *lowercaseSingularNamer) Name(t *types.Type) string { + return strings.ToLower(t.Name.Name) +} + +// DefaultNameSystem returns the default name system for ordering the types to be +// processed by the generators in this package. +func DefaultNameSystem() string { + return "public" +} + +// objectMetaForPackage returns the type of ObjectMeta used by package p. +func objectMetaForPackage(pkg *types.Package) (*types.Type, bool, error) { + generate := false + for _, t := range pkg.Types { + if !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient { + continue + } + generate = true + for _, member := range t.Members { + if member.Name == "ObjectMeta" { + return member.Type, isInternal(member), nil + } + } + } + if generate { + return nil, false, fmt.Errorf("unable to find ObjectMeta for any types in package %s", pkg.Path) + } + return nil, false, nil +} + +// isInternal returns true if the tags for a member do not contain a json tag. +func isInternal(m types.Member) bool { + return !strings.Contains(m.Tags, "json") +} + +const subdirForInternalInterfaces = "internalinterfaces" + +// GetTargets makes the client target definition. +func GetTargets(context *generator.Context, args *args.Args) []generator.Target { + boilerplate, err := gengo.GoBoilerplate(args.GoHeaderFile, "", gengo.StdGeneratedBy) + if err != nil { + klog.Fatalf("Failed loading boilerplate: %v", err) + } + + externalVersionOutputDir := args.OutputDir + externalVersionOutputPkg := args.OutputPackage + + targetList := make([]generator.Target, 0) + typesForGroupVersion := make(map[clientgentypes.GroupVersion][]*types.Type) + + externalGroupVersions := make(map[string]clientgentypes.GroupVersions) + groupGoNames := make(map[string]string) + for _, inputPkg := range context.Inputs { + pkg := context.Universe.Package(inputPkg) + + objectMeta, _, err := objectMetaForPackage(pkg) + if err != nil { + klog.Fatal(err) + } + if objectMeta == nil { + // no types in this package had genclient + continue + } + + var ( + gv clientgentypes.GroupVersion + targetGroupVersions map[string]clientgentypes.GroupVersions + ) + + gv.Group = clientgentypes.Group(path.Base(path.Dir(pkg.Path))) + gv.Version = clientgentypes.Version(path.Base(pkg.Path)) + targetGroupVersions = externalGroupVersions + + groupPkgName := gv.Group.NonEmpty() + gvPkg := path.Clean(pkg.Path) + + // If there's a comment of the form "// +groupName=somegroup" or + // "// +groupName=somegroup.foo.bar.io", use the first field (somegroup) as the name of the + // group when generating. + if override := gengo.ExtractCommentTags("+", pkg.Comments)["groupName"]; override != nil { //nolint:staticcheck + gv.Group = clientgentypes.Group(override[0]) + } + + // If there's a comment of the form "// +groupGoName=SomeUniqueShortName", use that as + // the Go group identifier in CamelCase. It defaults + groupGoNames[groupPkgName] = namer.IC(strings.Split(gv.Group.NonEmpty(), ".")[0]) + if override := gengo.ExtractCommentTags("+", pkg.Comments)["groupGoName"]; override != nil { //nolint:staticcheck + groupGoNames[groupPkgName] = namer.IC(override[0]) + } + + var typesToGenerate []*types.Type + for _, t := range pkg.Types { + tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) + if !tags.GenerateClient || tags.NoVerbs || !tags.HasVerb("list") || !tags.HasVerb("watch") { + continue + } + + typesToGenerate = append(typesToGenerate, t) + typesForGroupVersion[gv] = append(typesForGroupVersion[gv], t) + } + if len(typesToGenerate) == 0 { + continue + } + + groupVersionsEntry, ok := targetGroupVersions[groupPkgName] + if !ok { + groupVersionsEntry = clientgentypes.GroupVersions{ + PackageName: groupPkgName, + Group: gv.Group, + } + } + groupVersionsEntry.Versions = append(groupVersionsEntry.Versions, clientgentypes.PackageVersion{Version: gv.Version, Package: gvPkg}) + targetGroupVersions[groupPkgName] = groupVersionsEntry + + orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)} + typesToGenerate = orderer.OrderTypes(typesToGenerate) + + outputDirBase := externalVersionOutputDir + outputPkgBase := externalVersionOutputPkg + clientSetPkg := args.VersionedClientSetPackage + + targetList = append(targetList, versionTarget(outputDirBase, outputPkgBase, groupPkgName, gv, groupGoNames[groupPkgName], boilerplate, typesToGenerate, clientSetPkg, args)) + } + + if len(externalGroupVersions) != 0 { + targetList = append(targetList, + factoryInterfaceTarget(externalVersionOutputDir, externalVersionOutputPkg, boilerplate, args), + factoryTarget(externalVersionOutputDir, externalVersionOutputPkg, boilerplate, groupGoNames, genutil.PluralExceptionListToMapOrDie(args.PluralExceptions), externalGroupVersions, typesForGroupVersion, args), + ) + + for _, gvs := range externalGroupVersions { + targetList = append(targetList, groupTarget(externalVersionOutputDir, externalVersionOutputPkg, gvs, boilerplate, args)) + } + } + + return targetList +} + +func factoryTarget( + outputDirBase, outputPkgBase string, boilerplate []byte, groupGoNames, pluralExceptions map[string]string, + groupVersions map[string]clientgentypes.GroupVersions, typesForGroupVersion map[clientgentypes.GroupVersion][]*types.Type, + args *args.Args, +) generator.Target { + return &generator.SimpleTarget{ + PkgName: path.Base(outputDirBase), + PkgPath: outputPkgBase, + PkgDir: outputDirBase, + HeaderComment: boilerplate, + GeneratorsFunc: func(_ *generator.Context) (generators []generator.Generator) { + generators = append(generators, + &factoryGenerator{ + GoGenerator: generator.GoGenerator{ + OutputFilename: "factory.go", + }, + outputPackage: outputPkgBase, + imports: imports.NewImportTrackerForPackage(outputPkgBase), + groupVersions: groupVersions, + clientSetPackage: args.VersionedClientSetPackage, + internalInterfacesPackage: path.Join(outputPkgBase, subdirForInternalInterfaces), + gvGoNames: groupGoNames, + singleClusterVersionedClientSetPackage: args.SingleClusterVersionedClientSetPackage, + singleClusterInformersPackage: args.SingleClusterInformersPackage, + }, + &genericGenerator{ + GoGenerator: generator.GoGenerator{ + OutputFilename: "generic.go", + }, + outputPackage: outputPkgBase, + imports: imports.NewImportTrackerForPackage(outputPkgBase), + groupVersions: groupVersions, + pluralExceptions: pluralExceptions, + typesForGroupVersion: typesForGroupVersion, + groupGoNames: groupGoNames, + singleClusterInformersPkg: args.SingleClusterInformersPackage, + }) + + return generators + }, + } +} + +func factoryInterfaceTarget(outputDirBase, outputPkgBase string, boilerplate []byte, args *args.Args) generator.Target { + outputDir := filepath.Join(outputDirBase, subdirForInternalInterfaces) + outputPkg := path.Join(outputPkgBase, subdirForInternalInterfaces) + + return &generator.SimpleTarget{ + PkgName: path.Base(outputDir), + PkgPath: outputPkg, + PkgDir: outputDir, + HeaderComment: boilerplate, + GeneratorsFunc: func(_ *generator.Context) (generators []generator.Generator) { + generators = append(generators, &factoryInterfaceGenerator{ + GoGenerator: generator.GoGenerator{ + OutputFilename: "factory_interfaces.go", + }, + outputPackage: outputPkg, + imports: imports.NewImportTrackerForPackage(outputPkg), + clientSetPackage: args.VersionedClientSetPackage, + singleClusterVersionedClientSetPackage: args.SingleClusterVersionedClientSetPackage, + singleClusterInformersPackage: args.SingleClusterInformersPackage, + }) + + return generators + }, + } +} + +func groupTarget(outputDirBase, outputPackageBase string, groupVersions clientgentypes.GroupVersions, boilerplate []byte, args *args.Args) generator.Target { + outputDir := filepath.Join(outputDirBase, groupVersions.PackageName) + outputPkg := path.Join(outputPackageBase, groupVersions.PackageName) + groupPkgName := strings.Split(groupVersions.PackageName, ".")[0] + + return &generator.SimpleTarget{ + PkgName: groupPkgName, + PkgPath: outputPkg, + PkgDir: outputDir, + HeaderComment: boilerplate, + GeneratorsFunc: func(_ *generator.Context) (generators []generator.Generator) { + generators = append(generators, &groupInterfaceGenerator{ + GoGenerator: generator.GoGenerator{ + OutputFilename: "interface.go", + }, + outputPackage: outputPkg, + groupVersions: groupVersions, + imports: imports.NewImportTrackerForPackage(outputPkg), + internalInterfacesPackage: path.Join(outputPackageBase, subdirForInternalInterfaces), + singleClusterInformersPackage: args.SingleClusterInformersPackage, + }) + return generators + }, + FilterFunc: func(c *generator.Context, t *types.Type) bool { + tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) + return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("watch") + }, + } +} + +func versionTarget( + outputDirBase, outputPkgBase string, groupPkgName string, gv clientgentypes.GroupVersion, groupGoName string, + boilerplate []byte, typesToGenerate []*types.Type, clientSetPackage string, args *args.Args, +) generator.Target { + subdir := []string{groupPkgName, strings.ToLower(gv.Version.NonEmpty())} + outputDir := filepath.Join(outputDirBase, filepath.Join(subdir...)) + outputPkg := path.Join(outputPkgBase, path.Join(subdir...)) + + return &generator.SimpleTarget{ + PkgName: strings.ToLower(gv.Version.NonEmpty()), + PkgPath: outputPkg, + PkgDir: outputDir, + HeaderComment: boilerplate, + GeneratorsFunc: func(_ *generator.Context) (generators []generator.Generator) { + generators = append(generators, &versionInterfaceGenerator{ + GoGenerator: generator.GoGenerator{ + OutputFilename: "interface.go", + }, + outputPackage: outputPkg, + imports: imports.NewImportTrackerForPackage(outputPkg), + types: typesToGenerate, + internalInterfacesPackage: path.Join(outputPkgBase, subdirForInternalInterfaces), + singleClusterInformersPackage: args.SingleClusterInformersPackage, + }) + + for _, t := range typesToGenerate { + generators = append(generators, &informerGenerator{ + GoGenerator: generator.GoGenerator{ + OutputFilename: strings.ToLower(t.Name.Name) + ".go", + }, + outputPackage: outputPkg, + groupPkgName: groupPkgName, + groupVersion: gv, + groupGoName: groupGoName, + typeToGenerate: t, + imports: imports.NewImportTrackerForPackage(outputPkg), + clientSetPackage: clientSetPackage, + listersPackage: args.ListersPackage, + internalInterfacesPackage: path.Join(outputPkgBase, subdirForInternalInterfaces), + singleClusterListersPackage: args.SingleClusterListersPackage, + singleClusterInformersPackage: args.SingleClusterInformersPackage, + singleClusterVersionedClientSetPackage: args.SingleClusterVersionedClientSetPackage, + }) + } + return generators + }, + FilterFunc: func(c *generator.Context, t *types.Type) bool { + tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) + return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("watch") + }, + } +} diff --git a/cmd/cluster-informer-gen/generators/types.go b/cmd/cluster-informer-gen/generators/types.go new file mode 100644 index 000000000..96fadda0c --- /dev/null +++ b/cmd/cluster-informer-gen/generators/types.go @@ -0,0 +1,52 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import "k8s.io/gengo/v2/types" + +var ( + cacheGenericLister = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "GenericLister"} + cacheIndexers = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "Indexers"} + cacheListWatch = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "ListWatch"} + cacheMetaNamespaceIndexFunc = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "MetaNamespaceIndexFunc"} + cacheNamespaceIndex = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "NamespaceIndex"} + cacheNewSharedIndexInformer = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "NewSharedIndexInformer"} + cacheSharedIndexInformer = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "SharedIndexInformer"} + cacheWaitForCacheSync = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "WaitForCacheSync"} + scopeableCacheSharedIndexInformer = types.Name{Package: "github.com/kcp-dev/apimachinery/v2/pkg/cache", Name: "ScopeableSharedIndexInformer"} + kcpcacheGenericClusterLister = types.Name{Package: "github.com/kcp-dev/apimachinery/v2/pkg/cache", Name: "GenericClusterLister"} + kcpcacheNewGenericClusterLister = types.Name{Package: "github.com/kcp-dev/apimachinery/v2/pkg/cache", Name: "NewGenericClusterLister"} + kcpinformersNewSharedIndexInformer = types.Name{Package: "github.com/kcp-dev/apimachinery/v2/third_party/informers", Name: "NewSharedIndexInformer"} + cacheTransformFunc = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "TransformFunc"} + contextContext = types.Name{Package: "context", Name: "Context"} + contextBackgroundFunc = types.Name{Package: "context", Name: "Background"} + fmtErrorfFunc = types.Name{Package: "fmt", Name: "Errorf"} + reflectType = types.Name{Package: "reflect", Name: "Type"} + reflectTypeOf = types.Name{Package: "reflect", Name: "TypeOf"} + runtimeObject = types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "Object"} + schemaGroupResource = types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupResource"} + schemaGroupVersionResource = types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersionResource"} + syncMutex = types.Name{Package: "sync", Name: "Mutex"} + syncWaitGroup = types.Name{Package: "sync", Name: "WaitGroup"} + timeDuration = types.Name{Package: "time", Name: "Duration"} + metav1ListOptions = types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"} + metav1NamespaceAll = types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "NamespaceAll"} + metav1Object = types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "Object"} + watchInterface = types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"} + logicalclusterName = types.Name{Package: "github.com/kcp-dev/logicalcluster/v3", Name: "Name"} +) diff --git a/cmd/cluster-informer-gen/generators/versioninterface.go b/cmd/cluster-informer-gen/generators/versioninterface.go new file mode 100644 index 000000000..882682045 --- /dev/null +++ b/cmd/cluster-informer-gen/generators/versioninterface.go @@ -0,0 +1,145 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "io" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/util" +) + +// versionInterfaceGenerator generates the per-version interface file. +type versionInterfaceGenerator struct { + generator.GoGenerator + outputPackage string + imports namer.ImportTracker + types []*types.Type + filtered bool + internalInterfacesPackage string + singleClusterInformersPackage string +} + +var _ generator.Generator = &versionInterfaceGenerator{} + +func (g *versionInterfaceGenerator) Filter(_ *generator.Context, _ *types.Type) bool { + if !g.filtered { + g.filtered = true + return true + } + return false +} + +func (g *versionInterfaceGenerator) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.outputPackage, g.imports), + } +} + +func (g *versionInterfaceGenerator) Imports(_ *generator.Context) (imports []string) { + imports = append(imports, g.imports.ImportLines()...) + return +} + +func (g *versionInterfaceGenerator) GenerateType(c *generator.Context, _ *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "$", "$") + + m := map[string]any{ + "interfacesTweakListOptionsFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "TweakListOptionsFunc"}), + "interfacesSharedInformerFactory": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedInformerFactory"}), + "interfacesSharedScopedInformerFactory": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedScopedInformerFactory"}), + "types": g.types, + } + + sw.Do(clusterVersionTemplate, m) + for _, typeDef := range g.types { + m["type"] = typeDef + sw.Do(clusterVersionFuncTemplate, m) + } + + if g.singleClusterInformersPackage == "" { + sw.Do(versionTemplate, m) + for _, typeDef := range g.types { + tags, err := util.ParseClientGenTags(append(typeDef.SecondClosestCommentLines, typeDef.CommentLines...)) + if err != nil { + return err + } + m["namespaced"] = !tags.NonNamespaced + m["type"] = typeDef + sw.Do(versionFuncTemplate, m) + } + } + + return sw.Error() +} + +var clusterVersionTemplate = ` +type ClusterInterface interface { + $range .types -$ + // $.|publicPlural$ returns a $.|public$ClusterInformer. + $.|publicPlural$() $.|public$ClusterInformer + $end$ +} + +type version struct { + factory $.interfacesSharedInformerFactory|raw$ + tweakListOptions $.interfacesTweakListOptionsFunc|raw$ +} + +// New returns a new Interface. +func New(f $.interfacesSharedInformerFactory|raw$, tweakListOptions $.interfacesTweakListOptionsFunc|raw$) ClusterInterface { + return &version{factory: f, tweakListOptions: tweakListOptions} +} +` + +var clusterVersionFuncTemplate = ` +// $.type|publicPlural$ returns a $.type|public$ClusterInformer. +func (v *version) $.type|publicPlural$() $.type|public$ClusterInformer { + return &$.type|private$ClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} +` + +var versionTemplate = ` +type Interface interface { + $range .types -$ + // $.|publicPlural$ returns a $.|public$Informer. + $.|publicPlural$() $.|public$Informer + $end$ +} + +type scopedVersion struct { + factory $.interfacesSharedScopedInformerFactory|raw$ + tweakListOptions $.interfacesTweakListOptionsFunc|raw$ + namespace string +} + +// New returns a new Interface. +func NewScoped(f $.interfacesSharedScopedInformerFactory|raw$, namespace string, tweakListOptions $.interfacesTweakListOptionsFunc|raw$) Interface { + return &scopedVersion{factory: f, tweakListOptions: tweakListOptions} +} +` + +var versionFuncTemplate = ` +// $.type|publicPlural$ returns a $.type|public$Informer. +func (v *scopedVersion) $.type|publicPlural$() $.type|public$Informer { + return &$.type|private$ScopedInformer{factory: v.factory$if .namespaced$, namespace: v.namespace$end$, tweakListOptions: v.tweakListOptions} +} +` diff --git a/cmd/cluster-informer-gen/main.go b/cmd/cluster-informer-gen/main.go new file mode 100644 index 000000000..c2970ee29 --- /dev/null +++ b/cmd/cluster-informer-gen/main.go @@ -0,0 +1,62 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "flag" + + "github.com/spf13/pflag" + + "k8s.io/gengo/v2" + "k8s.io/gengo/v2/generator" + "k8s.io/klog/v2" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-informer-gen/args" + "github.com/kcp-dev/code-generator/v3/cmd/cluster-informer-gen/generators" + "github.com/kcp-dev/code-generator/v3/pkg/util" +) + +func main() { + klog.InitFlags(nil) + args := args.New() + + args.AddFlags(pflag.CommandLine) + _ = flag.Set("logtostderr", "true") + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + + if err := args.Validate(); err != nil { + klog.Fatalf("Error: %v", err) + } + + myTargets := func(context *generator.Context) []generator.Target { + return generators.GetTargets(context, args) + } + + // Run it. + if err := gengo.Execute( + generators.NameSystems(util.PluralExceptionListToMapOrDie(args.PluralExceptions)), + generators.DefaultNameSystem(), + myTargets, + gengo.StdBuildTag, + pflag.Args(), + ); err != nil { + klog.Fatalf("Error: %v", err) + } + klog.V(2).Info("Completed successfully.") +} diff --git a/cmd/cluster-lister-gen/args/args.go b/cmd/cluster-lister-gen/args/args.go new file mode 100644 index 000000000..158fd5778 --- /dev/null +++ b/cmd/cluster-lister-gen/args/args.go @@ -0,0 +1,68 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package args + +import ( + "fmt" + + "github.com/spf13/pflag" +) + +// Args is used by the gengo framework to pass args specific to this generator. +type Args struct { + OutputDir string // must be a directory path + OutputPackage string // must be a Go import-path + GoHeaderFile string + + // PluralExceptions specify list of exceptions used when pluralizing certain types. + // For example 'Endpoints:Endpoints', otherwise the pluralizer will generate 'Endpointes'. + PluralExceptions []string + + // Path to the generated Kubernetes single-cluster listers package. + SingleClusterListersPackage string +} + +// New returns default arguments for the generator. +func New() *Args { + return &Args{} +} + +// AddFlags add the generator flags to the flag set. +func (args *Args) AddFlags(fs *pflag.FlagSet) { + fs.StringVar(&args.OutputDir, "output-dir", "", + "the base directory under which to generate results") + fs.StringVar(&args.OutputPackage, "output-pkg", "", + "the base Go import-path under which to generate results") + fs.StringSliceVar(&args.PluralExceptions, "plural-exceptions", args.PluralExceptions, + "list of comma separated plural exception definitions in Type:PluralizedType format") + fs.StringVar(&args.SingleClusterListersPackage, "single-cluster-listers-pkg", args.SingleClusterListersPackage, + "package path to the generated Kubernetes single-cluster listers package (optional)") + fs.StringVar(&args.GoHeaderFile, "go-header-file", "", + "the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year") +} + +// Validate checks the given arguments. +func (args *Args) Validate() error { + if len(args.OutputDir) == 0 { + return fmt.Errorf("--output-dir must be specified") + } + if len(args.OutputPackage) == 0 { + return fmt.Errorf("--output-pkg must be specified") + } + return nil +} diff --git a/cmd/cluster-lister-gen/generators/expansion.go b/cmd/cluster-lister-gen/generators/expansion.go new file mode 100644 index 000000000..8d881643c --- /dev/null +++ b/cmd/cluster-lister-gen/generators/expansion.go @@ -0,0 +1,91 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "io" + "os" + "path/filepath" + "strings" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/types" + "k8s.io/klog/v2" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/util" +) + +// expansionGenerator produces a file for a expansion interfaces. +type expansionGenerator struct { + generator.GoGenerator + outputPath string + types []*types.Type + singleClusterListersPkg string +} + +// We only want to call GenerateType() once per group. +func (g *expansionGenerator) Filter(_ *generator.Context, t *types.Type) bool { + return t == g.types[0] +} + +func (g *expansionGenerator) GenerateType(c *generator.Context, _ *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "$", "$") + for _, t := range g.types { + manualFile := filepath.Join(g.outputPath, strings.ToLower(t.Name.Name+"_expansion.go")) + if _, err := os.Stat(manualFile); err == nil { + klog.V(4).Infof("file %q exists, not generating", manualFile) + } else if os.IsNotExist(err) { + tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) + if err != nil { + return err + } + + sw.Do(clusterListerExpansionInterfaceTemplate, t) + // no external interface means we generated our own, so we also generate our own expansion for it + if g.singleClusterListersPkg == "" { + sw.Do(listerExpansionInterfaceTemplate, t) + + if !tags.NonNamespaced { + sw.Do(namespaceListerExpansionInterfaceTemplate, t) + } + } + } else { + return err + } + } + + return sw.Error() +} + +var clusterListerExpansionInterfaceTemplate = ` +// $.|public$ClusterListerExpansion allows custom methods to be added to +// $.|public$ClusterLister. +type $.|public$ClusterListerExpansion interface {} +` + +var listerExpansionInterfaceTemplate = ` +// $.|public$ListerExpansion allows custom methods to be added to +// $.|public$Lister. +type $.|public$ListerExpansion interface {} +` + +var namespaceListerExpansionInterfaceTemplate = ` +// $.|public$NamespaceListerExpansion allows custom methods to be added to +// $.|public$NamespaceLister. +type $.|public$NamespaceListerExpansion interface {} +` diff --git a/cmd/cluster-lister-gen/generators/lister.go b/cmd/cluster-lister-gen/generators/lister.go new file mode 100644 index 000000000..255971c67 --- /dev/null +++ b/cmd/cluster-lister-gen/generators/lister.go @@ -0,0 +1,410 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package generators + +import ( + "fmt" + "io" + "path" + "path/filepath" + "strings" + + "k8s.io/gengo/v2" + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + "k8s.io/klog/v2" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/generators/util" + clientgentypes "github.com/kcp-dev/code-generator/v3/cmd/cluster-client-gen/types" + "github.com/kcp-dev/code-generator/v3/cmd/cluster-lister-gen/args" + "github.com/kcp-dev/code-generator/v3/pkg/imports" +) + +// NameSystems returns the name system used by the generators in this package. +func NameSystems(pluralExceptions map[string]string) namer.NameSystems { + return namer.NameSystems{ + "public": namer.NewPublicNamer(0), + "private": namer.NewPrivateNamer(0), + "raw": namer.NewRawNamer("", nil), + "publicPlural": namer.NewPublicPluralNamer(pluralExceptions), + "lowercaseSingular": &lowercaseSingularNamer{}, + } +} + +// lowercaseSingularNamer implements Namer. +type lowercaseSingularNamer struct{} + +// Name returns t's name in all lowercase. +func (n *lowercaseSingularNamer) Name(t *types.Type) string { + return strings.ToLower(t.Name.Name) +} + +// DefaultNameSystem returns the default name system for ordering the types to be +// processed by the generators in this package. +func DefaultNameSystem() string { + return "public" +} + +// GetTargets makes the client target definition. +func GetTargets(context *generator.Context, args *args.Args) []generator.Target { + boilerplate, err := gengo.GoBoilerplate(args.GoHeaderFile, "", gengo.StdGeneratedBy) + if err != nil { + klog.Fatalf("Failed loading boilerplate: %v", err) + } + + targetList := make([]generator.Target, 0) + for _, inputPkg := range context.Inputs { + p := context.Universe.Package(inputPkg) + + objectMeta, internal, err := objectMetaForPackage(p) + if err != nil { + klog.Fatal(err) + } + if objectMeta == nil { + // no types in this package had genclient + continue + } + + var gv clientgentypes.GroupVersion + + if internal { + lastSlash := strings.LastIndex(p.Path, "/") + if lastSlash == -1 { + klog.Fatalf("error constructing internal group version for package %q", p.Path) + } + gv.Group = clientgentypes.Group(p.Path[lastSlash+1:]) + } else { + parts := strings.Split(p.Path, "/") + gv.Group = clientgentypes.Group(parts[len(parts)-2]) + gv.Version = clientgentypes.Version(parts[len(parts)-1]) + } + groupPackageName := strings.ToLower(gv.Group.NonEmpty()) + + // If there's a comment of the form "// +groupName=somegroup" or + // "// +groupName=somegroup.foo.bar.io", use the first field (somegroup) as the name of the + // group when generating. + if override := gengo.ExtractCommentTags("+", p.Comments)["groupName"]; override != nil { //nolint:staticcheck + gv.Group = clientgentypes.Group(strings.SplitN(override[0], ".", 2)[0]) + } + + var typesToGenerate []*types.Type + for _, t := range p.Types { + tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) + if !tags.GenerateClient || !tags.HasVerb("list") || !tags.HasVerb("get") { + continue + } + typesToGenerate = append(typesToGenerate, t) + } + if len(typesToGenerate) == 0 { + continue + } + orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)} + typesToGenerate = orderer.OrderTypes(typesToGenerate) + + subdir := []string{groupPackageName, strings.ToLower(gv.Version.NonEmpty())} + outputDir := filepath.Join(args.OutputDir, filepath.Join(subdir...)) + outputPkg := path.Join(args.OutputPackage, path.Join(subdir...)) + + targetList = append(targetList, &generator.SimpleTarget{ + PkgName: strings.ToLower(gv.Version.NonEmpty()), + PkgPath: outputPkg, + PkgDir: outputDir, + HeaderComment: boilerplate, + FilterFunc: func(_ *generator.Context, t *types.Type) bool { + tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) + return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("get") + }, + GeneratorsFunc: func(_ *generator.Context) (generators []generator.Generator) { + var singleClusterListersPkg string + if args.SingleClusterListersPackage != "" { + singleClusterListersPkg = path.Join(args.SingleClusterListersPackage, groupPackageName, string(gv.Version)) + } + + generators = append(generators, &expansionGenerator{ + GoGenerator: generator.GoGenerator{ + OutputFilename: "expansion_generated.go", + }, + outputPath: outputDir, + types: typesToGenerate, + singleClusterListersPkg: singleClusterListersPkg, + }) + + for _, t := range typesToGenerate { + generators = append(generators, &listerGenerator{ + GoGenerator: generator.GoGenerator{ + OutputFilename: strings.ToLower(t.Name.Name) + ".go", + }, + outputPackage: outputPkg, + groupVersion: gv, + typeToGenerate: t, + imports: imports.NewImportTrackerForPackage(outputPkg), + singleClusterListersPkg: singleClusterListersPkg, + }) + } + + return generators + }, + }) + } + + return targetList +} + +// objectMetaForPackage returns the type of ObjectMeta used by package p. +func objectMetaForPackage(p *types.Package) (*types.Type, bool, error) { + generatingForPackage := false + for _, t := range p.Types { + // filter out types which don't have genclient. + if !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient { + continue + } + generatingForPackage = true + for _, member := range t.Members { + if member.Name == "ObjectMeta" { + return member.Type, isInternal(member), nil + } + } + } + if generatingForPackage { + return nil, false, fmt.Errorf("unable to find ObjectMeta for any types in package %s", p.Path) + } + return nil, false, nil +} + +// isInternal returns true if the tags for a member do not contain a json tag. +func isInternal(m types.Member) bool { + return !strings.Contains(m.Tags, "json") +} + +// listerGenerator produces a file of listers for a given GroupVersion and type. +type listerGenerator struct { + generator.GoGenerator + outputPackage string + groupVersion clientgentypes.GroupVersion + typeToGenerate *types.Type + imports namer.ImportTracker + singleClusterListersPkg string +} + +var _ generator.Generator = &listerGenerator{} + +func (g *listerGenerator) Filter(_ *generator.Context, t *types.Type) bool { + return t == g.typeToGenerate +} + +func (g *listerGenerator) Namers(_ *generator.Context) namer.NameSystems { + return namer.NameSystems{ + "raw": namer.NewRawNamer(g.outputPackage, g.imports), + } +} + +func (g *listerGenerator) Imports(_ *generator.Context) (imports []string) { + imports = append(imports, g.imports.ImportLines()...) + imports = append(imports, + `"github.com/kcp-dev/logicalcluster/v3"`, + `kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers"`, + `"k8s.io/apimachinery/pkg/labels"`, + `"k8s.io/client-go/tools/cache"`, + ) + return +} + +func (g *listerGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { + sw := generator.NewSnippetWriter(w, c, "$", "$") + + interfacesPkg := g.singleClusterListersPkg + if interfacesPkg == "" { + // This will make gengo not output an import statement at all for any references. + interfacesPkg = g.outputPackage + } + + tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) + if err != nil { + return err + } + + klog.V(5).Infof("processing type %v", t) + m := map[string]interface{}{ + "type": t, + "namespaced": !tags.NonNamespaced, + "Resource": c.Universe.Function(types.Name{Package: t.Name.Package, Name: "Resource"}), + "listerInterface": c.Universe.Type(types.Name{Package: interfacesPkg, Name: t.Name.Name + "Lister"}), + "namespaceListerInterface": c.Universe.Type(types.Name{Package: interfacesPkg, Name: t.Name.Name + "NamespaceLister"}), + } + + sw.Do(typeClusterListerInterface, m) + sw.Do(typeListerStruct, m) + + // no external interfaces provided, so we generate our own + if g.singleClusterListersPkg == "" { + sw.Do(typeListerInterface, m) + } + + if !tags.NonNamespaced { + sw.Do(typeListerNamespaceLister, m) + sw.Do(namespaceListerStruct, m) + + if g.singleClusterListersPkg == "" { + sw.Do(namespaceListerInterface, m) + } + } + + sw.Do(scopedLister, m) + + return sw.Error() +} + +var typeClusterListerInterface = ` +// $.type|public$ClusterLister helps list $.type|publicPlural$ across all workspaces, +// or scope down to a $.type|public$Lister for one workspace. +// All objects returned here must be treated as read-only. +type $.type|public$ClusterLister interface { + // List lists all $.type|publicPlural$ in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*$.type|raw$, err error) + // Cluster returns a lister that can list and get $.type|publicPlural$ in one workspace. + Cluster(clusterName logicalcluster.Name) $.listerInterface|raw$ + $.type|public$ClusterListerExpansion +} + +// $.type|private$ClusterLister implements the $.type|public$ClusterLister interface. +type $.type|private$ClusterLister struct { + kcplisters.ResourceClusterIndexer[*$.type|raw$] +} + +var _ $.type|public$ClusterLister = new($.type|private$ClusterLister) + +// New$.type|public$ClusterLister returns a new $.type|public$ClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +$if .namespaced -$ +// - has the kcpcache.ClusterAndNamespaceIndex as an index +$end -$ +func New$.type|public$ClusterLister(indexer cache.Indexer) $.type|public$ClusterLister { + return &$.type|private$ClusterLister{ + kcplisters.NewCluster[*$.type|raw$](indexer, $.Resource|raw$("$.type|lowercaseSingular$")), + } +} + +// Cluster scopes the lister to one workspace, allowing users to list and get $.type|publicPlural$. +func (l *$.type|private$ClusterLister) Cluster(clusterName logicalcluster.Name) $.listerInterface|raw$ { + return &$.type|private$Lister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } +} +` + +var typeListerInterface = ` +$if .namespaced -$ +// $.listerInterface|raw$ can list $.type|publicPlural$ across all namespaces, or scope down to a $.namespaceListerInterface|raw$ for one namespace. +$else -$ +// $.listerInterface|raw$ can list all $.type|publicPlural$, or get one in particular. +$end -$ +// All objects returned here must be treated as read-only. +type $.listerInterface|raw$ interface { + // List lists all $.type|publicPlural$ in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*$.type|raw$, err error) +$if .namespaced -$ + // $.type|publicPlural$ returns a lister that can list and get $.type|publicPlural$ in one workspace and namespace. + $.type|publicPlural$(namespace string) $.namespaceListerInterface|raw$ +$else -$ + // Get retrieves the $.type|public$ from the indexer for a given workspace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*$.type|raw$, error) +$end -$ + $.type|public$ListerExpansion +} +` + +var typeListerStruct = ` +// $.type|private$Lister can list all $.type|publicPlural$ inside a workspace +// or scope down to a $.namespaceListerInterface|raw$ for one namespace. +type $.type|private$Lister struct { + kcplisters.ResourceIndexer[*$.type|raw$] +} + +var _ $.listerInterface|raw$ = new($.type|private$Lister) +` + +var typeListerNamespaceLister = ` +// $.type|publicPlural$ returns an object that can list and get $.type|publicPlural$ in one namespace. +func (l *$.type|private$Lister) $.type|publicPlural$(namespace string) $.namespaceListerInterface|raw$ { + return &$.type|private$NamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} +` + +var namespaceListerInterface = ` +// $.namespaceListerInterface|raw$ can list all $.type|publicPlural$, or get one in particular. +// All objects returned here must be treated as read-only. +type $.namespaceListerInterface|raw$ interface { + // List lists all $.type|publicPlural$ in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*$.type|raw$, err error) + // Get retrieves the $.type|public$ from the indexer for a given workspace, namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*$.type|raw$, error) + $.type|public$NamespaceListerExpansion +} +` + +var namespaceListerStruct = ` +// $.type|private$NamespaceLister implements the $.namespaceListerInterface|raw$ +// interface. +type $.type|private$NamespaceLister struct { + kcplisters.ResourceIndexer[*$.type|raw$] +} + +var _ $.namespaceListerInterface|raw$ = new($.type|private$NamespaceLister) +` + +var scopedLister = ` +// New$.type|public$Lister returns a new $.type|public$Lister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +$if .namespaced -$ +// - has the kcpcache.ClusterAndNamespaceIndex as an index +$end -$ +func New$.type|public$Lister(indexer cache.Indexer) $.listerInterface|raw$ { + return &$.type|private$Lister{ + kcplisters.New[*$.type|raw$](indexer, $.Resource|raw$("$.type|lowercaseSingular$")), + } +} + +// $.type|private$ScopedLister can list all $.type|publicPlural$ inside a workspace +// or scope down to a $.namespaceListerInterface|raw$$if .namespaced$ for one namespace$end$. +type $.type|private$ScopedLister struct { + kcplisters.ResourceIndexer[*$.type|raw$] +} + +$if .namespaced -$ +// $.type|publicPlural$ returns an object that can list and get $.type|publicPlural$ in one namespace. +func (l *$.type|private$ScopedLister) $.type|publicPlural$(namespace string) $.listerInterface|raw$ { + return &$.type|private$Lister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} +$end -$ +` diff --git a/cmd/cluster-lister-gen/main.go b/cmd/cluster-lister-gen/main.go new file mode 100644 index 000000000..4005dadc6 --- /dev/null +++ b/cmd/cluster-lister-gen/main.go @@ -0,0 +1,62 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "flag" + + "github.com/spf13/pflag" + + "k8s.io/gengo/v2" + "k8s.io/gengo/v2/generator" + "k8s.io/klog/v2" + + "github.com/kcp-dev/code-generator/v3/cmd/cluster-lister-gen/args" + "github.com/kcp-dev/code-generator/v3/cmd/cluster-lister-gen/generators" + "github.com/kcp-dev/code-generator/v3/pkg/util" +) + +func main() { + klog.InitFlags(nil) + args := args.New() + + args.AddFlags(pflag.CommandLine) + _ = flag.Set("logtostderr", "true") + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + + if err := args.Validate(); err != nil { + klog.Fatalf("Error: %v", err) + } + + myTargets := func(context *generator.Context) []generator.Target { + return generators.GetTargets(context, args) + } + + // Run it. + if err := gengo.Execute( + generators.NameSystems(util.PluralExceptionListToMapOrDie(args.PluralExceptions)), + generators.DefaultNameSystem(), + myTargets, + gengo.StdBuildTag, + pflag.Args(), + ); err != nil { + klog.Fatalf("Error: %v", err) + } + klog.V(2).Info("Completed successfully.") +} diff --git a/code-of-conduct.md b/code-of-conduct.md new file mode 100644 index 000000000..8dd5798f1 --- /dev/null +++ b/code-of-conduct.md @@ -0,0 +1,83 @@ +This project is following the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md). + +# Community Code of Conduct + +As contributors, maintainers, and participants in the CNCF community, and in the interest of fostering +an open and welcoming community, we pledge to respect all people who participate or contribute +through reporting issues, posting feature requests, updating documentation, +submitting pull requests or patches, attending conferences or events, or engaging in other community or project activities. + +We are committed to making participation in the CNCF community a harassment-free experience for everyone, regardless of age, body size, caste, disability, ethnicity, level of experience, family status, gender, gender identity and expression, marital status, military or veteran status, nationality, personal appearance, race, religion, sexual orientation, socieconomic status, tribe, or any other dimension of diversity. + +## Scope + +This code of conduct applies: +* within project and community spaces, +* in other spaces when an individual CNCF community participant's words or actions are directed at or are about a CNCF project, the CNCF community, or another CNCF community participant. + +### CNCF Events + +CNCF events that are produced by the Linux Foundation with professional events staff are governed by the Linux Foundation [Events Code of Conduct](https://events.linuxfoundation.org/code-of-conduct/) available on the event page. This is designed to be used in conjunction with the CNCF Code of Conduct. + +## Our Standards + +The CNCF Community is open, inclusive and respectful. Every member of our community has the right to have their identity respected. + +Examples of behavior that contributes to a positive environment include but are not limited to: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community +* Using welcoming and inclusive language + + +Examples of unacceptable behavior include but are not limited to: + +* The use of sexualized language or imagery +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment in any form +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Violence, threatening violence, or encouraging others to engage in violent behavior +* Stalking or following someone without their consent +* Unwelcome physical contact +* Unwelcome sexual or romantic attention or advances +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +The following behaviors are also prohibited: +* Providing knowingly false or misleading information in connection with a Code of Conduct investigation or otherwise intentionally tampering with an investigation. +* Retaliating against a person because they reported an incident or provided information about an incident as a witness. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. +By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect +of managing a CNCF project. +Project maintainers who do not follow or enforce the Code of Conduct may be temporarily or permanently removed from the project team. + +## Reporting + +For incidents occurring in the Kubernetes community, contact the [Kubernetes Code of Conduct Committee](https://git.k8s.io/community/committee-code-of-conduct) via . You can expect a response within three business days. + +For other projects, or for incidents that are project-agnostic or impact multiple CNCF projects, please contact the [CNCF Code of Conduct Committee](https://www.cncf.io/conduct/committee/) via conduct@cncf.io. Alternatively, you can contact any of the individual members of the [CNCF Code of Conduct Committee](https://www.cncf.io/conduct/committee/) to submit your report. For more detailed instructions on how to submit a report, including how to submit a report anonymously, please see our [Incident Resolution Procedures](https://www.cncf.io/conduct/procedures/). You can expect a response within three business days. + +For incidents occurring at CNCF event that is produced by the Linux Foundation, please contact eventconduct@cncf.io. + +## Enforcement + +Upon review and investigation of a reported incident, the CoC response team that has jurisdiction will determine what action is appropriate based on this Code of Conduct and its related documentation. + +For information about which Code of Conduct incidents are handled by project leadership, which incidents are handled by the CNCF Code of Conduct Committee, and which incidents are handled by the Linux Foundation (including its events team), see our [Jurisdiction Policy](https://www.cncf.io/conduct/jurisdiction/). + +## Amendments + +Consistent with the CNCF Charter, any substantive changes to this Code of Conduct must be approved by the Technical Oversight Committee. + +## Acknowledgements + +This Code of Conduct is adapted from the Contributor Covenant +(http://contributor-covenant.org), version 2.0 available at +http://contributor-covenant.org/version/2/0/code_of_conduct/ diff --git a/examples/go.mod b/examples/go.mod index 9159f1c4a..811ee8bab 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -1,55 +1,58 @@ module acme.corp -go 1.19 +go 1.24.0 replace acme.corp/pkg => ./pkg require ( - github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0 - github.com/kcp-dev/client-go v0.0.0-20221215092857-c1e5154a9825 - github.com/kcp-dev/logicalcluster/v3 v3.0.0 - k8s.io/apimachinery v0.25.2 - k8s.io/client-go v0.25.2 - sigs.k8s.io/structured-merge-diff/v4 v4.2.3 + github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250717064240-78e565b4a69a + github.com/kcp-dev/client-go v0.0.0-20250721105427-d4a93d7c5fc9 + github.com/kcp-dev/logicalcluster/v3 v3.0.5 + k8s.io/apimachinery v0.33.3 + k8s.io/client-go v0.33.3 + sigs.k8s.io/structured-merge-diff/v4 v4.6.0 ) require ( - github.com/PuerkitoBio/purell v1.1.1 // indirect - github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/emicklei/go-restful/v3 v3.8.0 // indirect - github.com/evanphx/json-patch v4.12.0+incompatible // indirect - github.com/go-logr/logr v1.2.3 // indirect - github.com/go-openapi/jsonpointer v0.19.5 // indirect - github.com/go-openapi/jsonreference v0.19.5 // indirect - github.com/go-openapi/swag v0.19.14 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/emicklei/go-restful/v3 v3.12.1 // indirect + github.com/fxamacker/cbor/v2 v2.7.0 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-openapi/jsonpointer v0.21.0 // indirect + github.com/go-openapi/jsonreference v0.21.0 // indirect + github.com/go-openapi/swag v0.23.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/protobuf v1.5.2 // indirect - github.com/google/gnostic v0.5.7-v3refs // indirect - github.com/google/go-cmp v0.5.8 // indirect - github.com/google/gofuzz v1.1.0 // indirect + github.com/google/gnostic-models v0.6.9 // indirect + github.com/google/go-cmp v0.7.0 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/mailru/easyjson v0.7.6 // indirect + github.com/mailru/easyjson v0.9.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect - golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect - golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect - golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect - golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect - golang.org/x/text v0.3.7 // indirect - golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect - google.golang.org/appengine v1.6.7 // indirect - google.golang.org/protobuf v1.28.0 // indirect + github.com/x448/float16 v0.8.4 // indirect + golang.org/x/net v0.40.0 // indirect + golang.org/x/oauth2 v0.29.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/term v0.32.0 // indirect + golang.org/x/text v0.25.0 // indirect + golang.org/x/time v0.11.0 // indirect + google.golang.org/protobuf v1.36.5 // indirect + gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/api v0.25.2 // indirect - k8s.io/klog/v2 v2.70.1 // indirect - k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect - k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect - sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect - sigs.k8s.io/yaml v1.3.0 // indirect + k8s.io/api v0.33.3 // indirect + k8s.io/klog/v2 v2.130.1 // indirect + k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect + k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect + sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect + sigs.k8s.io/randfill v1.0.0 // indirect + sigs.k8s.io/yaml v1.4.0 // indirect +) + +replace ( + github.com/kcp-dev/apimachinery/v2 => ../../apimachinery + github.com/kcp-dev/client-go => ../../client-go ) diff --git a/examples/go.sum b/examples/go.sum index e7fbb2fd1..5db6d6687 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -1,162 +1,47 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= -cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= -cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= -cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= -cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= -cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= -cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= -cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= -cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= -cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= -cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= -cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= -cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= -cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= -cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= -cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= -cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= -cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= -cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= -cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= -cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= -cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= -cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= -cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= -cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= -cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= -cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= -cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= -cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= -cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= -dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= -github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= -github.com/emicklei/go-restful/v3 v3.8.0 h1:eCZ8ulSerjdAiaNpF7GxXIE7ZCMo1moN1qX+S609eVw= -github.com/emicklei/go-restful/v3 v3.8.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= -github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= -github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= -github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= -github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/jsonreference v0.19.5 h1:1WJP/wi4OjB4iV8KVbH73rQaoialJrqv8gitZLxGLtM= -github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg= -github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng= -github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU= +github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= +github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ= +github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= +github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= +github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= -github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/gnostic v0.5.7-v3refs h1:FhTMOKj2VhjpouxvWJAV1TL304uMlb9zcDqkl6cEI54= -github.com/google/gnostic v0.5.7-v3refs/go.mod h1:73MKFl6jIHelAJNaBGFzt3SPtZULs9dYrGFt8OiIsHQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gnostic-models v0.6.9 h1:MU/8wDLif2qCXZmzncUQ/BOfxWfthHi63KqpoNbWqVw= +github.com/google/gnostic-models v0.6.9/go.mod h1:CiWsm0s6BSQd1hRn8/QmxqB6BesYcbSZxsz9b0KuDBw= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= -github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= -github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= -github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo= +github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0 h1:fb+3CdDlxvnK+o1wm3IcDbD+MJndMUa17EUGqYORsvg= -github.com/kcp-dev/apimachinery/v2 v2.0.0-alpha.0/go.mod h1:dn1hXHMY9E6JbyOGa0qXt1Dq4akd/jHMZOpFhJoX7q4= -github.com/kcp-dev/client-go v0.0.0-20221215092857-c1e5154a9825 h1:7jgn80ujqiaAFKTZ3AE5Lx5mOwyUdDLeJzn9MhZGA3E= -github.com/kcp-dev/client-go v0.0.0-20221215092857-c1e5154a9825/go.mod h1:sj0r6sAHNsfEpA37uLTVGZj9TMQQWjBXk4rbpcIDZ7U= -github.com/kcp-dev/logicalcluster/v3 v3.0.0 h1:tH6M2NuA11eLMsxii9IDOGo64X8B+P3e3pC6W2oEsx8= -github.com/kcp-dev/logicalcluster/v3 v3.0.0/go.mod h1:6rb68Tntup98cRr9+50rvSDxUbfqrC1yQ/T6RiZcSgA= +github.com/kcp-dev/logicalcluster/v3 v3.0.5 h1:JbYakokb+5Uinz09oTXomSUJVQsqfxEvU4RyHUYxHOU= +github.com/kcp-dev/logicalcluster/v3 v3.0.5/go.mod h1:EWBUBxdr49fUB1cLMO4nOdBWmYifLbP1LfoL20KkXYY= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= -github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4= +github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -164,325 +49,99 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/onsi/ginkgo/v2 v2.1.6 h1:Fx2POJZfKRQcM1pH49qSZiYeu319wji004qX+GDovrU= -github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q= +github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM= +github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo= +github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4= +github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= +github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= +github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= +github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= -github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= +github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= -go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= -golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= -golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= -golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= -golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= -golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 h1:RerP+noqYHUQ8CMRcPlC2nvTa4dcBIjegkuWdcUDuqg= -golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= +golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= +golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98= +golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg= +golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44= -golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= +golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= +golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0= +golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= -golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc= +golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= -google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= -google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= -google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= -google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= -google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= -google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= +google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4= +gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -k8s.io/api v0.25.2 h1:v6G8RyFcwf0HR5jQGIAYlvtRNrxMJQG1xJzaSeVnIS8= -k8s.io/api v0.25.2/go.mod h1:qP1Rn4sCVFwx/xIhe+we2cwBLTXNcheRyYXwajonhy0= -k8s.io/apimachinery v0.25.2 h1:WbxfAjCx+AeN8Ilp9joWnyJ6xu9OMeS/fsfjK/5zaQs= -k8s.io/apimachinery v0.25.2/go.mod h1:hqqA1X0bsgsxI6dXsJ4HnNTBOmJNxyPp8dw3u2fSHwA= -k8s.io/client-go v0.25.2 h1:SUPp9p5CwM0yXGQrwYurw9LWz+YtMwhWd0GqOsSiefo= -k8s.io/client-go v0.25.2/go.mod h1:i7cNU7N+yGQmJkewcRD2+Vuj4iz7b30kI8OcL3horQ4= -k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= -k8s.io/klog/v2 v2.70.1 h1:7aaoSdahviPmR+XkS7FyxlkkXs6tHISSG03RxleQAVQ= -k8s.io/klog/v2 v2.70.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= -k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 h1:MQ8BAZPZlWk3S9K4a9NCkIFQtZShWqoha7snGixVgEA= -k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1/go.mod h1:C/N6wCaBHeBHkHUesQOQy2/MZqGgMAFPqGsGQLdbZBU= -k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed h1:jAne/RjBTyawwAy0utX5eqigAwz/lQhTmy+Hr/Cpue4= -k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= -rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= -sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k= -sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= -sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE= -sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= +k8s.io/api v0.33.3 h1:SRd5t//hhkI1buzxb288fy2xvjubstenEKL9K51KBI8= +k8s.io/api v0.33.3/go.mod h1:01Y/iLUjNBM3TAvypct7DIj0M0NIZc+PzAHCIo0CYGE= +k8s.io/apimachinery v0.33.3 h1:4ZSrmNa0c/ZpZJhAgRdcsFcZOw1PQU1bALVQ0B3I5LA= +k8s.io/apimachinery v0.33.3/go.mod h1:BHW0YOu7n22fFv/JkYOEfkUYNRN0fj0BlvMFWA7b+SM= +k8s.io/client-go v0.33.3 h1:M5AfDnKfYmVJif92ngN532gFqakcGi6RvaOF16efrpA= +k8s.io/client-go v0.33.3/go.mod h1:luqKBQggEf3shbxHY4uVENAxrDISLOarxpTKMiUuujg= +k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= +k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= +k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff h1:/usPimJzUKKu+m+TE36gUyGcf03XZEP0ZIKgKj35LS4= +k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff/go.mod h1:5jIi+8yX4RIb8wk3XwBo5Pq2ccx4FP10ohkbSKCZoK8= +k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 h1:hwvWFiBzdWw1FhfY1FooPn3kzWuJ8tmbZBHi4zVsl1Y= +k8s.io/utils v0.0.0-20250604170112-4c0f3b243397/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE= +sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg= +sigs.k8s.io/randfill v0.0.0-20250304075658-069ef1bbf016/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= +sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU= +sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= +sigs.k8s.io/structured-merge-diff/v4 v4.6.0 h1:IUA9nvMmnKWcj5jl84xn+T5MnlZKThmUW1TdblaLVAc= +sigs.k8s.io/structured-merge-diff/v4 v4.6.0/go.mod h1:dDy58f92j70zLsuZVuUX5Wp9vtxXpaZnkPGWeqDfCps= +sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= +sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/examples/pkg/apis/example/doc.go b/examples/pkg/apis/example/doc.go index 3238abfd6..327effea5 100644 --- a/examples/pkg/apis/example/doc.go +++ b/examples/pkg/apis/example/doc.go @@ -15,4 +15,5 @@ limitations under the License. */ // +k8s:deepcopy-gen=package,register +// +groupName=example.dev package example diff --git a/examples/pkg/apis/example/register.go b/examples/pkg/apis/example/register.go index e6989b217..1a2eb513c 100644 --- a/examples/pkg/apis/example/register.go +++ b/examples/pkg/apis/example/register.go @@ -24,15 +24,15 @@ import ( const GroupName = "example.dev" -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/example/v1/doc.go b/examples/pkg/apis/example/v1/doc.go index 907f7bc67..d854351c1 100644 --- a/examples/pkg/apis/example/v1/doc.go +++ b/examples/pkg/apis/example/v1/doc.go @@ -15,4 +15,5 @@ limitations under the License. */ // +k8s:deepcopy-gen=package,register +// +groupName=example.dev package v1 diff --git a/examples/pkg/apis/example/v1/register.go b/examples/pkg/apis/example/v1/register.go index c1db9897f..27e0756af 100644 --- a/examples/pkg/apis/example/v1/register.go +++ b/examples/pkg/apis/example/v1/register.go @@ -17,22 +17,22 @@ limitations under the License. package v1 import ( + "acme.corp/pkg/apis/example" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - - "acme.corp/pkg/apis/example" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/example/v1/zz_generated.deepcopy.go b/examples/pkg/apis/example/v1/zz_generated.deepcopy.go index aa79613c5..e07544edb 100644 --- a/examples/pkg/apis/example/v1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/example/v1/zz_generated.deepcopy.go @@ -1,12 +1,28 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Code generated by controller-gen. DO NOT EDIT. +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/runtime" + runtime "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -15,6 +31,7 @@ func (in *ClusterTestType) DeepCopyInto(out *ClusterTestType) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Status = in.Status + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestType. @@ -47,6 +64,7 @@ func (in *ClusterTestTypeList) DeepCopyInto(out *ClusterTestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeList. @@ -70,6 +88,7 @@ func (in *ClusterTestTypeList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterTestTypeStatus) DeepCopyInto(out *ClusterTestTypeStatus) { *out = *in + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeStatus. @@ -87,6 +106,7 @@ func (in *Field) DeepCopyInto(out *Field) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Field. @@ -119,6 +139,7 @@ func (in *FieldList) DeepCopyInto(out *FieldList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FieldList. @@ -149,6 +170,7 @@ func (in *TestType) DeepCopyInto(out *TestType) { *out = make([]string, len(*in)) copy(*out, *in) } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. @@ -181,6 +203,7 @@ func (in *TestTypeList) DeepCopyInto(out *TestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. @@ -206,6 +229,7 @@ func (in *WithoutVerbType) DeepCopyInto(out *WithoutVerbType) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WithoutVerbType. diff --git a/examples/pkg/apis/example/v1alpha1/doc.go b/examples/pkg/apis/example/v1alpha1/doc.go index bfb9b5875..b44cedfa2 100644 --- a/examples/pkg/apis/example/v1alpha1/doc.go +++ b/examples/pkg/apis/example/v1alpha1/doc.go @@ -15,4 +15,5 @@ limitations under the License. */ // +k8s:deepcopy-gen=package,register +// +groupName=example.dev package v1alpha1 diff --git a/examples/pkg/apis/example/v1alpha1/register.go b/examples/pkg/apis/example/v1alpha1/register.go index 6cf9e5b3a..8392abea1 100644 --- a/examples/pkg/apis/example/v1alpha1/register.go +++ b/examples/pkg/apis/example/v1alpha1/register.go @@ -17,22 +17,22 @@ limitations under the License. package v1alpha1 import ( + "acme.corp/pkg/apis/example" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - - "acme.corp/pkg/apis/example" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1alpha1"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/example/v1alpha1/zz_generated.deepcopy.go b/examples/pkg/apis/example/v1alpha1/zz_generated.deepcopy.go index 642cfb305..685ce1a3c 100644 --- a/examples/pkg/apis/example/v1alpha1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/example/v1alpha1/zz_generated.deepcopy.go @@ -1,12 +1,28 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Code generated by controller-gen. DO NOT EDIT. +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. package v1alpha1 import ( - "k8s.io/apimachinery/pkg/runtime" + runtime "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -15,6 +31,7 @@ func (in *ClusterTestType) DeepCopyInto(out *ClusterTestType) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Status = in.Status + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestType. @@ -47,6 +64,7 @@ func (in *ClusterTestTypeList) DeepCopyInto(out *ClusterTestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeList. @@ -70,6 +88,7 @@ func (in *ClusterTestTypeList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterTestTypeStatus) DeepCopyInto(out *ClusterTestTypeStatus) { *out = *in + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeStatus. @@ -92,6 +111,7 @@ func (in *TestType) DeepCopyInto(out *TestType) { *out = make([]string, len(*in)) copy(*out, *in) } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. @@ -124,6 +144,7 @@ func (in *TestTypeList) DeepCopyInto(out *TestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. diff --git a/examples/pkg/apis/example/v1beta1/doc.go b/examples/pkg/apis/example/v1beta1/doc.go index 4898c9788..34d9b9dc3 100644 --- a/examples/pkg/apis/example/v1beta1/doc.go +++ b/examples/pkg/apis/example/v1beta1/doc.go @@ -15,4 +15,5 @@ limitations under the License. */ // +k8s:deepcopy-gen=package,register +// +groupName=example.dev package v1beta1 diff --git a/examples/pkg/apis/example/v1beta1/register.go b/examples/pkg/apis/example/v1beta1/register.go index 352a5037b..5f1b4133e 100644 --- a/examples/pkg/apis/example/v1beta1/register.go +++ b/examples/pkg/apis/example/v1beta1/register.go @@ -17,22 +17,22 @@ limitations under the License. package v1beta1 import ( + "acme.corp/pkg/apis/example" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - - "acme.corp/pkg/apis/example" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1beta1"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/example/v1beta1/types.go b/examples/pkg/apis/example/v1beta1/types.go index e153e6401..8445bdd08 100644 --- a/examples/pkg/apis/example/v1beta1/types.go +++ b/examples/pkg/apis/example/v1beta1/types.go @@ -19,7 +19,6 @@ package v1beta1 import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" // +genclient -// +genclient:skipVerbs=list,watch // TestType is a top-level type. A client is created for it. // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type TestType struct { diff --git a/examples/pkg/apis/example/v1beta1/zz_generated.deepcopy.go b/examples/pkg/apis/example/v1beta1/zz_generated.deepcopy.go index 57f394bfb..dd6744c7b 100644 --- a/examples/pkg/apis/example/v1beta1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/example/v1beta1/zz_generated.deepcopy.go @@ -1,12 +1,28 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Code generated by controller-gen. DO NOT EDIT. +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. package v1beta1 import ( - "k8s.io/apimachinery/pkg/runtime" + runtime "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -15,6 +31,7 @@ func (in *ClusterTestType) DeepCopyInto(out *ClusterTestType) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Status = in.Status + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestType. @@ -47,6 +64,7 @@ func (in *ClusterTestTypeList) DeepCopyInto(out *ClusterTestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeList. @@ -70,6 +88,7 @@ func (in *ClusterTestTypeList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterTestTypeStatus) DeepCopyInto(out *ClusterTestTypeStatus) { *out = *in + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeStatus. @@ -92,6 +111,7 @@ func (in *TestType) DeepCopyInto(out *TestType) { *out = make([]string, len(*in)) copy(*out, *in) } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. @@ -124,6 +144,7 @@ func (in *TestTypeList) DeepCopyInto(out *TestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. diff --git a/examples/pkg/apis/example/v2/doc.go b/examples/pkg/apis/example/v2/doc.go index 352a93762..90917aae7 100644 --- a/examples/pkg/apis/example/v2/doc.go +++ b/examples/pkg/apis/example/v2/doc.go @@ -15,4 +15,5 @@ limitations under the License. */ // +k8s:deepcopy-gen=package,register +// +groupName=example.dev package v2 diff --git a/examples/pkg/apis/example/v2/register.go b/examples/pkg/apis/example/v2/register.go index 907ec623f..36ed89745 100644 --- a/examples/pkg/apis/example/v2/register.go +++ b/examples/pkg/apis/example/v2/register.go @@ -17,22 +17,22 @@ limitations under the License. package v2 import ( + "acme.corp/pkg/apis/example" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - - "acme.corp/pkg/apis/example" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v2"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/example/v2/zz_generated.deepcopy.go b/examples/pkg/apis/example/v2/zz_generated.deepcopy.go index 4efb1f8e1..bf1fbeb5e 100644 --- a/examples/pkg/apis/example/v2/zz_generated.deepcopy.go +++ b/examples/pkg/apis/example/v2/zz_generated.deepcopy.go @@ -1,12 +1,28 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Code generated by controller-gen. DO NOT EDIT. +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. package v2 import ( - "k8s.io/apimachinery/pkg/runtime" + runtime "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -15,6 +31,7 @@ func (in *ClusterTestType) DeepCopyInto(out *ClusterTestType) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Status = in.Status + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestType. @@ -47,6 +64,7 @@ func (in *ClusterTestTypeList) DeepCopyInto(out *ClusterTestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeList. @@ -70,6 +88,7 @@ func (in *ClusterTestTypeList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterTestTypeStatus) DeepCopyInto(out *ClusterTestTypeStatus) { *out = *in + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeStatus. @@ -92,6 +111,7 @@ func (in *TestType) DeepCopyInto(out *TestType) { *out = make([]string, len(*in)) copy(*out, *in) } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. @@ -124,6 +144,7 @@ func (in *TestTypeList) DeepCopyInto(out *TestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. diff --git a/examples/pkg/apis/example/zz_generated.deepcopy.go b/examples/pkg/apis/example/zz_generated.deepcopy.go index 6838afd25..58611b208 100644 --- a/examples/pkg/apis/example/zz_generated.deepcopy.go +++ b/examples/pkg/apis/example/zz_generated.deepcopy.go @@ -1,12 +1,28 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Code generated by controller-gen. DO NOT EDIT. +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. package example import ( - "k8s.io/apimachinery/pkg/runtime" + runtime "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -15,6 +31,7 @@ func (in *ClusterTestType) DeepCopyInto(out *ClusterTestType) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Status = in.Status + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestType. @@ -47,6 +64,7 @@ func (in *ClusterTestTypeList) DeepCopyInto(out *ClusterTestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeList. @@ -70,6 +88,7 @@ func (in *ClusterTestTypeList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterTestTypeStatus) DeepCopyInto(out *ClusterTestTypeStatus) { *out = *in + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeStatus. @@ -87,6 +106,7 @@ func (in *Field) DeepCopyInto(out *Field) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Field. @@ -119,6 +139,7 @@ func (in *FieldList) DeepCopyInto(out *FieldList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FieldList. @@ -149,6 +170,7 @@ func (in *TestType) DeepCopyInto(out *TestType) { *out = make([]string, len(*in)) copy(*out, *in) } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. @@ -181,6 +203,7 @@ func (in *TestTypeList) DeepCopyInto(out *TestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. @@ -206,6 +229,7 @@ func (in *WithoutVerbType) DeepCopyInto(out *WithoutVerbType) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WithoutVerbType. diff --git a/examples/pkg/apis/example3/register.go b/examples/pkg/apis/example3/register.go index a529c01f1..885ca8587 100644 --- a/examples/pkg/apis/example3/register.go +++ b/examples/pkg/apis/example3/register.go @@ -17,5 +17,5 @@ limitations under the License. package example const ( - GroupName = "example3.dev" + GroupName = "example3.some.corp" ) diff --git a/examples/pkg/apis/example3/v1/register.go b/examples/pkg/apis/example3/v1/register.go index 44c15dfd1..a996e6acb 100644 --- a/examples/pkg/apis/example3/v1/register.go +++ b/examples/pkg/apis/example3/v1/register.go @@ -17,22 +17,22 @@ limitations under the License. package v1 import ( + example "acme.corp/pkg/apis/example3" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - - example "acme.corp/pkg/apis/example3" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/example3/v1/zz_generated.deepcopy.go b/examples/pkg/apis/example3/v1/zz_generated.deepcopy.go index 8598c20a6..2df6f53e5 100644 --- a/examples/pkg/apis/example3/v1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/example3/v1/zz_generated.deepcopy.go @@ -1,12 +1,28 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Code generated by controller-gen. DO NOT EDIT. +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/runtime" + runtime "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -15,6 +31,7 @@ func (in *ClusterTestType) DeepCopyInto(out *ClusterTestType) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Status = in.Status + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestType. @@ -47,6 +64,7 @@ func (in *ClusterTestTypeList) DeepCopyInto(out *ClusterTestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeList. @@ -70,6 +88,7 @@ func (in *ClusterTestTypeList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterTestTypeStatus) DeepCopyInto(out *ClusterTestTypeStatus) { *out = *in + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeStatus. @@ -92,6 +111,7 @@ func (in *TestType) DeepCopyInto(out *TestType) { *out = make([]string, len(*in)) copy(*out, *in) } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. @@ -124,6 +144,7 @@ func (in *TestTypeList) DeepCopyInto(out *TestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. diff --git a/examples/pkg/apis/exampledashed/doc.go b/examples/pkg/apis/exampledashed/doc.go new file mode 100644 index 000000000..574f2f997 --- /dev/null +++ b/examples/pkg/apis/exampledashed/doc.go @@ -0,0 +1,22 @@ +/* +Copyright 2021 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package exampledashed + +const ( + // GroupName is the group name use in this package. + GroupName = "example-dashed.some.corp" +) diff --git a/pkg/internal/listergen/parser.go b/examples/pkg/apis/exampledashed/v1/doc.go similarity index 68% rename from pkg/internal/listergen/parser.go rename to examples/pkg/apis/exampledashed/v1/doc.go index bb9ce20bc..6adf1cdd6 100644 --- a/pkg/internal/listergen/parser.go +++ b/examples/pkg/apis/exampledashed/v1/doc.go @@ -14,19 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -package listergen - -import ( - "strings" - "text/template" - - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -var ( - templateFuncs = template.FuncMap{ - "upperFirst": util.UpperFirst, - "lowerFirst": util.LowerFirst, - "toLower": strings.ToLower, - } -) +// Package v1 contains API Schema definitions for the example-dashed.some.corp +// v1 API group. +// +// +k8s:deepcopy-gen=package,register +// +groupName=example-dashed.some.corp +// +groupGoName=ExampleDashed +package v1 diff --git a/examples/pkg/apis/exampledashed/v1/register.go b/examples/pkg/apis/exampledashed/v1/register.go new file mode 100644 index 000000000..5f8c47ec6 --- /dev/null +++ b/examples/pkg/apis/exampledashed/v1/register.go @@ -0,0 +1,55 @@ +/* +Copyright 2021 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import ( + example "acme.corp/pkg/apis/exampledashed" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// SchemeGroupVersion is group version used to register these objects. +var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource. +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &TestType{}, + &TestTypeList{}, + &ClusterTestType{}, + &ClusterTestTypeList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/examples/pkg/apis/exampledashed/v1/types.go b/examples/pkg/apis/exampledashed/v1/types.go new file mode 100644 index 000000000..1f1a48209 --- /dev/null +++ b/examples/pkg/apis/exampledashed/v1/types.go @@ -0,0 +1,70 @@ +/* +Copyright 2022 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + +// +genclient +// +genclient:noStatus +// +genclient:method=CreateField,verb=create,subresource=field,input=acme.corp/pkg/apis/example/v1.Field,result=acme.corp/pkg/apis/example/v1.Field +// +genclient:method=UpdateField,verb=update,subresource=field,input=acme.corp/pkg/apis/example/v1.Field,result=acme.corp/pkg/apis/example/v1.Field +// +genclient:method=GetField,verb=get,subresource=field,result=acme.corp/pkg/apis/example/v1.Field +// TestType is a top-level type. A client is created for it. +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type TestType struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + // +optional + APIGroups []string `json:"apiGroups,omitempty"` +} + +// TestTypeList is a top-level list type. The client methods for lists are automatically created. +// You are not supposed to create a separated client for this one. +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type TestTypeList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + Items []TestType `json:"items"` +} + +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type ClusterTestType struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + // ObjectKind is the type of resource being referenced + ObjectKind string `json:"kind"` + // ObjectName is the name of resource being referenced + ObjectName string `json:"name"` + // +optional + Status ClusterTestTypeStatus `json:"status,omitempty"` +} + +type ClusterTestTypeStatus struct { + Blah string `json:"blah,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type ClusterTestTypeList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []ClusterTestType `json:"items"` +} diff --git a/examples/pkg/apis/exampledashed/v1/zz_generated.deepcopy.go b/examples/pkg/apis/exampledashed/v1/zz_generated.deepcopy.go new file mode 100644 index 000000000..2df6f53e5 --- /dev/null +++ b/examples/pkg/apis/exampledashed/v1/zz_generated.deepcopy.go @@ -0,0 +1,166 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterTestType) DeepCopyInto(out *ClusterTestType) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestType. +func (in *ClusterTestType) DeepCopy() *ClusterTestType { + if in == nil { + return nil + } + out := new(ClusterTestType) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ClusterTestType) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterTestTypeList) DeepCopyInto(out *ClusterTestTypeList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ClusterTestType, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeList. +func (in *ClusterTestTypeList) DeepCopy() *ClusterTestTypeList { + if in == nil { + return nil + } + out := new(ClusterTestTypeList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ClusterTestTypeList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterTestTypeStatus) DeepCopyInto(out *ClusterTestTypeStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeStatus. +func (in *ClusterTestTypeStatus) DeepCopy() *ClusterTestTypeStatus { + if in == nil { + return nil + } + out := new(ClusterTestTypeStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestType) DeepCopyInto(out *TestType) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + if in.APIGroups != nil { + in, out := &in.APIGroups, &out.APIGroups + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. +func (in *TestType) DeepCopy() *TestType { + if in == nil { + return nil + } + out := new(TestType) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TestType) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestTypeList) DeepCopyInto(out *TestTypeList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]TestType, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. +func (in *TestTypeList) DeepCopy() *TestTypeList { + if in == nil { + return nil + } + out := new(TestTypeList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TestTypeList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} diff --git a/examples/pkg/apis/existinginterfaces/register.go b/examples/pkg/apis/existinginterfaces/register.go index a4e8efd75..54fa947df 100644 --- a/examples/pkg/apis/existinginterfaces/register.go +++ b/examples/pkg/apis/existinginterfaces/register.go @@ -17,5 +17,5 @@ limitations under the License. package existinginterfaces const ( - GroupName = "existinginterfaces.dev" + GroupName = "existinginterfaces.acme.corp" ) diff --git a/examples/pkg/apis/existinginterfaces/v1/register.go b/examples/pkg/apis/existinginterfaces/v1/register.go index e15c0058d..6a7f922dd 100644 --- a/examples/pkg/apis/existinginterfaces/v1/register.go +++ b/examples/pkg/apis/existinginterfaces/v1/register.go @@ -17,22 +17,22 @@ limitations under the License. package v1 import ( + "acme.corp/pkg/apis/existinginterfaces" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - - "acme.corp/pkg/apis/existinginterfaces" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: existinginterfaces.GroupName, Version: "v1"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/existinginterfaces/v1/zz_generated.deepcopy.go b/examples/pkg/apis/existinginterfaces/v1/zz_generated.deepcopy.go index 8598c20a6..2df6f53e5 100644 --- a/examples/pkg/apis/existinginterfaces/v1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/existinginterfaces/v1/zz_generated.deepcopy.go @@ -1,12 +1,28 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Code generated by controller-gen. DO NOT EDIT. +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/runtime" + runtime "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -15,6 +31,7 @@ func (in *ClusterTestType) DeepCopyInto(out *ClusterTestType) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Status = in.Status + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestType. @@ -47,6 +64,7 @@ func (in *ClusterTestTypeList) DeepCopyInto(out *ClusterTestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeList. @@ -70,6 +88,7 @@ func (in *ClusterTestTypeList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterTestTypeStatus) DeepCopyInto(out *ClusterTestTypeStatus) { *out = *in + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeStatus. @@ -92,6 +111,7 @@ func (in *TestType) DeepCopyInto(out *TestType) { *out = make([]string, len(*in)) copy(*out, *in) } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. @@ -124,6 +144,7 @@ func (in *TestTypeList) DeepCopyInto(out *TestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. diff --git a/examples/pkg/apis/secondexample/v1/doc.go b/examples/pkg/apis/secondexample/v1/doc.go index 907f7bc67..73f017d52 100644 --- a/examples/pkg/apis/secondexample/v1/doc.go +++ b/examples/pkg/apis/secondexample/v1/doc.go @@ -15,4 +15,5 @@ limitations under the License. */ // +k8s:deepcopy-gen=package,register +// +groupName=secondexample.dev package v1 diff --git a/examples/pkg/apis/secondexample/v1/register.go b/examples/pkg/apis/secondexample/v1/register.go index 4b139992f..7274f4449 100644 --- a/examples/pkg/apis/secondexample/v1/register.go +++ b/examples/pkg/apis/secondexample/v1/register.go @@ -17,22 +17,22 @@ limitations under the License. package v1 import ( + example "acme.corp/pkg/apis/secondexample" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - - example "acme.corp/pkg/apis/secondexample" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/secondexample/v1/zz_generated.deepcopy.go b/examples/pkg/apis/secondexample/v1/zz_generated.deepcopy.go index 8598c20a6..2df6f53e5 100644 --- a/examples/pkg/apis/secondexample/v1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/secondexample/v1/zz_generated.deepcopy.go @@ -1,12 +1,28 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Code generated by controller-gen. DO NOT EDIT. +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/runtime" + runtime "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -15,6 +31,7 @@ func (in *ClusterTestType) DeepCopyInto(out *ClusterTestType) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Status = in.Status + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestType. @@ -47,6 +64,7 @@ func (in *ClusterTestTypeList) DeepCopyInto(out *ClusterTestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeList. @@ -70,6 +88,7 @@ func (in *ClusterTestTypeList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterTestTypeStatus) DeepCopyInto(out *ClusterTestTypeStatus) { *out = *in + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeStatus. @@ -92,6 +111,7 @@ func (in *TestType) DeepCopyInto(out *TestType) { *out = make([]string, len(*in)) copy(*out, *in) } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. @@ -124,6 +144,7 @@ func (in *TestTypeList) DeepCopyInto(out *TestTypeList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. diff --git a/examples/pkg/generated/applyconfigurations/example/v1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/example/v1/clustertesttype.go index e4130846e..ffc4f8774 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1/clustertesttype.go +++ b/examples/pkg/generated/applyconfigurations/example/v1/clustertesttype.go @@ -14,33 +14,33 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" + metav1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// ClusterTestTypeApplyConfiguration represents an declarative configuration of the ClusterTestType type for use +// ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use // with apply. type ClusterTestTypeApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - ObjectKind *string `json:"kind,omitempty"` - ObjectName *string `json:"name,omitempty"` - Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` + metav1.TypeMetaApplyConfiguration `json:",inline"` + *metav1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + ObjectKind *string `json:"kind,omitempty"` + ObjectName *string `json:"name,omitempty"` + Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` } -// ClusterTestType constructs an declarative configuration of the ClusterTestType type for use with +// ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with // apply. func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { b := &ClusterTestTypeApplyConfiguration{} b.WithName(name) b.WithKind("ClusterTestType") - b.WithAPIVersion("example/v1") + b.WithAPIVersion("example.dev/v1") return b } @@ -48,7 +48,7 @@ func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -56,7 +56,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestT // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *ClusterTestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -65,7 +65,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *Cluste // If called multiple times, the Name field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -74,7 +74,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestT // If called multiple times, the GenerateName field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -83,7 +83,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *Clus // If called multiple times, the Namespace field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -92,7 +92,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *Cluster // If called multiple times, the UID field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -101,7 +101,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTes // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -110,25 +110,25 @@ func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *C // If called multiple times, the Generation field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } // WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { +func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value apismetav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } // WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { +func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value apismetav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -137,7 +137,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -147,11 +147,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value // overwriting an existing map entries in Labels field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -162,11 +162,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string // overwriting an existing map entries in Annotations field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -174,13 +174,13 @@ func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]s // WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *ClusterTestTypeApplyConfiguration { +func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*metav1.OwnerReferenceApplyConfiguration) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -191,14 +191,14 @@ func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.Ow func (b *ClusterTestTypeApplyConfiguration) WithFinalizers(values ...string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } func (b *ClusterTestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + b.ObjectMetaApplyConfiguration = &metav1.ObjectMetaApplyConfiguration{} } } @@ -225,3 +225,9 @@ func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeSta b.Status = value return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *ClusterTestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/example/v1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/example/v1/clustertesttypestatus.go index a5457af72..9e9d64b6d 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/example/v1/clustertesttypestatus.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 -// ClusterTestTypeStatusApplyConfiguration represents an declarative configuration of the ClusterTestTypeStatus type for use +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use // with apply. type ClusterTestTypeStatusApplyConfiguration struct { Blah *string `json:"blah,omitempty"` } -// ClusterTestTypeStatusApplyConfiguration constructs an declarative configuration of the ClusterTestTypeStatus type for use with +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with // apply. func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { return &ClusterTestTypeStatusApplyConfiguration{} diff --git a/examples/pkg/generated/applyconfigurations/example/v1/testtype.go b/examples/pkg/generated/applyconfigurations/example/v1/testtype.go index 5803165db..194cef1ef 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1/testtype.go +++ b/examples/pkg/generated/applyconfigurations/example/v1/testtype.go @@ -14,32 +14,32 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" + metav1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// TestTypeApplyConfiguration represents an declarative configuration of the TestType type for use +// TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use // with apply. type TestTypeApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - APIGroups []string `json:"apiGroups,omitempty"` + metav1.TypeMetaApplyConfiguration `json:",inline"` + *metav1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + APIGroups []string `json:"apiGroups,omitempty"` } -// TestType constructs an declarative configuration of the TestType type for use with +// TestType constructs a declarative configuration of the TestType type for use with // apply. func TestType(name, namespace string) *TestTypeApplyConfiguration { b := &TestTypeApplyConfiguration{} b.WithName(name) b.WithNamespace(namespace) b.WithKind("TestType") - b.WithAPIVersion("example/v1") + b.WithAPIVersion("example.dev/v1") return b } @@ -47,7 +47,7 @@ func TestType(name, namespace string) *TestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -55,7 +55,7 @@ func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfig // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -64,7 +64,7 @@ func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApply // If called multiple times, the Name field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -73,7 +73,7 @@ func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfig // If called multiple times, the GenerateName field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -82,7 +82,7 @@ func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApp // If called multiple times, the Namespace field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -91,7 +91,7 @@ func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyC // If called multiple times, the UID field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -100,7 +100,7 @@ func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConf // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -109,25 +109,25 @@ func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestType // If called multiple times, the Generation field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } // WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *TestTypeApplyConfiguration { +func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value apismetav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } // WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *TestTypeApplyConfiguration { +func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value apismetav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -136,7 +136,7 @@ func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -146,11 +146,11 @@ func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) // overwriting an existing map entries in Labels field with the same key. func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -161,11 +161,11 @@ func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *Test // overwriting an existing map entries in Annotations field with the same key. func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -173,13 +173,13 @@ func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) // WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *TestTypeApplyConfiguration { +func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*metav1.OwnerReferenceApplyConfiguration) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -190,14 +190,14 @@ func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerRefe func (b *TestTypeApplyConfiguration) WithFinalizers(values ...string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + b.ObjectMetaApplyConfiguration = &metav1.ObjectMetaApplyConfiguration{} } } @@ -210,3 +210,9 @@ func (b *TestTypeApplyConfiguration) WithAPIGroups(values ...string) *TestTypeAp } return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *TestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/example/v1/withoutverbtype.go b/examples/pkg/generated/applyconfigurations/example/v1/withoutverbtype.go index d7377b5e6..19bf83a8c 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1/withoutverbtype.go +++ b/examples/pkg/generated/applyconfigurations/example/v1/withoutverbtype.go @@ -14,31 +14,31 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" + metav1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// WithoutVerbTypeApplyConfiguration represents an declarative configuration of the WithoutVerbType type for use +// WithoutVerbTypeApplyConfiguration represents a declarative configuration of the WithoutVerbType type for use // with apply. type WithoutVerbTypeApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + metav1.TypeMetaApplyConfiguration `json:",inline"` + *metav1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` } -// WithoutVerbType constructs an declarative configuration of the WithoutVerbType type for use with +// WithoutVerbType constructs a declarative configuration of the WithoutVerbType type for use with // apply. func WithoutVerbType(name, namespace string) *WithoutVerbTypeApplyConfiguration { b := &WithoutVerbTypeApplyConfiguration{} b.WithName(name) b.WithNamespace(namespace) b.WithKind("WithoutVerbType") - b.WithAPIVersion("example/v1") + b.WithAPIVersion("example.dev/v1") return b } @@ -46,7 +46,7 @@ func WithoutVerbType(name, namespace string) *WithoutVerbTypeApplyConfiguration // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *WithoutVerbTypeApplyConfiguration) WithKind(value string) *WithoutVerbTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -54,7 +54,7 @@ func (b *WithoutVerbTypeApplyConfiguration) WithKind(value string) *WithoutVerbT // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *WithoutVerbTypeApplyConfiguration) WithAPIVersion(value string) *WithoutVerbTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -63,7 +63,7 @@ func (b *WithoutVerbTypeApplyConfiguration) WithAPIVersion(value string) *Withou // If called multiple times, the Name field is set to the value of the last call. func (b *WithoutVerbTypeApplyConfiguration) WithName(value string) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -72,7 +72,7 @@ func (b *WithoutVerbTypeApplyConfiguration) WithName(value string) *WithoutVerbT // If called multiple times, the GenerateName field is set to the value of the last call. func (b *WithoutVerbTypeApplyConfiguration) WithGenerateName(value string) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -81,7 +81,7 @@ func (b *WithoutVerbTypeApplyConfiguration) WithGenerateName(value string) *With // If called multiple times, the Namespace field is set to the value of the last call. func (b *WithoutVerbTypeApplyConfiguration) WithNamespace(value string) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -90,7 +90,7 @@ func (b *WithoutVerbTypeApplyConfiguration) WithNamespace(value string) *Without // If called multiple times, the UID field is set to the value of the last call. func (b *WithoutVerbTypeApplyConfiguration) WithUID(value types.UID) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -99,7 +99,7 @@ func (b *WithoutVerbTypeApplyConfiguration) WithUID(value types.UID) *WithoutVer // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *WithoutVerbTypeApplyConfiguration) WithResourceVersion(value string) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -108,25 +108,25 @@ func (b *WithoutVerbTypeApplyConfiguration) WithResourceVersion(value string) *W // If called multiple times, the Generation field is set to the value of the last call. func (b *WithoutVerbTypeApplyConfiguration) WithGeneration(value int64) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } // WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *WithoutVerbTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *WithoutVerbTypeApplyConfiguration { +func (b *WithoutVerbTypeApplyConfiguration) WithCreationTimestamp(value apismetav1.Time) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } // WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *WithoutVerbTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *WithoutVerbTypeApplyConfiguration { +func (b *WithoutVerbTypeApplyConfiguration) WithDeletionTimestamp(value apismetav1.Time) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -135,7 +135,7 @@ func (b *WithoutVerbTypeApplyConfiguration) WithDeletionTimestamp(value metav1.T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *WithoutVerbTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -145,11 +145,11 @@ func (b *WithoutVerbTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value // overwriting an existing map entries in Labels field with the same key. func (b *WithoutVerbTypeApplyConfiguration) WithLabels(entries map[string]string) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -160,11 +160,11 @@ func (b *WithoutVerbTypeApplyConfiguration) WithLabels(entries map[string]string // overwriting an existing map entries in Annotations field with the same key. func (b *WithoutVerbTypeApplyConfiguration) WithAnnotations(entries map[string]string) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -172,13 +172,13 @@ func (b *WithoutVerbTypeApplyConfiguration) WithAnnotations(entries map[string]s // WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *WithoutVerbTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *WithoutVerbTypeApplyConfiguration { +func (b *WithoutVerbTypeApplyConfiguration) WithOwnerReferences(values ...*metav1.OwnerReferenceApplyConfiguration) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -189,13 +189,19 @@ func (b *WithoutVerbTypeApplyConfiguration) WithOwnerReferences(values ...*v1.Ow func (b *WithoutVerbTypeApplyConfiguration) WithFinalizers(values ...string) *WithoutVerbTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } func (b *WithoutVerbTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + b.ObjectMetaApplyConfiguration = &metav1.ObjectMetaApplyConfiguration{} } } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *WithoutVerbTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttype.go index 2bcfa5616..f70e08473 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttype.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1alpha1 @@ -24,7 +24,7 @@ import ( v1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// ClusterTestTypeApplyConfiguration represents an declarative configuration of the ClusterTestType type for use +// ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use // with apply. type ClusterTestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` @@ -34,13 +34,13 @@ type ClusterTestTypeApplyConfiguration struct { Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` } -// ClusterTestType constructs an declarative configuration of the ClusterTestType type for use with +// ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with // apply. func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { b := &ClusterTestTypeApplyConfiguration{} b.WithName(name) b.WithKind("ClusterTestType") - b.WithAPIVersion("example/v1alpha1") + b.WithAPIVersion("example.dev/v1alpha1") return b } @@ -48,7 +48,7 @@ func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -56,7 +56,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestT // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *ClusterTestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -65,7 +65,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *Cluste // If called multiple times, the Name field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -74,7 +74,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestT // If called multiple times, the GenerateName field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -83,7 +83,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *Clus // If called multiple times, the Namespace field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -92,7 +92,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *Cluster // If called multiple times, the UID field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -101,7 +101,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTes // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -110,7 +110,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *C // If called multiple times, the Generation field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } @@ -119,7 +119,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *Cluster // If called multiple times, the CreationTimestamp field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } @@ -128,7 +128,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.T // If called multiple times, the DeletionTimestamp field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -137,7 +137,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -147,11 +147,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value // overwriting an existing map entries in Labels field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -162,11 +162,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string // overwriting an existing map entries in Annotations field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -180,7 +180,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.Ow if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -191,7 +191,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.Ow func (b *ClusterTestTypeApplyConfiguration) WithFinalizers(values ...string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } @@ -225,3 +225,9 @@ func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeSta b.Status = value return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *ClusterTestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttypestatus.go index cf07ff071..c1fb4e0af 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttypestatus.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1alpha1 -// ClusterTestTypeStatusApplyConfiguration represents an declarative configuration of the ClusterTestTypeStatus type for use +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use // with apply. type ClusterTestTypeStatusApplyConfiguration struct { Blah *string `json:"blah,omitempty"` } -// ClusterTestTypeStatusApplyConfiguration constructs an declarative configuration of the ClusterTestTypeStatus type for use with +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with // apply. func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { return &ClusterTestTypeStatusApplyConfiguration{} diff --git a/examples/pkg/generated/applyconfigurations/example/v1alpha1/testtype.go b/examples/pkg/generated/applyconfigurations/example/v1alpha1/testtype.go index cdf22a9c8..1b3432b7b 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1alpha1/testtype.go +++ b/examples/pkg/generated/applyconfigurations/example/v1alpha1/testtype.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1alpha1 @@ -24,7 +24,7 @@ import ( v1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// TestTypeApplyConfiguration represents an declarative configuration of the TestType type for use +// TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use // with apply. type TestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` @@ -32,14 +32,14 @@ type TestTypeApplyConfiguration struct { APIGroups []string `json:"apiGroups,omitempty"` } -// TestType constructs an declarative configuration of the TestType type for use with +// TestType constructs a declarative configuration of the TestType type for use with // apply. func TestType(name, namespace string) *TestTypeApplyConfiguration { b := &TestTypeApplyConfiguration{} b.WithName(name) b.WithNamespace(namespace) b.WithKind("TestType") - b.WithAPIVersion("example/v1alpha1") + b.WithAPIVersion("example.dev/v1alpha1") return b } @@ -47,7 +47,7 @@ func TestType(name, namespace string) *TestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -55,7 +55,7 @@ func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfig // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -64,7 +64,7 @@ func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApply // If called multiple times, the Name field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -73,7 +73,7 @@ func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfig // If called multiple times, the GenerateName field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -82,7 +82,7 @@ func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApp // If called multiple times, the Namespace field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -91,7 +91,7 @@ func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyC // If called multiple times, the UID field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -100,7 +100,7 @@ func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConf // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -109,7 +109,7 @@ func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestType // If called multiple times, the Generation field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } @@ -118,7 +118,7 @@ func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyC // If called multiple times, the CreationTimestamp field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } @@ -127,7 +127,7 @@ func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *T // If called multiple times, the DeletionTimestamp field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -136,7 +136,7 @@ func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -146,11 +146,11 @@ func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) // overwriting an existing map entries in Labels field with the same key. func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -161,11 +161,11 @@ func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *Test // overwriting an existing map entries in Annotations field with the same key. func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -179,7 +179,7 @@ func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerRefe if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -190,7 +190,7 @@ func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerRefe func (b *TestTypeApplyConfiguration) WithFinalizers(values ...string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } @@ -210,3 +210,9 @@ func (b *TestTypeApplyConfiguration) WithAPIGroups(values ...string) *TestTypeAp } return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *TestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttype.go index 47aa6204f..734792054 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttype.go +++ b/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttype.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1beta1 @@ -24,7 +24,7 @@ import ( v1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// ClusterTestTypeApplyConfiguration represents an declarative configuration of the ClusterTestType type for use +// ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use // with apply. type ClusterTestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` @@ -34,13 +34,13 @@ type ClusterTestTypeApplyConfiguration struct { Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` } -// ClusterTestType constructs an declarative configuration of the ClusterTestType type for use with +// ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with // apply. func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { b := &ClusterTestTypeApplyConfiguration{} b.WithName(name) b.WithKind("ClusterTestType") - b.WithAPIVersion("example/v1beta1") + b.WithAPIVersion("example.dev/v1beta1") return b } @@ -48,7 +48,7 @@ func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -56,7 +56,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestT // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *ClusterTestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -65,7 +65,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *Cluste // If called multiple times, the Name field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -74,7 +74,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestT // If called multiple times, the GenerateName field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -83,7 +83,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *Clus // If called multiple times, the Namespace field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -92,7 +92,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *Cluster // If called multiple times, the UID field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -101,7 +101,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTes // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -110,7 +110,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *C // If called multiple times, the Generation field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } @@ -119,7 +119,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *Cluster // If called multiple times, the CreationTimestamp field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } @@ -128,7 +128,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.T // If called multiple times, the DeletionTimestamp field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -137,7 +137,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -147,11 +147,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value // overwriting an existing map entries in Labels field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -162,11 +162,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string // overwriting an existing map entries in Annotations field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -180,7 +180,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.Ow if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -191,7 +191,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.Ow func (b *ClusterTestTypeApplyConfiguration) WithFinalizers(values ...string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } @@ -225,3 +225,9 @@ func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeSta b.Status = value return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *ClusterTestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttypestatus.go index a4f0be3f8..dfb1b5601 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttypestatus.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1beta1 -// ClusterTestTypeStatusApplyConfiguration represents an declarative configuration of the ClusterTestTypeStatus type for use +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use // with apply. type ClusterTestTypeStatusApplyConfiguration struct { Blah *string `json:"blah,omitempty"` } -// ClusterTestTypeStatusApplyConfiguration constructs an declarative configuration of the ClusterTestTypeStatus type for use with +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with // apply. func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { return &ClusterTestTypeStatusApplyConfiguration{} diff --git a/examples/pkg/generated/applyconfigurations/example/v1beta1/testtype.go b/examples/pkg/generated/applyconfigurations/example/v1beta1/testtype.go index 676189039..32ac250fd 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1beta1/testtype.go +++ b/examples/pkg/generated/applyconfigurations/example/v1beta1/testtype.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1beta1 @@ -24,7 +24,7 @@ import ( v1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// TestTypeApplyConfiguration represents an declarative configuration of the TestType type for use +// TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use // with apply. type TestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` @@ -32,14 +32,14 @@ type TestTypeApplyConfiguration struct { APIGroups []string `json:"apiGroups,omitempty"` } -// TestType constructs an declarative configuration of the TestType type for use with +// TestType constructs a declarative configuration of the TestType type for use with // apply. func TestType(name, namespace string) *TestTypeApplyConfiguration { b := &TestTypeApplyConfiguration{} b.WithName(name) b.WithNamespace(namespace) b.WithKind("TestType") - b.WithAPIVersion("example/v1beta1") + b.WithAPIVersion("example.dev/v1beta1") return b } @@ -47,7 +47,7 @@ func TestType(name, namespace string) *TestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -55,7 +55,7 @@ func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfig // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -64,7 +64,7 @@ func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApply // If called multiple times, the Name field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -73,7 +73,7 @@ func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfig // If called multiple times, the GenerateName field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -82,7 +82,7 @@ func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApp // If called multiple times, the Namespace field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -91,7 +91,7 @@ func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyC // If called multiple times, the UID field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -100,7 +100,7 @@ func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConf // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -109,7 +109,7 @@ func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestType // If called multiple times, the Generation field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } @@ -118,7 +118,7 @@ func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyC // If called multiple times, the CreationTimestamp field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } @@ -127,7 +127,7 @@ func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *T // If called multiple times, the DeletionTimestamp field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -136,7 +136,7 @@ func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -146,11 +146,11 @@ func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) // overwriting an existing map entries in Labels field with the same key. func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -161,11 +161,11 @@ func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *Test // overwriting an existing map entries in Annotations field with the same key. func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -179,7 +179,7 @@ func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerRefe if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -190,7 +190,7 @@ func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerRefe func (b *TestTypeApplyConfiguration) WithFinalizers(values ...string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } @@ -210,3 +210,9 @@ func (b *TestTypeApplyConfiguration) WithAPIGroups(values ...string) *TestTypeAp } return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *TestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/example/v2/clustertesttype.go b/examples/pkg/generated/applyconfigurations/example/v2/clustertesttype.go index 9332469ab..1e535c5be 100644 --- a/examples/pkg/generated/applyconfigurations/example/v2/clustertesttype.go +++ b/examples/pkg/generated/applyconfigurations/example/v2/clustertesttype.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v2 @@ -24,7 +24,7 @@ import ( v1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// ClusterTestTypeApplyConfiguration represents an declarative configuration of the ClusterTestType type for use +// ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use // with apply. type ClusterTestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` @@ -34,13 +34,13 @@ type ClusterTestTypeApplyConfiguration struct { Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` } -// ClusterTestType constructs an declarative configuration of the ClusterTestType type for use with +// ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with // apply. func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { b := &ClusterTestTypeApplyConfiguration{} b.WithName(name) b.WithKind("ClusterTestType") - b.WithAPIVersion("example/v2") + b.WithAPIVersion("example.dev/v2") return b } @@ -48,7 +48,7 @@ func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -56,7 +56,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestT // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *ClusterTestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -65,7 +65,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *Cluste // If called multiple times, the Name field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -74,7 +74,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestT // If called multiple times, the GenerateName field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -83,7 +83,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *Clus // If called multiple times, the Namespace field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -92,7 +92,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *Cluster // If called multiple times, the UID field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -101,7 +101,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTes // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -110,7 +110,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *C // If called multiple times, the Generation field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } @@ -119,7 +119,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *Cluster // If called multiple times, the CreationTimestamp field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } @@ -128,7 +128,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.T // If called multiple times, the DeletionTimestamp field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -137,7 +137,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -147,11 +147,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value // overwriting an existing map entries in Labels field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -162,11 +162,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string // overwriting an existing map entries in Annotations field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -180,7 +180,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.Ow if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -191,7 +191,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.Ow func (b *ClusterTestTypeApplyConfiguration) WithFinalizers(values ...string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } @@ -225,3 +225,9 @@ func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeSta b.Status = value return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *ClusterTestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/example/v2/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/example/v2/clustertesttypestatus.go index a2102efb8..b3287ed0b 100644 --- a/examples/pkg/generated/applyconfigurations/example/v2/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/example/v2/clustertesttypestatus.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v2 -// ClusterTestTypeStatusApplyConfiguration represents an declarative configuration of the ClusterTestTypeStatus type for use +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use // with apply. type ClusterTestTypeStatusApplyConfiguration struct { Blah *string `json:"blah,omitempty"` } -// ClusterTestTypeStatusApplyConfiguration constructs an declarative configuration of the ClusterTestTypeStatus type for use with +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with // apply. func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { return &ClusterTestTypeStatusApplyConfiguration{} diff --git a/examples/pkg/generated/applyconfigurations/example/v2/testtype.go b/examples/pkg/generated/applyconfigurations/example/v2/testtype.go index c84fb5d56..01019f9ab 100644 --- a/examples/pkg/generated/applyconfigurations/example/v2/testtype.go +++ b/examples/pkg/generated/applyconfigurations/example/v2/testtype.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v2 @@ -24,7 +24,7 @@ import ( v1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// TestTypeApplyConfiguration represents an declarative configuration of the TestType type for use +// TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use // with apply. type TestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` @@ -32,14 +32,14 @@ type TestTypeApplyConfiguration struct { APIGroups []string `json:"apiGroups,omitempty"` } -// TestType constructs an declarative configuration of the TestType type for use with +// TestType constructs a declarative configuration of the TestType type for use with // apply. func TestType(name, namespace string) *TestTypeApplyConfiguration { b := &TestTypeApplyConfiguration{} b.WithName(name) b.WithNamespace(namespace) b.WithKind("TestType") - b.WithAPIVersion("example/v2") + b.WithAPIVersion("example.dev/v2") return b } @@ -47,7 +47,7 @@ func TestType(name, namespace string) *TestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -55,7 +55,7 @@ func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfig // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -64,7 +64,7 @@ func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApply // If called multiple times, the Name field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -73,7 +73,7 @@ func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfig // If called multiple times, the GenerateName field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -82,7 +82,7 @@ func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApp // If called multiple times, the Namespace field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -91,7 +91,7 @@ func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyC // If called multiple times, the UID field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -100,7 +100,7 @@ func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConf // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -109,7 +109,7 @@ func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestType // If called multiple times, the Generation field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } @@ -118,7 +118,7 @@ func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyC // If called multiple times, the CreationTimestamp field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } @@ -127,7 +127,7 @@ func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *T // If called multiple times, the DeletionTimestamp field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -136,7 +136,7 @@ func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -146,11 +146,11 @@ func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) // overwriting an existing map entries in Labels field with the same key. func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -161,11 +161,11 @@ func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *Test // overwriting an existing map entries in Annotations field with the same key. func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -179,7 +179,7 @@ func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerRefe if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -190,7 +190,7 @@ func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerRefe func (b *TestTypeApplyConfiguration) WithFinalizers(values ...string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } @@ -210,3 +210,9 @@ func (b *TestTypeApplyConfiguration) WithAPIGroups(values ...string) *TestTypeAp } return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *TestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttype.go index 66d527648..539af2118 100644 --- a/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttype.go +++ b/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttype.go @@ -14,27 +14,27 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" + metav1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// ClusterTestTypeApplyConfiguration represents an declarative configuration of the ClusterTestType type for use +// ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use // with apply. type ClusterTestTypeApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - ObjectKind *string `json:"kind,omitempty"` - ObjectName *string `json:"name,omitempty"` - Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` + metav1.TypeMetaApplyConfiguration `json:",inline"` + *metav1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + ObjectKind *string `json:"kind,omitempty"` + ObjectName *string `json:"name,omitempty"` + Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` } -// ClusterTestType constructs an declarative configuration of the ClusterTestType type for use with +// ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with // apply. func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { b := &ClusterTestTypeApplyConfiguration{} @@ -48,7 +48,7 @@ func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -56,7 +56,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestT // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *ClusterTestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -65,7 +65,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *Cluste // If called multiple times, the Name field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -74,7 +74,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestT // If called multiple times, the GenerateName field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -83,7 +83,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *Clus // If called multiple times, the Namespace field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -92,7 +92,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *Cluster // If called multiple times, the UID field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -101,7 +101,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTes // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -110,25 +110,25 @@ func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *C // If called multiple times, the Generation field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } // WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { +func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value apismetav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } // WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { +func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value apismetav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -137,7 +137,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -147,11 +147,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value // overwriting an existing map entries in Labels field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -162,11 +162,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string // overwriting an existing map entries in Annotations field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -174,13 +174,13 @@ func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]s // WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *ClusterTestTypeApplyConfiguration { +func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*metav1.OwnerReferenceApplyConfiguration) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -191,14 +191,14 @@ func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.Ow func (b *ClusterTestTypeApplyConfiguration) WithFinalizers(values ...string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } func (b *ClusterTestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + b.ObjectMetaApplyConfiguration = &metav1.ObjectMetaApplyConfiguration{} } } @@ -225,3 +225,9 @@ func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeSta b.Status = value return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *ClusterTestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttypestatus.go index a5457af72..9e9d64b6d 100644 --- a/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttypestatus.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 -// ClusterTestTypeStatusApplyConfiguration represents an declarative configuration of the ClusterTestTypeStatus type for use +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use // with apply. type ClusterTestTypeStatusApplyConfiguration struct { Blah *string `json:"blah,omitempty"` } -// ClusterTestTypeStatusApplyConfiguration constructs an declarative configuration of the ClusterTestTypeStatus type for use with +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with // apply. func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { return &ClusterTestTypeStatusApplyConfiguration{} diff --git a/examples/pkg/generated/applyconfigurations/example3/v1/testtype.go b/examples/pkg/generated/applyconfigurations/example3/v1/testtype.go index 4043fb013..5330929f5 100644 --- a/examples/pkg/generated/applyconfigurations/example3/v1/testtype.go +++ b/examples/pkg/generated/applyconfigurations/example3/v1/testtype.go @@ -14,25 +14,25 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" + metav1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// TestTypeApplyConfiguration represents an declarative configuration of the TestType type for use +// TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use // with apply. type TestTypeApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - APIGroups []string `json:"apiGroups,omitempty"` + metav1.TypeMetaApplyConfiguration `json:",inline"` + *metav1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + APIGroups []string `json:"apiGroups,omitempty"` } -// TestType constructs an declarative configuration of the TestType type for use with +// TestType constructs a declarative configuration of the TestType type for use with // apply. func TestType(name, namespace string) *TestTypeApplyConfiguration { b := &TestTypeApplyConfiguration{} @@ -47,7 +47,7 @@ func TestType(name, namespace string) *TestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -55,7 +55,7 @@ func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfig // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -64,7 +64,7 @@ func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApply // If called multiple times, the Name field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -73,7 +73,7 @@ func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfig // If called multiple times, the GenerateName field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -82,7 +82,7 @@ func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApp // If called multiple times, the Namespace field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -91,7 +91,7 @@ func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyC // If called multiple times, the UID field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -100,7 +100,7 @@ func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConf // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -109,25 +109,25 @@ func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestType // If called multiple times, the Generation field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } // WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *TestTypeApplyConfiguration { +func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value apismetav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } // WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *TestTypeApplyConfiguration { +func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value apismetav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -136,7 +136,7 @@ func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -146,11 +146,11 @@ func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) // overwriting an existing map entries in Labels field with the same key. func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -161,11 +161,11 @@ func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *Test // overwriting an existing map entries in Annotations field with the same key. func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -173,13 +173,13 @@ func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) // WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *TestTypeApplyConfiguration { +func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*metav1.OwnerReferenceApplyConfiguration) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -190,14 +190,14 @@ func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerRefe func (b *TestTypeApplyConfiguration) WithFinalizers(values ...string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + b.ObjectMetaApplyConfiguration = &metav1.ObjectMetaApplyConfiguration{} } } @@ -210,3 +210,9 @@ func (b *TestTypeApplyConfiguration) WithAPIGroups(values ...string) *TestTypeAp } return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *TestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..15fced8cf --- /dev/null +++ b/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttype.go @@ -0,0 +1,233 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +import ( + apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + metav1 "k8s.io/client-go/applyconfigurations/meta/v1" +) + +// ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use +// with apply. +type ClusterTestTypeApplyConfiguration struct { + metav1.TypeMetaApplyConfiguration `json:",inline"` + *metav1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + ObjectKind *string `json:"kind,omitempty"` + ObjectName *string `json:"name,omitempty"` + Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` +} + +// ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with +// apply. +func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { + b := &ClusterTestTypeApplyConfiguration{} + b.WithName(name) + b.WithKind("ClusterTestType") + b.WithAPIVersion("example-dashed.some.corp/v1") + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestTypeApplyConfiguration { + b.TypeMetaApplyConfiguration.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *ClusterTestTypeApplyConfiguration { + b.TypeMetaApplyConfiguration.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value apismetav1.Time) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value apismetav1.Time) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.ObjectMetaApplyConfiguration.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.ObjectMetaApplyConfiguration.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*metav1.OwnerReferenceApplyConfiguration) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *ClusterTestTypeApplyConfiguration) WithFinalizers(values ...string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) + } + return b +} + +func (b *ClusterTestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &metav1.ObjectMetaApplyConfiguration{} + } +} + +// WithObjectKind sets the ObjectKind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ObjectKind field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithObjectKind(value string) *ClusterTestTypeApplyConfiguration { + b.ObjectKind = &value + return b +} + +// WithObjectName sets the ObjectName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ObjectName field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithObjectName(value string) *ClusterTestTypeApplyConfiguration { + b.ObjectName = &value + return b +} + +// WithStatus sets the Status field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Status field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeStatusApplyConfiguration) *ClusterTestTypeApplyConfiguration { + b.Status = value + return b +} + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *ClusterTestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttypestatus.go new file mode 100644 index 000000000..9e9d64b6d --- /dev/null +++ b/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttypestatus.go @@ -0,0 +1,39 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use +// with apply. +type ClusterTestTypeStatusApplyConfiguration struct { + Blah *string `json:"blah,omitempty"` +} + +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with +// apply. +func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { + return &ClusterTestTypeStatusApplyConfiguration{} +} + +// WithBlah sets the Blah field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Blah field is set to the value of the last call. +func (b *ClusterTestTypeStatusApplyConfiguration) WithBlah(value string) *ClusterTestTypeStatusApplyConfiguration { + b.Blah = &value + return b +} diff --git a/examples/pkg/generated/applyconfigurations/exampledashed/v1/testtype.go b/examples/pkg/generated/applyconfigurations/exampledashed/v1/testtype.go new file mode 100644 index 000000000..78e62e25d --- /dev/null +++ b/examples/pkg/generated/applyconfigurations/exampledashed/v1/testtype.go @@ -0,0 +1,218 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +import ( + apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + metav1 "k8s.io/client-go/applyconfigurations/meta/v1" +) + +// TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use +// with apply. +type TestTypeApplyConfiguration struct { + metav1.TypeMetaApplyConfiguration `json:",inline"` + *metav1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + APIGroups []string `json:"apiGroups,omitempty"` +} + +// TestType constructs a declarative configuration of the TestType type for use with +// apply. +func TestType(name, namespace string) *TestTypeApplyConfiguration { + b := &TestTypeApplyConfiguration{} + b.WithName(name) + b.WithNamespace(namespace) + b.WithKind("TestType") + b.WithAPIVersion("example-dashed.some.corp/v1") + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfiguration { + b.TypeMetaApplyConfiguration.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApplyConfiguration { + b.TypeMetaApplyConfiguration.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value apismetav1.Time) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value apismetav1.Time) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.ObjectMetaApplyConfiguration.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.ObjectMetaApplyConfiguration.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*metav1.OwnerReferenceApplyConfiguration) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *TestTypeApplyConfiguration) WithFinalizers(values ...string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) + } + return b +} + +func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &metav1.ObjectMetaApplyConfiguration{} + } +} + +// WithAPIGroups adds the given value to the APIGroups field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the APIGroups field. +func (b *TestTypeApplyConfiguration) WithAPIGroups(values ...string) *TestTypeApplyConfiguration { + for i := range values { + b.APIGroups = append(b.APIGroups, values[i]) + } + return b +} + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *TestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttype.go index eaf698560..ee17dcc1a 100644 --- a/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttype.go @@ -14,27 +14,27 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" + metav1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// ClusterTestTypeApplyConfiguration represents an declarative configuration of the ClusterTestType type for use +// ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use // with apply. type ClusterTestTypeApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - ObjectKind *string `json:"kind,omitempty"` - ObjectName *string `json:"name,omitempty"` - Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` + metav1.TypeMetaApplyConfiguration `json:",inline"` + *metav1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + ObjectKind *string `json:"kind,omitempty"` + ObjectName *string `json:"name,omitempty"` + Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` } -// ClusterTestType constructs an declarative configuration of the ClusterTestType type for use with +// ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with // apply. func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { b := &ClusterTestTypeApplyConfiguration{} @@ -48,7 +48,7 @@ func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -56,7 +56,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestT // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *ClusterTestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -65,7 +65,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *Cluste // If called multiple times, the Name field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -74,7 +74,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestT // If called multiple times, the GenerateName field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -83,7 +83,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *Clus // If called multiple times, the Namespace field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -92,7 +92,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *Cluster // If called multiple times, the UID field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -101,7 +101,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTes // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -110,25 +110,25 @@ func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *C // If called multiple times, the Generation field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } // WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { +func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value apismetav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } // WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { +func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value apismetav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -137,7 +137,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -147,11 +147,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value // overwriting an existing map entries in Labels field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -162,11 +162,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string // overwriting an existing map entries in Annotations field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -174,13 +174,13 @@ func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]s // WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *ClusterTestTypeApplyConfiguration { +func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*metav1.OwnerReferenceApplyConfiguration) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -191,14 +191,14 @@ func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.Ow func (b *ClusterTestTypeApplyConfiguration) WithFinalizers(values ...string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } func (b *ClusterTestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + b.ObjectMetaApplyConfiguration = &metav1.ObjectMetaApplyConfiguration{} } } @@ -225,3 +225,9 @@ func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeSta b.Status = value return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *ClusterTestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttypestatus.go index a5457af72..9e9d64b6d 100644 --- a/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttypestatus.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 -// ClusterTestTypeStatusApplyConfiguration represents an declarative configuration of the ClusterTestTypeStatus type for use +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use // with apply. type ClusterTestTypeStatusApplyConfiguration struct { Blah *string `json:"blah,omitempty"` } -// ClusterTestTypeStatusApplyConfiguration constructs an declarative configuration of the ClusterTestTypeStatus type for use with +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with // apply. func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { return &ClusterTestTypeStatusApplyConfiguration{} diff --git a/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/testtype.go b/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/testtype.go index d7199a866..e4831aa56 100644 --- a/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/testtype.go +++ b/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/testtype.go @@ -14,25 +14,25 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" + metav1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// TestTypeApplyConfiguration represents an declarative configuration of the TestType type for use +// TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use // with apply. type TestTypeApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - APIGroups []string `json:"apiGroups,omitempty"` + metav1.TypeMetaApplyConfiguration `json:",inline"` + *metav1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + APIGroups []string `json:"apiGroups,omitempty"` } -// TestType constructs an declarative configuration of the TestType type for use with +// TestType constructs a declarative configuration of the TestType type for use with // apply. func TestType(name, namespace string) *TestTypeApplyConfiguration { b := &TestTypeApplyConfiguration{} @@ -47,7 +47,7 @@ func TestType(name, namespace string) *TestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -55,7 +55,7 @@ func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfig // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -64,7 +64,7 @@ func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApply // If called multiple times, the Name field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -73,7 +73,7 @@ func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfig // If called multiple times, the GenerateName field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -82,7 +82,7 @@ func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApp // If called multiple times, the Namespace field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -91,7 +91,7 @@ func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyC // If called multiple times, the UID field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -100,7 +100,7 @@ func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConf // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -109,25 +109,25 @@ func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestType // If called multiple times, the Generation field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } // WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *TestTypeApplyConfiguration { +func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value apismetav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } // WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *TestTypeApplyConfiguration { +func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value apismetav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -136,7 +136,7 @@ func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -146,11 +146,11 @@ func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) // overwriting an existing map entries in Labels field with the same key. func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -161,11 +161,11 @@ func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *Test // overwriting an existing map entries in Annotations field with the same key. func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -173,13 +173,13 @@ func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) // WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *TestTypeApplyConfiguration { +func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*metav1.OwnerReferenceApplyConfiguration) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -190,14 +190,14 @@ func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerRefe func (b *TestTypeApplyConfiguration) WithFinalizers(values ...string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + b.ObjectMetaApplyConfiguration = &metav1.ObjectMetaApplyConfiguration{} } } @@ -210,3 +210,9 @@ func (b *TestTypeApplyConfiguration) WithAPIGroups(values ...string) *TestTypeAp } return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *TestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/internal/internal.go b/examples/pkg/generated/applyconfigurations/internal/internal.go index cd52fc945..86ad90aa9 100644 --- a/examples/pkg/generated/applyconfigurations/internal/internal.go +++ b/examples/pkg/generated/applyconfigurations/internal/internal.go @@ -14,13 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package internal import ( - "fmt" - "sync" + fmt "fmt" + sync "sync" typed "sigs.k8s.io/structured-merge-diff/v4/typed" ) diff --git a/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttype.go index 64d78f367..c468e201b 100644 --- a/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttype.go +++ b/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttype.go @@ -14,33 +14,33 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" + metav1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// ClusterTestTypeApplyConfiguration represents an declarative configuration of the ClusterTestType type for use +// ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use // with apply. type ClusterTestTypeApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - ObjectKind *string `json:"kind,omitempty"` - ObjectName *string `json:"name,omitempty"` - Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` + metav1.TypeMetaApplyConfiguration `json:",inline"` + *metav1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + ObjectKind *string `json:"kind,omitempty"` + ObjectName *string `json:"name,omitempty"` + Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` } -// ClusterTestType constructs an declarative configuration of the ClusterTestType type for use with +// ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with // apply. func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { b := &ClusterTestTypeApplyConfiguration{} b.WithName(name) b.WithKind("ClusterTestType") - b.WithAPIVersion("secondexample/v1") + b.WithAPIVersion("secondexample.dev/v1") return b } @@ -48,7 +48,7 @@ func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -56,7 +56,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestT // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *ClusterTestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -65,7 +65,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *Cluste // If called multiple times, the Name field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -74,7 +74,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestT // If called multiple times, the GenerateName field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -83,7 +83,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *Clus // If called multiple times, the Namespace field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -92,7 +92,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *Cluster // If called multiple times, the UID field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -101,7 +101,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTes // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -110,25 +110,25 @@ func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *C // If called multiple times, the Generation field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } // WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { +func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value apismetav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } // WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { +func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value apismetav1.Time) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -137,7 +137,7 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -147,11 +147,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value // overwriting an existing map entries in Labels field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -162,11 +162,11 @@ func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string // overwriting an existing map entries in Annotations field with the same key. func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -174,13 +174,13 @@ func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]s // WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *ClusterTestTypeApplyConfiguration { +func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*metav1.OwnerReferenceApplyConfiguration) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -191,14 +191,14 @@ func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.Ow func (b *ClusterTestTypeApplyConfiguration) WithFinalizers(values ...string) *ClusterTestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } func (b *ClusterTestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + b.ObjectMetaApplyConfiguration = &metav1.ObjectMetaApplyConfiguration{} } } @@ -225,3 +225,9 @@ func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeSta b.Status = value return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *ClusterTestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttypestatus.go index a5457af72..9e9d64b6d 100644 --- a/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttypestatus.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 -// ClusterTestTypeStatusApplyConfiguration represents an declarative configuration of the ClusterTestTypeStatus type for use +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use // with apply. type ClusterTestTypeStatusApplyConfiguration struct { Blah *string `json:"blah,omitempty"` } -// ClusterTestTypeStatusApplyConfiguration constructs an declarative configuration of the ClusterTestTypeStatus type for use with +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with // apply. func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { return &ClusterTestTypeStatusApplyConfiguration{} diff --git a/examples/pkg/generated/applyconfigurations/secondexample/v1/testtype.go b/examples/pkg/generated/applyconfigurations/secondexample/v1/testtype.go index b9964e999..82e1fddbe 100644 --- a/examples/pkg/generated/applyconfigurations/secondexample/v1/testtype.go +++ b/examples/pkg/generated/applyconfigurations/secondexample/v1/testtype.go @@ -14,32 +14,32 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" - v1 "k8s.io/client-go/applyconfigurations/meta/v1" + metav1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// TestTypeApplyConfiguration represents an declarative configuration of the TestType type for use +// TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use // with apply. type TestTypeApplyConfiguration struct { - v1.TypeMetaApplyConfiguration `json:",inline"` - *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - APIGroups []string `json:"apiGroups,omitempty"` + metav1.TypeMetaApplyConfiguration `json:",inline"` + *metav1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + APIGroups []string `json:"apiGroups,omitempty"` } -// TestType constructs an declarative configuration of the TestType type for use with +// TestType constructs a declarative configuration of the TestType type for use with // apply. func TestType(name, namespace string) *TestTypeApplyConfiguration { b := &TestTypeApplyConfiguration{} b.WithName(name) b.WithNamespace(namespace) b.WithKind("TestType") - b.WithAPIVersion("secondexample/v1") + b.WithAPIVersion("secondexample.dev/v1") return b } @@ -47,7 +47,7 @@ func TestType(name, namespace string) *TestTypeApplyConfiguration { // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Kind field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfiguration { - b.Kind = &value + b.TypeMetaApplyConfiguration.Kind = &value return b } @@ -55,7 +55,7 @@ func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfig // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the APIVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApplyConfiguration { - b.APIVersion = &value + b.TypeMetaApplyConfiguration.APIVersion = &value return b } @@ -64,7 +64,7 @@ func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApply // If called multiple times, the Name field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Name = &value + b.ObjectMetaApplyConfiguration.Name = &value return b } @@ -73,7 +73,7 @@ func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfig // If called multiple times, the GenerateName field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.GenerateName = &value + b.ObjectMetaApplyConfiguration.GenerateName = &value return b } @@ -82,7 +82,7 @@ func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApp // If called multiple times, the Namespace field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Namespace = &value + b.ObjectMetaApplyConfiguration.Namespace = &value return b } @@ -91,7 +91,7 @@ func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyC // If called multiple times, the UID field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.UID = &value + b.ObjectMetaApplyConfiguration.UID = &value return b } @@ -100,7 +100,7 @@ func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConf // If called multiple times, the ResourceVersion field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.ResourceVersion = &value + b.ObjectMetaApplyConfiguration.ResourceVersion = &value return b } @@ -109,25 +109,25 @@ func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestType // If called multiple times, the Generation field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.Generation = &value + b.ObjectMetaApplyConfiguration.Generation = &value return b } // WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the CreationTimestamp field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *TestTypeApplyConfiguration { +func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value apismetav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.CreationTimestamp = &value + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value return b } // WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the DeletionTimestamp field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *TestTypeApplyConfiguration { +func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value apismetav1.Time) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionTimestamp = &value + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value return b } @@ -136,7 +136,7 @@ func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *T // If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - b.DeletionGracePeriodSeconds = &value + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value return b } @@ -146,11 +146,11 @@ func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) // overwriting an existing map entries in Labels field with the same key. func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Labels == nil && len(entries) > 0 { - b.Labels = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) } for k, v := range entries { - b.Labels[k] = v + b.ObjectMetaApplyConfiguration.Labels[k] = v } return b } @@ -161,11 +161,11 @@ func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *Test // overwriting an existing map entries in Annotations field with the same key. func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() - if b.Annotations == nil && len(entries) > 0 { - b.Annotations = make(map[string]string, len(entries)) + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) } for k, v := range entries { - b.Annotations[k] = v + b.ObjectMetaApplyConfiguration.Annotations[k] = v } return b } @@ -173,13 +173,13 @@ func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) // WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the OwnerReferences field. -func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *TestTypeApplyConfiguration { +func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*metav1.OwnerReferenceApplyConfiguration) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { if values[i] == nil { panic("nil value passed to WithOwnerReferences") } - b.OwnerReferences = append(b.OwnerReferences, *values[i]) + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) } return b } @@ -190,14 +190,14 @@ func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerRefe func (b *TestTypeApplyConfiguration) WithFinalizers(values ...string) *TestTypeApplyConfiguration { b.ensureObjectMetaApplyConfigurationExists() for i := range values { - b.Finalizers = append(b.Finalizers, values[i]) + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) } return b } func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { if b.ObjectMetaApplyConfiguration == nil { - b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + b.ObjectMetaApplyConfiguration = &metav1.ObjectMetaApplyConfiguration{} } } @@ -210,3 +210,9 @@ func (b *TestTypeApplyConfiguration) WithAPIGroups(values ...string) *TestTypeAp } return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *TestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/examples/pkg/generated/applyconfigurations/utils.go b/examples/pkg/generated/applyconfigurations/utils.go index 1d49f48b6..b08a518eb 100644 --- a/examples/pkg/generated/applyconfigurations/utils.go +++ b/examples/pkg/generated/applyconfigurations/utils.go @@ -14,44 +14,57 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by applyconfiguration-gen-v0.26.3. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package applyconfigurations import ( - schema "k8s.io/apimachinery/pkg/runtime/schema" - - v1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/apis/example/v1" v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" v1beta1 "acme.corp/pkg/apis/example/v1beta1" v2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + v1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - examplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" + applyconfigurationsexamplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" examplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" examplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" examplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" applyconfigurationsexample3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" + exampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" applyconfigurationsexistinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" + internal "acme.corp/pkg/generated/applyconfigurations/internal" applyconfigurationssecondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" + + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + testing "k8s.io/client-go/testing" ) // ForKind returns an apply configuration type for the given GroupVersionKind, or nil if no // apply configuration type exists for the given GroupVersionKind. func ForKind(kind schema.GroupVersionKind) interface{} { switch kind { - // Group=example, Version=v1 + // Group=example-dashed.some.corp, Version=v1 case v1.SchemeGroupVersion.WithKind("ClusterTestType"): - return &examplev1.ClusterTestTypeApplyConfiguration{} + return &exampledashedv1.ClusterTestTypeApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): - return &examplev1.ClusterTestTypeStatusApplyConfiguration{} + return &exampledashedv1.ClusterTestTypeStatusApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("TestType"): - return &examplev1.TestTypeApplyConfiguration{} - case v1.SchemeGroupVersion.WithKind("WithoutVerbType"): - return &examplev1.WithoutVerbTypeApplyConfiguration{} + return &exampledashedv1.TestTypeApplyConfiguration{} - // Group=example, Version=v1alpha1 + // Group=example.dev, Version=v1 + case examplev1.SchemeGroupVersion.WithKind("ClusterTestType"): + return &applyconfigurationsexamplev1.ClusterTestTypeApplyConfiguration{} + case examplev1.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): + return &applyconfigurationsexamplev1.ClusterTestTypeStatusApplyConfiguration{} + case examplev1.SchemeGroupVersion.WithKind("TestType"): + return &applyconfigurationsexamplev1.TestTypeApplyConfiguration{} + case examplev1.SchemeGroupVersion.WithKind("WithoutVerbType"): + return &applyconfigurationsexamplev1.WithoutVerbTypeApplyConfiguration{} + + // Group=example.dev, Version=v1alpha1 case v1alpha1.SchemeGroupVersion.WithKind("ClusterTestType"): return &examplev1alpha1.ClusterTestTypeApplyConfiguration{} case v1alpha1.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): @@ -59,7 +72,7 @@ func ForKind(kind schema.GroupVersionKind) interface{} { case v1alpha1.SchemeGroupVersion.WithKind("TestType"): return &examplev1alpha1.TestTypeApplyConfiguration{} - // Group=example, Version=v1beta1 + // Group=example.dev, Version=v1beta1 case v1beta1.SchemeGroupVersion.WithKind("ClusterTestType"): return &examplev1beta1.ClusterTestTypeApplyConfiguration{} case v1beta1.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): @@ -67,7 +80,7 @@ func ForKind(kind schema.GroupVersionKind) interface{} { case v1beta1.SchemeGroupVersion.WithKind("TestType"): return &examplev1beta1.TestTypeApplyConfiguration{} - // Group=example, Version=v2 + // Group=example.dev, Version=v2 case v2.SchemeGroupVersion.WithKind("ClusterTestType"): return &examplev2.ClusterTestTypeApplyConfiguration{} case v2.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): @@ -91,7 +104,7 @@ func ForKind(kind schema.GroupVersionKind) interface{} { case existinginterfacesv1.SchemeGroupVersion.WithKind("TestType"): return &applyconfigurationsexistinginterfacesv1.TestTypeApplyConfiguration{} - // Group=secondexample, Version=v1 + // Group=secondexample.dev, Version=v1 case secondexamplev1.SchemeGroupVersion.WithKind("ClusterTestType"): return &applyconfigurationssecondexamplev1.ClusterTestTypeApplyConfiguration{} case secondexamplev1.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): @@ -102,3 +115,7 @@ func ForKind(kind schema.GroupVersionKind) interface{} { } return nil } + +func NewTypeConverter(scheme *runtime.Scheme) *testing.TypeConverter { + return &testing.TypeConverter{Scheme: scheme, TypeResolver: internal.Parser()} +} diff --git a/examples/pkg/generated/clientset/versioned/clientset.go b/examples/pkg/generated/clientset/versioned/clientset.go index 9bc6476b9..5596fe778 100644 --- a/examples/pkg/generated/clientset/versioned/clientset.go +++ b/examples/pkg/generated/clientset/versioned/clientset.go @@ -14,25 +14,26 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package versioned import ( - "fmt" - "net/http" - - discovery "k8s.io/client-go/discovery" - rest "k8s.io/client-go/rest" - flowcontrol "k8s.io/client-go/util/flowcontrol" + fmt "fmt" + http "net/http" examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" ) type Interface interface { @@ -42,6 +43,7 @@ type Interface interface { ExampleV1beta1() examplev1beta1.ExampleV1beta1Interface ExampleV2() examplev2.ExampleV2Interface Example3V1() example3v1.Example3V1Interface + ExampleDashedV1() exampledashedv1.ExampleDashedV1Interface ExistinginterfacesV1() existinginterfacesv1.ExistinginterfacesV1Interface SecondexampleV1() secondexamplev1.SecondexampleV1Interface } @@ -54,6 +56,7 @@ type Clientset struct { exampleV1beta1 *examplev1beta1.ExampleV1beta1Client exampleV2 *examplev2.ExampleV2Client example3V1 *example3v1.Example3V1Client + exampleDashedV1 *exampledashedv1.ExampleDashedV1Client existinginterfacesV1 *existinginterfacesv1.ExistinginterfacesV1Client secondexampleV1 *secondexamplev1.SecondexampleV1Client } @@ -83,6 +86,11 @@ func (c *Clientset) Example3V1() example3v1.Example3V1Interface { return c.example3V1 } +// ExampleDashedV1 retrieves the ExampleDashedV1Client +func (c *Clientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1Interface { + return c.exampleDashedV1 +} + // ExistinginterfacesV1 retrieves the ExistinginterfacesV1Client func (c *Clientset) ExistinginterfacesV1() existinginterfacesv1.ExistinginterfacesV1Interface { return c.existinginterfacesV1 @@ -157,6 +165,10 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, if err != nil { return nil, err } + cs.exampleDashedV1, err = exampledashedv1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } cs.existinginterfacesV1, err = existinginterfacesv1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err @@ -191,6 +203,7 @@ func New(c rest.Interface) *Clientset { cs.exampleV1beta1 = examplev1beta1.New(c) cs.exampleV2 = examplev2.New(c) cs.example3V1 = example3v1.New(c) + cs.exampleDashedV1 = exampledashedv1.New(c) cs.existinginterfacesV1 = existinginterfacesv1.New(c) cs.secondexampleV1 = secondexamplev1.New(c) diff --git a/examples/pkg/generated/clientset/versioned/fake/clientset_generated.go b/examples/pkg/generated/clientset/versioned/fake/clientset_generated.go index 9159e84df..31254267b 100644 --- a/examples/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/examples/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -14,17 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/discovery" - fakediscovery "k8s.io/client-go/discovery/fake" - "k8s.io/client-go/testing" - + applyconfigurations "acme.corp/pkg/generated/applyconfigurations" clientset "acme.corp/pkg/generated/clientset/versioned" examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" fakeexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1/fake" @@ -36,16 +31,29 @@ import ( fakeexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2/fake" example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" fakeexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1/fake" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + fakeexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake" existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" fakeexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake" secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" fakesecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1/fake" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" ) // NewSimpleClientset returns a clientset that will respond with the provided objects. // It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement +// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement // for a real clientset and is mostly useful in simple unit tests. +// +// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves +// server side apply testing. NewClientset is only available when apply configurations are generated (e.g. +// via --with-applyconfig). func NewSimpleClientset(objects ...runtime.Object) *Clientset { o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) for _, obj := range objects { @@ -58,9 +66,13 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset { cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} cs.AddReactor("*", "*", testing.ObjectReaction(o)) cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + var opts metav1.ListOptions + if watchActcion, ok := action.(testing.WatchActionImpl); ok { + opts = watchActcion.ListOptions + } gvr := action.GetResource() ns := action.GetNamespace() - watch, err := o.Watch(gvr, ns) + watch, err := o.Watch(gvr, ns, opts) if err != nil { return false, nil, err } @@ -87,6 +99,42 @@ func (c *Clientset) Tracker() testing.ObjectTracker { return c.tracker } +// NewClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewClientset(objects ...runtime.Object) *Clientset { + o := testing.NewFieldManagedObjectTracker( + scheme, + codecs.UniversalDecoder(), + applyconfigurations.NewTypeConverter(scheme), + ) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + cs := &Clientset{tracker: o} + cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.AddReactor("*", "*", testing.ObjectReaction(o)) + cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + var opts metav1.ListOptions + if watchActcion, ok := action.(testing.WatchActionImpl); ok { + opts = watchActcion.ListOptions + } + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns, opts) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + var ( _ clientset.Interface = &Clientset{} _ testing.FakeClient = &Clientset{} @@ -117,6 +165,11 @@ func (c *Clientset) Example3V1() example3v1.Example3V1Interface { return &fakeexample3v1.FakeExample3V1{Fake: &c.Fake} } +// ExampleDashedV1 retrieves the ExampleDashedV1Client +func (c *Clientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1Interface { + return &fakeexampledashedv1.FakeExampleDashedV1{Fake: &c.Fake} +} + // ExistinginterfacesV1 retrieves the ExistinginterfacesV1Client func (c *Clientset) ExistinginterfacesV1() existinginterfacesv1.ExistinginterfacesV1Interface { return &fakeexistinginterfacesv1.FakeExistinginterfacesV1{Fake: &c.Fake} diff --git a/examples/pkg/generated/clientset/versioned/fake/doc.go b/examples/pkg/generated/clientset/versioned/fake/doc.go index ae835ad95..d134e6f33 100644 --- a/examples/pkg/generated/clientset/versioned/fake/doc.go +++ b/examples/pkg/generated/clientset/versioned/fake/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated fake clientset. package fake diff --git a/examples/pkg/generated/clientset/versioned/fake/register.go b/examples/pkg/generated/clientset/versioned/fake/register.go index 4842f975d..70dffd2b9 100644 --- a/examples/pkg/generated/clientset/versioned/fake/register.go +++ b/examples/pkg/generated/clientset/versioned/fake/register.go @@ -14,24 +14,25 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - examplev1 "acme.corp/pkg/apis/example/v1" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" ) var scheme = runtime.NewScheme() @@ -43,6 +44,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{ examplev1beta1.AddToScheme, examplev2.AddToScheme, example3v1.AddToScheme, + exampledashedv1.AddToScheme, existinginterfacesv1.AddToScheme, secondexamplev1.AddToScheme, } diff --git a/examples/pkg/generated/clientset/versioned/scheme/doc.go b/examples/pkg/generated/clientset/versioned/scheme/doc.go index 9708489e5..0a0dd78ea 100644 --- a/examples/pkg/generated/clientset/versioned/scheme/doc.go +++ b/examples/pkg/generated/clientset/versioned/scheme/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // This package contains the scheme of the automatically generated clientset. package scheme diff --git a/examples/pkg/generated/clientset/versioned/scheme/register.go b/examples/pkg/generated/clientset/versioned/scheme/register.go index b93d14457..e6d28263e 100644 --- a/examples/pkg/generated/clientset/versioned/scheme/register.go +++ b/examples/pkg/generated/clientset/versioned/scheme/register.go @@ -14,24 +14,25 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package scheme import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - examplev1 "acme.corp/pkg/apis/example/v1" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" ) var Scheme = runtime.NewScheme() @@ -43,6 +44,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{ examplev1beta1.AddToScheme, examplev2.AddToScheme, example3v1.AddToScheme, + exampledashedv1.AddToScheme, existinginterfacesv1.AddToScheme, secondexamplev1.AddToScheme, } diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1/clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1/clustertesttype.go index 286ebc563..48ecfa3cf 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/clustertesttype.go @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + + examplev1 "acme.corp/pkg/apis/example/v1" + applyconfigurationsexamplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - v1 "acme.corp/pkg/apis/example/v1" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // ClusterTestTypesGetter has a method to return a ClusterTestTypeInterface. @@ -39,147 +39,37 @@ type ClusterTestTypesGetter interface { // ClusterTestTypeInterface has methods to work with ClusterTestType resources. type ClusterTestTypeInterface interface { - Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (*v1.ClusterTestType, error) - Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) - UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) + Create(ctx context.Context, clusterTestType *examplev1.ClusterTestType, opts metav1.CreateOptions) (*examplev1.ClusterTestType, error) + Update(ctx context.Context, clusterTestType *examplev1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1.ClusterTestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, clusterTestType *examplev1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1.ClusterTestType, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.ClusterTestType, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.ClusterTestTypeList, error) + Get(ctx context.Context, name string, opts metav1.GetOptions) (*examplev1.ClusterTestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*examplev1.ClusterTestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *examplev1.ClusterTestType, err error) + Apply(ctx context.Context, clusterTestType *applyconfigurationsexamplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *examplev1.ClusterTestType, err error) + // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). + ApplyStatus(ctx context.Context, clusterTestType *applyconfigurationsexamplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *examplev1.ClusterTestType, err error) ClusterTestTypeExpansion } // clusterTestTypes implements ClusterTestTypeInterface type clusterTestTypes struct { - client rest.Interface + *gentype.ClientWithListAndApply[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList, *applyconfigurationsexamplev1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *ExampleV1Client) *clusterTestTypes { return &clusterTestTypes{ - client: c.RESTClient(), + gentype.NewClientWithListAndApply[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList, *applyconfigurationsexamplev1.ClusterTestTypeApplyConfiguration]( + "clustertesttypes", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *examplev1.ClusterTestType { return &examplev1.ClusterTestType{} }, + func() *examplev1.ClusterTestTypeList { return &examplev1.ClusterTestTypeList{} }, + ), } } - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *clusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Get(). - Resource("clustertesttypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.ClusterTestTypeList{} - err = c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *clusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Post(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *clusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *clusterTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Resource("clustertesttypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *clusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Resource("clustertesttypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *clusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Patch(pt). - Resource("clustertesttypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1/doc.go b/examples/pkg/generated/clientset/versioned/typed/example/v1/doc.go index 9d46e1563..278483ba7 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated typed clients. package v1 diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1/example_client.go b/examples/pkg/generated/clientset/versioned/typed/example/v1/example_client.go index 29c1d81f3..6b30f8bb5 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/example_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/example_client.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - "net/http" + http "net/http" - rest "k8s.io/client-go/rest" + examplev1 "acme.corp/pkg/apis/example/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" - v1 "acme.corp/pkg/apis/example/v1" - "acme.corp/pkg/generated/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" ) type ExampleV1Interface interface { @@ -34,7 +34,7 @@ type ExampleV1Interface interface { WithoutVerbTypesGetter } -// ExampleV1Client is used to interact with features provided by the example group. +// ExampleV1Client is used to interact with features provided by the example.dev group. type ExampleV1Client struct { restClient rest.Interface } @@ -56,9 +56,7 @@ func (c *ExampleV1Client) WithoutVerbTypes(namespace string) WithoutVerbTypeInte // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExampleV1Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err @@ -70,9 +68,7 @@ func NewForConfig(c *rest.Config) (*ExampleV1Client, error) { // Note the http client provided takes precedence over the configured transport values. func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV1Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) client, err := rest.RESTClientForConfigAndClient(&config, h) if err != nil { return nil, err @@ -95,17 +91,15 @@ func New(c rest.Interface) *ExampleV1Client { return &ExampleV1Client{c} } -func setConfigDefaults(config *rest.Config) error { - gv := v1.SchemeGroupVersion +func setConfigDefaults(config *rest.Config) { + gv := examplev1.SchemeGroupVersion config.GroupVersion = &gv config.APIPath = "/apis" - config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() if config.UserAgent == "" { config.UserAgent = rest.DefaultKubernetesUserAgent() } - - return nil } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/doc.go b/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/doc.go index fbcf54bc4..e388f2918 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // Package fake has the automatically generated clients. package fake diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go index 8a85cf26d..a277f46b2 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go @@ -14,121 +14,39 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" + v1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - - examplev1 "acme.corp/pkg/apis/example/v1" + gentype "k8s.io/client-go/gentype" ) -// FakeClusterTestTypes implements ClusterTestTypeInterface -type FakeClusterTestTypes struct { +// fakeClusterTestTypes implements ClusterTestTypeInterface +type fakeClusterTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *examplev1.ClusterTestTypeApplyConfiguration] Fake *FakeExampleV1 } -var clustertesttypesResource = schema.GroupVersionResource{Group: "example", Version: "v1", Resource: "clustertesttypes"} - -var clustertesttypesKind = schema.GroupVersionKind{Group: "example", Version: "v1", Kind: "ClusterTestType"} - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *examplev1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootGetAction(clustertesttypesResource, name), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *FakeClusterTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *examplev1.ClusterTestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootListAction(clustertesttypesResource, clustertesttypesKind, opts), &examplev1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1.ClusterTestTypeList{ListMeta: obj.(*examplev1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchAction(clustertesttypesResource, opts)) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *examplev1.ClusterTestType, opts v1.CreateOptions) (result *examplev1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(clustertesttypesResource, clusterTestType), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *examplev1.ClusterTestType, opts v1.UpdateOptions) (result *examplev1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(clustertesttypesResource, clusterTestType), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *examplev1.ClusterTestType, opts v1.UpdateOptions) (*examplev1.ClusterTestType, error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(clustertesttypesResource, "status", clusterTestType), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &examplev1.ClusterTestType{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(clustertesttypesResource, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1.ClusterTestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *examplev1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, name, pt, data, subresources...), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypes(fake *FakeExampleV1) typedexamplev1.ClusterTestTypeInterface { + return &fakeClusterTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *examplev1.ClusterTestTypeApplyConfiguration]( + fake.Fake, + "", + v1.SchemeGroupVersion.WithResource("clustertesttypes"), + v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *v1.ClusterTestType { return &v1.ClusterTestType{} }, + func() *v1.ClusterTestTypeList { return &v1.ClusterTestTypeList{} }, + func(dst, src *v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.ClusterTestTypeList) []*v1.ClusterTestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.ClusterTestTypeList, items []*v1.ClusterTestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*examplev1.ClusterTestType), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_example_client.go b/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_example_client.go index 3358e8636..be3832ab0 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_example_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_example_client.go @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( + v1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + rest "k8s.io/client-go/rest" testing "k8s.io/client-go/testing" - - v1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" ) type FakeExampleV1 struct { @@ -30,15 +30,15 @@ type FakeExampleV1 struct { } func (c *FakeExampleV1) ClusterTestTypes() v1.ClusterTestTypeInterface { - return &FakeClusterTestTypes{c} + return newFakeClusterTestTypes(c) } func (c *FakeExampleV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } func (c *FakeExampleV1) WithoutVerbTypes(namespace string) v1.WithoutVerbTypeInterface { - return &FakeWithoutVerbTypes{c, namespace} + return newFakeWithoutVerbTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_testtype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_testtype.go index 79c43e863..77a33ca0d 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_testtype.go @@ -14,151 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" + context "context" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" + v1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" - examplev1 "acme.corp/pkg/apis/example/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + gentype "k8s.io/client-go/gentype" + testing "k8s.io/client-go/testing" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *examplev1.TestTypeApplyConfiguration] Fake *FakeExampleV1 - ns string -} - -var testtypesResource = schema.GroupVersionResource{Group: "example", Version: "v1", Resource: "testtypes"} - -var testtypesKind = schema.GroupVersionKind{Group: "example", Version: "v1", Kind: "TestType"} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *examplev1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(testtypesResource, c.ns, name), &examplev1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *examplev1.TestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(testtypesResource, testtypesKind, c.ns, opts), &examplev1.TestTypeList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1.TestTypeList{ListMeta: obj.(*examplev1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(testtypesResource, c.ns, opts)) - } -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *examplev1.TestType, opts v1.CreateOptions) (result *examplev1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(testtypesResource, c.ns, testType), &examplev1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *examplev1.TestType, opts v1.UpdateOptions) (result *examplev1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(testtypesResource, c.ns, testType), &examplev1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &examplev1.TestType{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(testtypesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *examplev1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, name, pt, data, subresources...), &examplev1.TestType{}) - - if obj == nil { - return nil, err +func newFakeTestTypes(fake *FakeExampleV1, namespace string) typedexamplev1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *examplev1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*examplev1.TestType), err } // CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. -func (c *FakeTestTypes) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts v1.CreateOptions) (result *examplev1.Field, err error) { +func (c *fakeTestTypes) CreateField(ctx context.Context, testTypeName string, field *v1.Field, opts metav1.CreateOptions) (result *v1.Field, err error) { + emptyResult := &v1.Field{} obj, err := c.Fake. - Invokes(testing.NewCreateSubresourceAction(testtypesResource, testTypeName, "field", c.ns, field), &examplev1.Field{}) + Invokes(testing.NewCreateSubresourceActionWithOptions(c.Resource(), testTypeName, "field", c.Namespace(), field, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } - return obj.(*examplev1.Field), err + return obj.(*v1.Field), err } // UpdateField takes the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. -func (c *FakeTestTypes) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts v1.UpdateOptions) (result *examplev1.Field, err error) { +func (c *fakeTestTypes) UpdateField(ctx context.Context, testTypeName string, field *v1.Field, opts metav1.UpdateOptions) (result *v1.Field, err error) { + emptyResult := &v1.Field{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(testtypesResource, "field", c.ns, field), &examplev1.Field{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(c.Resource(), "field", c.Namespace(), field, opts), &v1.Field{}) if obj == nil { - return nil, err + return emptyResult, err } - return obj.(*examplev1.Field), err + return obj.(*v1.Field), err } // GetField takes name of the testType, and returns the corresponding field object, and an error if there is any. -func (c *FakeTestTypes) GetField(ctx context.Context, testTypeName string, options v1.GetOptions) (result *examplev1.Field, err error) { +func (c *fakeTestTypes) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (result *v1.Field, err error) { + emptyResult := &v1.Field{} obj, err := c.Fake. - Invokes(testing.NewGetSubresourceAction(testtypesResource, c.ns, "field", testTypeName), &examplev1.Field{}) + Invokes(testing.NewGetSubresourceActionWithOptions(c.Resource(), c.Namespace(), "field", testTypeName, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } - return obj.(*examplev1.Field), err + return obj.(*v1.Field), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_withoutverbtype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_withoutverbtype.go index 42cc3f413..3fb554032 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_withoutverbtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/fake/fake_withoutverbtype.go @@ -14,12 +14,32 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake -// FakeWithoutVerbTypes implements WithoutVerbTypeInterface -type FakeWithoutVerbTypes struct { +import ( + v1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + + gentype "k8s.io/client-go/gentype" +) + +// fakeWithoutVerbTypes implements WithoutVerbTypeInterface +type fakeWithoutVerbTypes struct { + *gentype.FakeClient[*v1.WithoutVerbType] Fake *FakeExampleV1 - ns string +} + +func newFakeWithoutVerbTypes(fake *FakeExampleV1, namespace string) examplev1.WithoutVerbTypeInterface { + return &fakeWithoutVerbTypes{ + gentype.NewFakeClient[*v1.WithoutVerbType]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("withoutverbtypes"), + v1.SchemeGroupVersion.WithKind("WithoutVerbType"), + func() *v1.WithoutVerbType { return &v1.WithoutVerbType{} }, + ), + fake, + } } diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1/generated_expansion.go b/examples/pkg/generated/clientset/versioned/typed/example/v1/generated_expansion.go index 85512364f..90cc7d776 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/generated_expansion.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/generated_expansion.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1/testtype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1/testtype.go index e21691a47..ce44c3e43 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/testtype.go @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + + examplev1 "acme.corp/pkg/apis/example/v1" + applyconfigurationsexamplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - v1 "acme.corp/pkg/apis/example/v1" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // TestTypesGetter has a method to return a TestTypeInterface. @@ -39,154 +39,46 @@ type TestTypesGetter interface { // TestTypeInterface has methods to work with TestType resources. type TestTypeInterface interface { - Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (*v1.TestType, error) - Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) + Create(ctx context.Context, testType *examplev1.TestType, opts metav1.CreateOptions) (*examplev1.TestType, error) + Update(ctx context.Context, testType *examplev1.TestType, opts metav1.UpdateOptions) (*examplev1.TestType, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.TestType, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.TestTypeList, error) + Get(ctx context.Context, name string, opts metav1.GetOptions) (*examplev1.TestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*examplev1.TestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) - CreateField(ctx context.Context, testTypeName string, field *v1.Field, opts metav1.CreateOptions) (*v1.Field, error) - UpdateField(ctx context.Context, testTypeName string, field *v1.Field, opts metav1.UpdateOptions) (*v1.Field, error) - GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*v1.Field, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *examplev1.TestType, err error) + Apply(ctx context.Context, testType *applyconfigurationsexamplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *examplev1.TestType, err error) + CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (*examplev1.Field, error) + UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (*examplev1.Field, error) + GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*examplev1.Field, error) TestTypeExpansion } // testTypes implements TestTypeInterface type testTypes struct { - client rest.Interface - ns string + *gentype.ClientWithListAndApply[*examplev1.TestType, *examplev1.TestTypeList, *applyconfigurationsexamplev1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *ExampleV1Client, namespace string) *testTypes { return &testTypes{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *testTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.TestTypeList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *testTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Post(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Put(). - Namespace(c.ns). - Resource("testtypes"). - Name(testType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *testTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *testTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + gentype.NewClientWithListAndApply[*examplev1.TestType, *examplev1.TestTypeList, *applyconfigurationsexamplev1.TestTypeApplyConfiguration]( + "testtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *examplev1.TestType { return &examplev1.TestType{} }, + func() *examplev1.TestTypeList { return &examplev1.TestTypeList{} }, + ), } - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched testType. -func (c *testTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return } // CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. -func (c *testTypes) CreateField(ctx context.Context, testTypeName string, field *v1.Field, opts metav1.CreateOptions) (result *v1.Field, err error) { - result = &v1.Field{} - err = c.client.Post(). - Namespace(c.ns). +func (c *testTypes) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (result *examplev1.Field, err error) { + result = &examplev1.Field{} + err = c.GetClient().Post(). + Namespace(c.GetNamespace()). Resource("testtypes"). Name(testTypeName). SubResource("field"). @@ -198,10 +90,10 @@ func (c *testTypes) CreateField(ctx context.Context, testTypeName string, field } // UpdateField takes the top resource name and the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. -func (c *testTypes) UpdateField(ctx context.Context, testTypeName string, field *v1.Field, opts metav1.UpdateOptions) (result *v1.Field, err error) { - result = &v1.Field{} - err = c.client.Put(). - Namespace(c.ns). +func (c *testTypes) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (result *examplev1.Field, err error) { + result = &examplev1.Field{} + err = c.GetClient().Put(). + Namespace(c.GetNamespace()). Resource("testtypes"). Name(testTypeName). SubResource("field"). @@ -212,11 +104,11 @@ func (c *testTypes) UpdateField(ctx context.Context, testTypeName string, field return } -// GetField takes name of the testType, and returns the corresponding v1.Field object, and an error if there is any. -func (c *testTypes) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (result *v1.Field, err error) { - result = &v1.Field{} - err = c.client.Get(). - Namespace(c.ns). +// GetField takes name of the testType, and returns the corresponding examplev1.Field object, and an error if there is any. +func (c *testTypes) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (result *examplev1.Field, err error) { + result = &examplev1.Field{} + err = c.GetClient().Get(). + Namespace(c.GetNamespace()). Resource("testtypes"). Name(testTypeName). SubResource("field"). diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1/withoutverbtype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1/withoutverbtype.go index 43cfbf95a..b9f74fe56 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/withoutverbtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/withoutverbtype.go @@ -14,12 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - rest "k8s.io/client-go/rest" + examplev1 "acme.corp/pkg/apis/example/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + + gentype "k8s.io/client-go/gentype" ) // WithoutVerbTypesGetter has a method to return a WithoutVerbTypeInterface. @@ -35,14 +38,18 @@ type WithoutVerbTypeInterface interface { // withoutVerbTypes implements WithoutVerbTypeInterface type withoutVerbTypes struct { - client rest.Interface - ns string + *gentype.Client[*examplev1.WithoutVerbType] } // newWithoutVerbTypes returns a WithoutVerbTypes func newWithoutVerbTypes(c *ExampleV1Client, namespace string) *withoutVerbTypes { return &withoutVerbTypes{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClient[*examplev1.WithoutVerbType]( + "withoutverbtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *examplev1.WithoutVerbType { return &examplev1.WithoutVerbType{} }, + ), } } diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/clustertesttype.go index 868d7dbc8..d81c3789a 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/clustertesttype.go @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1alpha1 import ( - "context" - "time" + context "context" + + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + applyconfigurationsexamplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // ClusterTestTypesGetter has a method to return a ClusterTestTypeInterface. @@ -39,147 +39,37 @@ type ClusterTestTypesGetter interface { // ClusterTestTypeInterface has methods to work with ClusterTestType resources. type ClusterTestTypeInterface interface { - Create(ctx context.Context, clusterTestType *v1alpha1.ClusterTestType, opts v1.CreateOptions) (*v1alpha1.ClusterTestType, error) - Update(ctx context.Context, clusterTestType *v1alpha1.ClusterTestType, opts v1.UpdateOptions) (*v1alpha1.ClusterTestType, error) - UpdateStatus(ctx context.Context, clusterTestType *v1alpha1.ClusterTestType, opts v1.UpdateOptions) (*v1alpha1.ClusterTestType, error) + Create(ctx context.Context, clusterTestType *examplev1alpha1.ClusterTestType, opts v1.CreateOptions) (*examplev1alpha1.ClusterTestType, error) + Update(ctx context.Context, clusterTestType *examplev1alpha1.ClusterTestType, opts v1.UpdateOptions) (*examplev1alpha1.ClusterTestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, clusterTestType *examplev1alpha1.ClusterTestType, opts v1.UpdateOptions) (*examplev1alpha1.ClusterTestType, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.ClusterTestType, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.ClusterTestTypeList, error) + Get(ctx context.Context, name string, opts v1.GetOptions) (*examplev1alpha1.ClusterTestType, error) + List(ctx context.Context, opts v1.ListOptions) (*examplev1alpha1.ClusterTestTypeList, error) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ClusterTestType, err error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *examplev1alpha1.ClusterTestType, err error) + Apply(ctx context.Context, clusterTestType *applyconfigurationsexamplev1alpha1.ClusterTestTypeApplyConfiguration, opts v1.ApplyOptions) (result *examplev1alpha1.ClusterTestType, err error) + // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). + ApplyStatus(ctx context.Context, clusterTestType *applyconfigurationsexamplev1alpha1.ClusterTestTypeApplyConfiguration, opts v1.ApplyOptions) (result *examplev1alpha1.ClusterTestType, err error) ClusterTestTypeExpansion } // clusterTestTypes implements ClusterTestTypeInterface type clusterTestTypes struct { - client rest.Interface + *gentype.ClientWithListAndApply[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList, *applyconfigurationsexamplev1alpha1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *ExampleV1alpha1Client) *clusterTestTypes { return &clusterTestTypes{ - client: c.RESTClient(), + gentype.NewClientWithListAndApply[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList, *applyconfigurationsexamplev1alpha1.ClusterTestTypeApplyConfiguration]( + "clustertesttypes", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *examplev1alpha1.ClusterTestType { return &examplev1alpha1.ClusterTestType{} }, + func() *examplev1alpha1.ClusterTestTypeList { return &examplev1alpha1.ClusterTestTypeList{} }, + ), } } - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *clusterTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.ClusterTestType, err error) { - result = &v1alpha1.ClusterTestType{} - err = c.client.Get(). - Resource("clustertesttypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ClusterTestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.ClusterTestTypeList{} - err = c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *clusterTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Create(ctx context.Context, clusterTestType *v1alpha1.ClusterTestType, opts v1.CreateOptions) (result *v1alpha1.ClusterTestType, err error) { - result = &v1alpha1.ClusterTestType{} - err = c.client.Post(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Update(ctx context.Context, clusterTestType *v1alpha1.ClusterTestType, opts v1.UpdateOptions) (result *v1alpha1.ClusterTestType, err error) { - result = &v1alpha1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *clusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1alpha1.ClusterTestType, opts v1.UpdateOptions) (result *v1alpha1.ClusterTestType, err error) { - result = &v1alpha1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *clusterTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Resource("clustertesttypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *clusterTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Resource("clustertesttypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *clusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ClusterTestType, err error) { - result = &v1alpha1.ClusterTestType{} - err = c.client.Patch(pt). - Resource("clustertesttypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/doc.go b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/doc.go index b474121a9..364b93c7c 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated typed clients. package v1alpha1 diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/example_client.go b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/example_client.go index 62279d4d1..c0bc38e21 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/example_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/example_client.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1alpha1 import ( - "net/http" + http "net/http" - rest "k8s.io/client-go/rest" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" - v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - "acme.corp/pkg/generated/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" ) type ExampleV1alpha1Interface interface { @@ -33,7 +33,7 @@ type ExampleV1alpha1Interface interface { TestTypesGetter } -// ExampleV1alpha1Client is used to interact with features provided by the example group. +// ExampleV1alpha1Client is used to interact with features provided by the example.dev group. type ExampleV1alpha1Client struct { restClient rest.Interface } @@ -51,9 +51,7 @@ func (c *ExampleV1alpha1Client) TestTypes(namespace string) TestTypeInterface { // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExampleV1alpha1Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err @@ -65,9 +63,7 @@ func NewForConfig(c *rest.Config) (*ExampleV1alpha1Client, error) { // Note the http client provided takes precedence over the configured transport values. func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV1alpha1Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) client, err := rest.RESTClientForConfigAndClient(&config, h) if err != nil { return nil, err @@ -90,17 +86,15 @@ func New(c rest.Interface) *ExampleV1alpha1Client { return &ExampleV1alpha1Client{c} } -func setConfigDefaults(config *rest.Config) error { - gv := v1alpha1.SchemeGroupVersion +func setConfigDefaults(config *rest.Config) { + gv := examplev1alpha1.SchemeGroupVersion config.GroupVersion = &gv config.APIPath = "/apis" - config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() if config.UserAgent == "" { config.UserAgent = rest.DefaultKubernetesUserAgent() } - - return nil } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/doc.go b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/doc.go index fbcf54bc4..e388f2918 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // Package fake has the automatically generated clients. package fake diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/fake_clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/fake_clustertesttype.go index 1a443f6f5..2e30b9398 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/fake_clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/fake_clustertesttype.go @@ -14,121 +14,41 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" + typedexamplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + + gentype "k8s.io/client-go/gentype" ) -// FakeClusterTestTypes implements ClusterTestTypeInterface -type FakeClusterTestTypes struct { +// fakeClusterTestTypes implements ClusterTestTypeInterface +type fakeClusterTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1alpha1.ClusterTestType, *v1alpha1.ClusterTestTypeList, *examplev1alpha1.ClusterTestTypeApplyConfiguration] Fake *FakeExampleV1alpha1 } -var clustertesttypesResource = schema.GroupVersionResource{Group: "example", Version: "v1alpha1", Resource: "clustertesttypes"} - -var clustertesttypesKind = schema.GroupVersionKind{Group: "example", Version: "v1alpha1", Kind: "ClusterTestType"} - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootGetAction(clustertesttypesResource, name), &v1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *FakeClusterTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ClusterTestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootListAction(clustertesttypesResource, clustertesttypesKind, opts), &v1alpha1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.ClusterTestTypeList{ListMeta: obj.(*v1alpha1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*v1alpha1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchAction(clustertesttypesResource, opts)) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *v1alpha1.ClusterTestType, opts v1.CreateOptions) (result *v1alpha1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(clustertesttypesResource, clusterTestType), &v1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.ClusterTestType), err -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *v1alpha1.ClusterTestType, opts v1.UpdateOptions) (result *v1alpha1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(clustertesttypesResource, clusterTestType), &v1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.ClusterTestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1alpha1.ClusterTestType, opts v1.UpdateOptions) (*v1alpha1.ClusterTestType, error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(clustertesttypesResource, "status", clusterTestType), &v1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.ClusterTestType), err -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &v1alpha1.ClusterTestType{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(clustertesttypesResource, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha1.ClusterTestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, name, pt, data, subresources...), &v1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypes(fake *FakeExampleV1alpha1) typedexamplev1alpha1.ClusterTestTypeInterface { + return &fakeClusterTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1alpha1.ClusterTestType, *v1alpha1.ClusterTestTypeList, *examplev1alpha1.ClusterTestTypeApplyConfiguration]( + fake.Fake, + "", + v1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"), + v1alpha1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *v1alpha1.ClusterTestType { return &v1alpha1.ClusterTestType{} }, + func() *v1alpha1.ClusterTestTypeList { return &v1alpha1.ClusterTestTypeList{} }, + func(dst, src *v1alpha1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1alpha1.ClusterTestTypeList) []*v1alpha1.ClusterTestType { + return gentype.ToPointerSlice(list.Items) + }, + func(list *v1alpha1.ClusterTestTypeList, items []*v1alpha1.ClusterTestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*v1alpha1.ClusterTestType), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/fake_example_client.go b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/fake_example_client.go index 90cc2e76f..232cc0846 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/fake_example_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/fake_example_client.go @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( + v1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + rest "k8s.io/client-go/rest" testing "k8s.io/client-go/testing" - - v1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" ) type FakeExampleV1alpha1 struct { @@ -30,11 +30,11 @@ type FakeExampleV1alpha1 struct { } func (c *FakeExampleV1alpha1) ClusterTestTypes() v1alpha1.ClusterTestTypeInterface { - return &FakeClusterTestTypes{c} + return newFakeClusterTestTypes(c) } func (c *FakeExampleV1alpha1) TestTypes(namespace string) v1alpha1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/fake_testtype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/fake_testtype.go index 2f14d337f..31e70ec79 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/fake_testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/fake/fake_testtype.go @@ -14,118 +14,39 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" + typedexamplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + + gentype "k8s.io/client-go/gentype" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1alpha1.TestType, *v1alpha1.TestTypeList, *examplev1alpha1.TestTypeApplyConfiguration] Fake *FakeExampleV1alpha1 - ns string -} - -var testtypesResource = schema.GroupVersionResource{Group: "example", Version: "v1alpha1", Resource: "testtypes"} - -var testtypesKind = schema.GroupVersionKind{Group: "example", Version: "v1alpha1", Kind: "TestType"} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(testtypesResource, c.ns, name), &v1alpha1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.TestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(testtypesResource, testtypesKind, c.ns, opts), &v1alpha1.TestTypeList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.TestTypeList{ListMeta: obj.(*v1alpha1.TestTypeList).ListMeta} - for _, item := range obj.(*v1alpha1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(testtypesResource, c.ns, opts)) - } -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1alpha1.TestType, opts v1.CreateOptions) (result *v1alpha1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(testtypesResource, c.ns, testType), &v1alpha1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1alpha1.TestType, opts v1.UpdateOptions) (result *v1alpha1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(testtypesResource, c.ns, testType), &v1alpha1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1alpha1.TestType{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(testtypesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, name, pt, data, subresources...), &v1alpha1.TestType{}) - - if obj == nil { - return nil, err +func newFakeTestTypes(fake *FakeExampleV1alpha1, namespace string) typedexamplev1alpha1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1alpha1.TestType, *v1alpha1.TestTypeList, *examplev1alpha1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1alpha1.SchemeGroupVersion.WithResource("testtypes"), + v1alpha1.SchemeGroupVersion.WithKind("TestType"), + func() *v1alpha1.TestType { return &v1alpha1.TestType{} }, + func() *v1alpha1.TestTypeList { return &v1alpha1.TestTypeList{} }, + func(dst, src *v1alpha1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1alpha1.TestTypeList) []*v1alpha1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1alpha1.TestTypeList, items []*v1alpha1.TestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*v1alpha1.TestType), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/generated_expansion.go b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/generated_expansion.go index 957625dbe..11c39294a 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/generated_expansion.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/generated_expansion.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1alpha1 diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/testtype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/testtype.go index c3f01fb9e..3234713c1 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/testtype.go @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1alpha1 import ( - "context" - "time" + context "context" + + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + applyconfigurationsexamplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // TestTypesGetter has a method to return a TestTypeInterface. @@ -39,141 +39,33 @@ type TestTypesGetter interface { // TestTypeInterface has methods to work with TestType resources. type TestTypeInterface interface { - Create(ctx context.Context, testType *v1alpha1.TestType, opts v1.CreateOptions) (*v1alpha1.TestType, error) - Update(ctx context.Context, testType *v1alpha1.TestType, opts v1.UpdateOptions) (*v1alpha1.TestType, error) + Create(ctx context.Context, testType *examplev1alpha1.TestType, opts v1.CreateOptions) (*examplev1alpha1.TestType, error) + Update(ctx context.Context, testType *examplev1alpha1.TestType, opts v1.UpdateOptions) (*examplev1alpha1.TestType, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.TestType, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.TestTypeList, error) + Get(ctx context.Context, name string, opts v1.GetOptions) (*examplev1alpha1.TestType, error) + List(ctx context.Context, opts v1.ListOptions) (*examplev1alpha1.TestTypeList, error) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.TestType, err error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *examplev1alpha1.TestType, err error) + Apply(ctx context.Context, testType *applyconfigurationsexamplev1alpha1.TestTypeApplyConfiguration, opts v1.ApplyOptions) (result *examplev1alpha1.TestType, err error) TestTypeExpansion } // testTypes implements TestTypeInterface type testTypes struct { - client rest.Interface - ns string + *gentype.ClientWithListAndApply[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList, *applyconfigurationsexamplev1alpha1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *ExampleV1alpha1Client, namespace string) *testTypes { return &testTypes{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *testTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.TestType, err error) { - result = &v1alpha1.TestType{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypes) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.TestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.TestTypeList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *testTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + gentype.NewClientWithListAndApply[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList, *applyconfigurationsexamplev1alpha1.TestTypeApplyConfiguration]( + "testtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *examplev1alpha1.TestType { return &examplev1alpha1.TestType{} }, + func() *examplev1alpha1.TestTypeList { return &examplev1alpha1.TestTypeList{} }, + ), } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Create(ctx context.Context, testType *v1alpha1.TestType, opts v1.CreateOptions) (result *v1alpha1.TestType, err error) { - result = &v1alpha1.TestType{} - err = c.client.Post(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Update(ctx context.Context, testType *v1alpha1.TestType, opts v1.UpdateOptions) (result *v1alpha1.TestType, err error) { - result = &v1alpha1.TestType{} - err = c.client.Put(). - Namespace(c.ns). - Resource("testtypes"). - Name(testType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *testTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *testTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched testType. -func (c *testTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.TestType, err error) { - result = &v1alpha1.TestType{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return } diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/clustertesttype.go index b9767e315..bb82d7a7a 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/clustertesttype.go @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1beta1 import ( - "context" - "time" + context "context" + + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + applyconfigurationsexamplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - v1beta1 "acme.corp/pkg/apis/example/v1beta1" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // ClusterTestTypesGetter has a method to return a ClusterTestTypeInterface. @@ -39,147 +39,37 @@ type ClusterTestTypesGetter interface { // ClusterTestTypeInterface has methods to work with ClusterTestType resources. type ClusterTestTypeInterface interface { - Create(ctx context.Context, clusterTestType *v1beta1.ClusterTestType, opts v1.CreateOptions) (*v1beta1.ClusterTestType, error) - Update(ctx context.Context, clusterTestType *v1beta1.ClusterTestType, opts v1.UpdateOptions) (*v1beta1.ClusterTestType, error) - UpdateStatus(ctx context.Context, clusterTestType *v1beta1.ClusterTestType, opts v1.UpdateOptions) (*v1beta1.ClusterTestType, error) + Create(ctx context.Context, clusterTestType *examplev1beta1.ClusterTestType, opts v1.CreateOptions) (*examplev1beta1.ClusterTestType, error) + Update(ctx context.Context, clusterTestType *examplev1beta1.ClusterTestType, opts v1.UpdateOptions) (*examplev1beta1.ClusterTestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, clusterTestType *examplev1beta1.ClusterTestType, opts v1.UpdateOptions) (*examplev1beta1.ClusterTestType, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.ClusterTestType, error) - List(ctx context.Context, opts v1.ListOptions) (*v1beta1.ClusterTestTypeList, error) + Get(ctx context.Context, name string, opts v1.GetOptions) (*examplev1beta1.ClusterTestType, error) + List(ctx context.Context, opts v1.ListOptions) (*examplev1beta1.ClusterTestTypeList, error) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ClusterTestType, err error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *examplev1beta1.ClusterTestType, err error) + Apply(ctx context.Context, clusterTestType *applyconfigurationsexamplev1beta1.ClusterTestTypeApplyConfiguration, opts v1.ApplyOptions) (result *examplev1beta1.ClusterTestType, err error) + // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). + ApplyStatus(ctx context.Context, clusterTestType *applyconfigurationsexamplev1beta1.ClusterTestTypeApplyConfiguration, opts v1.ApplyOptions) (result *examplev1beta1.ClusterTestType, err error) ClusterTestTypeExpansion } // clusterTestTypes implements ClusterTestTypeInterface type clusterTestTypes struct { - client rest.Interface + *gentype.ClientWithListAndApply[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList, *applyconfigurationsexamplev1beta1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *ExampleV1beta1Client) *clusterTestTypes { return &clusterTestTypes{ - client: c.RESTClient(), + gentype.NewClientWithListAndApply[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList, *applyconfigurationsexamplev1beta1.ClusterTestTypeApplyConfiguration]( + "clustertesttypes", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *examplev1beta1.ClusterTestType { return &examplev1beta1.ClusterTestType{} }, + func() *examplev1beta1.ClusterTestTypeList { return &examplev1beta1.ClusterTestTypeList{} }, + ), } } - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *clusterTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.ClusterTestType, err error) { - result = &v1beta1.ClusterTestType{} - err = c.client.Get(). - Resource("clustertesttypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.ClusterTestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1beta1.ClusterTestTypeList{} - err = c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *clusterTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Create(ctx context.Context, clusterTestType *v1beta1.ClusterTestType, opts v1.CreateOptions) (result *v1beta1.ClusterTestType, err error) { - result = &v1beta1.ClusterTestType{} - err = c.client.Post(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Update(ctx context.Context, clusterTestType *v1beta1.ClusterTestType, opts v1.UpdateOptions) (result *v1beta1.ClusterTestType, err error) { - result = &v1beta1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *clusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1beta1.ClusterTestType, opts v1.UpdateOptions) (result *v1beta1.ClusterTestType, err error) { - result = &v1beta1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *clusterTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Resource("clustertesttypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *clusterTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Resource("clustertesttypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *clusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ClusterTestType, err error) { - result = &v1beta1.ClusterTestType{} - err = c.client.Patch(pt). - Resource("clustertesttypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/doc.go b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/doc.go index 2b77111a2..b26badd93 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated typed clients. package v1beta1 diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/example_client.go b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/example_client.go index 378a9ed61..299bf93a6 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/example_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/example_client.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1beta1 import ( - "net/http" + http "net/http" - rest "k8s.io/client-go/rest" + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" - v1beta1 "acme.corp/pkg/apis/example/v1beta1" - "acme.corp/pkg/generated/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" ) type ExampleV1beta1Interface interface { @@ -33,7 +33,7 @@ type ExampleV1beta1Interface interface { TestTypesGetter } -// ExampleV1beta1Client is used to interact with features provided by the example group. +// ExampleV1beta1Client is used to interact with features provided by the example.dev group. type ExampleV1beta1Client struct { restClient rest.Interface } @@ -51,9 +51,7 @@ func (c *ExampleV1beta1Client) TestTypes(namespace string) TestTypeInterface { // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExampleV1beta1Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err @@ -65,9 +63,7 @@ func NewForConfig(c *rest.Config) (*ExampleV1beta1Client, error) { // Note the http client provided takes precedence over the configured transport values. func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV1beta1Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) client, err := rest.RESTClientForConfigAndClient(&config, h) if err != nil { return nil, err @@ -90,17 +86,15 @@ func New(c rest.Interface) *ExampleV1beta1Client { return &ExampleV1beta1Client{c} } -func setConfigDefaults(config *rest.Config) error { - gv := v1beta1.SchemeGroupVersion +func setConfigDefaults(config *rest.Config) { + gv := examplev1beta1.SchemeGroupVersion config.GroupVersion = &gv config.APIPath = "/apis" - config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() if config.UserAgent == "" { config.UserAgent = rest.DefaultKubernetesUserAgent() } - - return nil } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/doc.go b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/doc.go index fbcf54bc4..e388f2918 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // Package fake has the automatically generated clients. package fake diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_clustertesttype.go index 850c7e534..3452c9f6a 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_clustertesttype.go @@ -14,121 +14,41 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - v1beta1 "acme.corp/pkg/apis/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" + typedexamplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + + gentype "k8s.io/client-go/gentype" ) -// FakeClusterTestTypes implements ClusterTestTypeInterface -type FakeClusterTestTypes struct { +// fakeClusterTestTypes implements ClusterTestTypeInterface +type fakeClusterTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1beta1.ClusterTestType, *v1beta1.ClusterTestTypeList, *examplev1beta1.ClusterTestTypeApplyConfiguration] Fake *FakeExampleV1beta1 } -var clustertesttypesResource = schema.GroupVersionResource{Group: "example", Version: "v1beta1", Resource: "clustertesttypes"} - -var clustertesttypesKind = schema.GroupVersionKind{Group: "example", Version: "v1beta1", Kind: "ClusterTestType"} - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootGetAction(clustertesttypesResource, name), &v1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*v1beta1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *FakeClusterTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.ClusterTestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootListAction(clustertesttypesResource, clustertesttypesKind, opts), &v1beta1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1beta1.ClusterTestTypeList{ListMeta: obj.(*v1beta1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*v1beta1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchAction(clustertesttypesResource, opts)) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *v1beta1.ClusterTestType, opts v1.CreateOptions) (result *v1beta1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(clustertesttypesResource, clusterTestType), &v1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*v1beta1.ClusterTestType), err -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *v1beta1.ClusterTestType, opts v1.UpdateOptions) (result *v1beta1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(clustertesttypesResource, clusterTestType), &v1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*v1beta1.ClusterTestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1beta1.ClusterTestType, opts v1.UpdateOptions) (*v1beta1.ClusterTestType, error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(clustertesttypesResource, "status", clusterTestType), &v1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*v1beta1.ClusterTestType), err -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &v1beta1.ClusterTestType{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(clustertesttypesResource, listOpts) - - _, err := c.Fake.Invokes(action, &v1beta1.ClusterTestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, name, pt, data, subresources...), &v1beta1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypes(fake *FakeExampleV1beta1) typedexamplev1beta1.ClusterTestTypeInterface { + return &fakeClusterTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1beta1.ClusterTestType, *v1beta1.ClusterTestTypeList, *examplev1beta1.ClusterTestTypeApplyConfiguration]( + fake.Fake, + "", + v1beta1.SchemeGroupVersion.WithResource("clustertesttypes"), + v1beta1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *v1beta1.ClusterTestType { return &v1beta1.ClusterTestType{} }, + func() *v1beta1.ClusterTestTypeList { return &v1beta1.ClusterTestTypeList{} }, + func(dst, src *v1beta1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1beta1.ClusterTestTypeList) []*v1beta1.ClusterTestType { + return gentype.ToPointerSlice(list.Items) + }, + func(list *v1beta1.ClusterTestTypeList, items []*v1beta1.ClusterTestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*v1beta1.ClusterTestType), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_example_client.go b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_example_client.go index 90d0bea0b..ee5c425cd 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_example_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_example_client.go @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( + v1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + rest "k8s.io/client-go/rest" testing "k8s.io/client-go/testing" - - v1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" ) type FakeExampleV1beta1 struct { @@ -30,11 +30,11 @@ type FakeExampleV1beta1 struct { } func (c *FakeExampleV1beta1) ClusterTestTypes() v1beta1.ClusterTestTypeInterface { - return &FakeClusterTestTypes{c} + return newFakeClusterTestTypes(c) } func (c *FakeExampleV1beta1) TestTypes(namespace string) v1beta1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_testtype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_testtype.go index a37d17243..c8f634468 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_testtype.go @@ -14,87 +14,39 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - testing "k8s.io/client-go/testing" - v1beta1 "acme.corp/pkg/apis/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" + typedexamplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + + gentype "k8s.io/client-go/gentype" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1beta1.TestType, *v1beta1.TestTypeList, *examplev1beta1.TestTypeApplyConfiguration] Fake *FakeExampleV1beta1 - ns string -} - -var testtypesResource = schema.GroupVersionResource{Group: "example", Version: "v1beta1", Resource: "testtypes"} - -var testtypesKind = schema.GroupVersionKind{Group: "example", Version: "v1beta1", Kind: "TestType"} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(testtypesResource, c.ns, name), &v1beta1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*v1beta1.TestType), err -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1beta1.TestType, opts v1.CreateOptions) (result *v1beta1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(testtypesResource, c.ns, testType), &v1beta1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*v1beta1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1beta1.TestType, opts v1.UpdateOptions) (result *v1beta1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(testtypesResource, c.ns, testType), &v1beta1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*v1beta1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1beta1.TestType{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(testtypesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v1beta1.TestTypeList{}) - return err } -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, name, pt, data, subresources...), &v1beta1.TestType{}) - - if obj == nil { - return nil, err +func newFakeTestTypes(fake *FakeExampleV1beta1, namespace string) typedexamplev1beta1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1beta1.TestType, *v1beta1.TestTypeList, *examplev1beta1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1beta1.SchemeGroupVersion.WithResource("testtypes"), + v1beta1.SchemeGroupVersion.WithKind("TestType"), + func() *v1beta1.TestType { return &v1beta1.TestType{} }, + func() *v1beta1.TestTypeList { return &v1beta1.TestTypeList{} }, + func(dst, src *v1beta1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1beta1.TestTypeList) []*v1beta1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1beta1.TestTypeList, items []*v1beta1.TestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*v1beta1.TestType), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/generated_expansion.go b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/generated_expansion.go index c8fb9b3fb..09cefbb6d 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/generated_expansion.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/generated_expansion.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1beta1 diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/testtype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/testtype.go index 7da5f43d3..35ad821f9 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/testtype.go @@ -14,20 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1beta1 import ( - "context" - "time" + context "context" + + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + applyconfigurationsexamplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" - rest "k8s.io/client-go/rest" - - v1beta1 "acme.corp/pkg/apis/example/v1beta1" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" ) // TestTypesGetter has a method to return a TestTypeInterface. @@ -38,107 +39,33 @@ type TestTypesGetter interface { // TestTypeInterface has methods to work with TestType resources. type TestTypeInterface interface { - Create(ctx context.Context, testType *v1beta1.TestType, opts v1.CreateOptions) (*v1beta1.TestType, error) - Update(ctx context.Context, testType *v1beta1.TestType, opts v1.UpdateOptions) (*v1beta1.TestType, error) + Create(ctx context.Context, testType *examplev1beta1.TestType, opts v1.CreateOptions) (*examplev1beta1.TestType, error) + Update(ctx context.Context, testType *examplev1beta1.TestType, opts v1.UpdateOptions) (*examplev1beta1.TestType, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.TestType, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.TestType, err error) + Get(ctx context.Context, name string, opts v1.GetOptions) (*examplev1beta1.TestType, error) + List(ctx context.Context, opts v1.ListOptions) (*examplev1beta1.TestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *examplev1beta1.TestType, err error) + Apply(ctx context.Context, testType *applyconfigurationsexamplev1beta1.TestTypeApplyConfiguration, opts v1.ApplyOptions) (result *examplev1beta1.TestType, err error) TestTypeExpansion } // testTypes implements TestTypeInterface type testTypes struct { - client rest.Interface - ns string + *gentype.ClientWithListAndApply[*examplev1beta1.TestType, *examplev1beta1.TestTypeList, *applyconfigurationsexamplev1beta1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *ExampleV1beta1Client, namespace string) *testTypes { return &testTypes{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithListAndApply[*examplev1beta1.TestType, *examplev1beta1.TestTypeList, *applyconfigurationsexamplev1beta1.TestTypeApplyConfiguration]( + "testtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *examplev1beta1.TestType { return &examplev1beta1.TestType{} }, + func() *examplev1beta1.TestTypeList { return &examplev1beta1.TestTypeList{} }, + ), } } - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *testTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.TestType, err error) { - result = &v1beta1.TestType{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Create(ctx context.Context, testType *v1beta1.TestType, opts v1.CreateOptions) (result *v1beta1.TestType, err error) { - result = &v1beta1.TestType{} - err = c.client.Post(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Update(ctx context.Context, testType *v1beta1.TestType, opts v1.UpdateOptions) (result *v1beta1.TestType, err error) { - result = &v1beta1.TestType{} - err = c.client.Put(). - Namespace(c.ns). - Resource("testtypes"). - Name(testType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *testTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *testTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched testType. -func (c *testTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.TestType, err error) { - result = &v1beta1.TestType{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v2/clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/example/v2/clustertesttype.go index f04ff33e4..42c0b700c 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v2/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v2/clustertesttype.go @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v2 import ( - "context" - "time" + context "context" + + examplev2 "acme.corp/pkg/apis/example/v2" + applyconfigurationsexamplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - v2 "acme.corp/pkg/apis/example/v2" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // ClusterTestTypesGetter has a method to return a ClusterTestTypeInterface. @@ -39,147 +39,37 @@ type ClusterTestTypesGetter interface { // ClusterTestTypeInterface has methods to work with ClusterTestType resources. type ClusterTestTypeInterface interface { - Create(ctx context.Context, clusterTestType *v2.ClusterTestType, opts v1.CreateOptions) (*v2.ClusterTestType, error) - Update(ctx context.Context, clusterTestType *v2.ClusterTestType, opts v1.UpdateOptions) (*v2.ClusterTestType, error) - UpdateStatus(ctx context.Context, clusterTestType *v2.ClusterTestType, opts v1.UpdateOptions) (*v2.ClusterTestType, error) + Create(ctx context.Context, clusterTestType *examplev2.ClusterTestType, opts v1.CreateOptions) (*examplev2.ClusterTestType, error) + Update(ctx context.Context, clusterTestType *examplev2.ClusterTestType, opts v1.UpdateOptions) (*examplev2.ClusterTestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, clusterTestType *examplev2.ClusterTestType, opts v1.UpdateOptions) (*examplev2.ClusterTestType, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v2.ClusterTestType, error) - List(ctx context.Context, opts v1.ListOptions) (*v2.ClusterTestTypeList, error) + Get(ctx context.Context, name string, opts v1.GetOptions) (*examplev2.ClusterTestType, error) + List(ctx context.Context, opts v1.ListOptions) (*examplev2.ClusterTestTypeList, error) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.ClusterTestType, err error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *examplev2.ClusterTestType, err error) + Apply(ctx context.Context, clusterTestType *applyconfigurationsexamplev2.ClusterTestTypeApplyConfiguration, opts v1.ApplyOptions) (result *examplev2.ClusterTestType, err error) + // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). + ApplyStatus(ctx context.Context, clusterTestType *applyconfigurationsexamplev2.ClusterTestTypeApplyConfiguration, opts v1.ApplyOptions) (result *examplev2.ClusterTestType, err error) ClusterTestTypeExpansion } // clusterTestTypes implements ClusterTestTypeInterface type clusterTestTypes struct { - client rest.Interface + *gentype.ClientWithListAndApply[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList, *applyconfigurationsexamplev2.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *ExampleV2Client) *clusterTestTypes { return &clusterTestTypes{ - client: c.RESTClient(), + gentype.NewClientWithListAndApply[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList, *applyconfigurationsexamplev2.ClusterTestTypeApplyConfiguration]( + "clustertesttypes", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *examplev2.ClusterTestType { return &examplev2.ClusterTestType{} }, + func() *examplev2.ClusterTestTypeList { return &examplev2.ClusterTestTypeList{} }, + ), } } - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *clusterTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *v2.ClusterTestType, err error) { - result = &v2.ClusterTestType{} - err = c.client.Get(). - Resource("clustertesttypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *v2.ClusterTestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v2.ClusterTestTypeList{} - err = c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *clusterTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Create(ctx context.Context, clusterTestType *v2.ClusterTestType, opts v1.CreateOptions) (result *v2.ClusterTestType, err error) { - result = &v2.ClusterTestType{} - err = c.client.Post(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Update(ctx context.Context, clusterTestType *v2.ClusterTestType, opts v1.UpdateOptions) (result *v2.ClusterTestType, err error) { - result = &v2.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *clusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v2.ClusterTestType, opts v1.UpdateOptions) (result *v2.ClusterTestType, err error) { - result = &v2.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *clusterTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Resource("clustertesttypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *clusterTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Resource("clustertesttypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *clusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.ClusterTestType, err error) { - result = &v2.ClusterTestType{} - err = c.client.Patch(pt). - Resource("clustertesttypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v2/doc.go b/examples/pkg/generated/clientset/versioned/typed/example/v2/doc.go index 7d4464cc0..ac8e9046b 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v2/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v2/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated typed clients. package v2 diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v2/example_client.go b/examples/pkg/generated/clientset/versioned/typed/example/v2/example_client.go index 6f4b3bb97..f1d508a67 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v2/example_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v2/example_client.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v2 import ( - "net/http" + http "net/http" - rest "k8s.io/client-go/rest" + examplev2 "acme.corp/pkg/apis/example/v2" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" - v2 "acme.corp/pkg/apis/example/v2" - "acme.corp/pkg/generated/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" ) type ExampleV2Interface interface { @@ -33,7 +33,7 @@ type ExampleV2Interface interface { TestTypesGetter } -// ExampleV2Client is used to interact with features provided by the example group. +// ExampleV2Client is used to interact with features provided by the example.dev group. type ExampleV2Client struct { restClient rest.Interface } @@ -51,9 +51,7 @@ func (c *ExampleV2Client) TestTypes(namespace string) TestTypeInterface { // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExampleV2Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err @@ -65,9 +63,7 @@ func NewForConfig(c *rest.Config) (*ExampleV2Client, error) { // Note the http client provided takes precedence over the configured transport values. func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV2Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) client, err := rest.RESTClientForConfigAndClient(&config, h) if err != nil { return nil, err @@ -90,17 +86,15 @@ func New(c rest.Interface) *ExampleV2Client { return &ExampleV2Client{c} } -func setConfigDefaults(config *rest.Config) error { - gv := v2.SchemeGroupVersion +func setConfigDefaults(config *rest.Config) { + gv := examplev2.SchemeGroupVersion config.GroupVersion = &gv config.APIPath = "/apis" - config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() if config.UserAgent == "" { config.UserAgent = rest.DefaultKubernetesUserAgent() } - - return nil } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/doc.go b/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/doc.go index fbcf54bc4..e388f2918 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // Package fake has the automatically generated clients. package fake diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/fake_clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/fake_clustertesttype.go index 24aae6be1..c76612bba 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/fake_clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/fake_clustertesttype.go @@ -14,121 +14,39 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - v2 "acme.corp/pkg/apis/example/v2" + examplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" + typedexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + + gentype "k8s.io/client-go/gentype" ) -// FakeClusterTestTypes implements ClusterTestTypeInterface -type FakeClusterTestTypes struct { +// fakeClusterTestTypes implements ClusterTestTypeInterface +type fakeClusterTestTypes struct { + *gentype.FakeClientWithListAndApply[*v2.ClusterTestType, *v2.ClusterTestTypeList, *examplev2.ClusterTestTypeApplyConfiguration] Fake *FakeExampleV2 } -var clustertesttypesResource = schema.GroupVersionResource{Group: "example", Version: "v2", Resource: "clustertesttypes"} - -var clustertesttypesKind = schema.GroupVersionKind{Group: "example", Version: "v2", Kind: "ClusterTestType"} - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *v2.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootGetAction(clustertesttypesResource, name), &v2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*v2.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *FakeClusterTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *v2.ClusterTestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootListAction(clustertesttypesResource, clustertesttypesKind, opts), &v2.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v2.ClusterTestTypeList{ListMeta: obj.(*v2.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*v2.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchAction(clustertesttypesResource, opts)) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *v2.ClusterTestType, opts v1.CreateOptions) (result *v2.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(clustertesttypesResource, clusterTestType), &v2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*v2.ClusterTestType), err -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *v2.ClusterTestType, opts v1.UpdateOptions) (result *v2.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(clustertesttypesResource, clusterTestType), &v2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*v2.ClusterTestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v2.ClusterTestType, opts v1.UpdateOptions) (*v2.ClusterTestType, error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(clustertesttypesResource, "status", clusterTestType), &v2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*v2.ClusterTestType), err -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &v2.ClusterTestType{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(clustertesttypesResource, listOpts) - - _, err := c.Fake.Invokes(action, &v2.ClusterTestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, name, pt, data, subresources...), &v2.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypes(fake *FakeExampleV2) typedexamplev2.ClusterTestTypeInterface { + return &fakeClusterTestTypes{ + gentype.NewFakeClientWithListAndApply[*v2.ClusterTestType, *v2.ClusterTestTypeList, *examplev2.ClusterTestTypeApplyConfiguration]( + fake.Fake, + "", + v2.SchemeGroupVersion.WithResource("clustertesttypes"), + v2.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *v2.ClusterTestType { return &v2.ClusterTestType{} }, + func() *v2.ClusterTestTypeList { return &v2.ClusterTestTypeList{} }, + func(dst, src *v2.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v2.ClusterTestTypeList) []*v2.ClusterTestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v2.ClusterTestTypeList, items []*v2.ClusterTestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*v2.ClusterTestType), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/fake_example_client.go b/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/fake_example_client.go index af30ba28c..788bec8ad 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/fake_example_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/fake_example_client.go @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( + v2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + rest "k8s.io/client-go/rest" testing "k8s.io/client-go/testing" - - v2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" ) type FakeExampleV2 struct { @@ -30,11 +30,11 @@ type FakeExampleV2 struct { } func (c *FakeExampleV2) ClusterTestTypes() v2.ClusterTestTypeInterface { - return &FakeClusterTestTypes{c} + return newFakeClusterTestTypes(c) } func (c *FakeExampleV2) TestTypes(namespace string) v2.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/fake_testtype.go b/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/fake_testtype.go index d7e0e2ff5..369a9381f 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/fake_testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v2/fake/fake_testtype.go @@ -14,118 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - v2 "acme.corp/pkg/apis/example/v2" + examplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" + typedexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + + gentype "k8s.io/client-go/gentype" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v2.TestType, *v2.TestTypeList, *examplev2.TestTypeApplyConfiguration] Fake *FakeExampleV2 - ns string -} - -var testtypesResource = schema.GroupVersionResource{Group: "example", Version: "v2", Resource: "testtypes"} - -var testtypesKind = schema.GroupVersionKind{Group: "example", Version: "v2", Kind: "TestType"} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *v2.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(testtypesResource, c.ns, name), &v2.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*v2.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *v2.TestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(testtypesResource, testtypesKind, c.ns, opts), &v2.TestTypeList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v2.TestTypeList{ListMeta: obj.(*v2.TestTypeList).ListMeta} - for _, item := range obj.(*v2.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(testtypesResource, c.ns, opts)) - } -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v2.TestType, opts v1.CreateOptions) (result *v2.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(testtypesResource, c.ns, testType), &v2.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*v2.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v2.TestType, opts v1.UpdateOptions) (result *v2.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(testtypesResource, c.ns, testType), &v2.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*v2.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v2.TestType{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(testtypesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v2.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, name, pt, data, subresources...), &v2.TestType{}) - - if obj == nil { - return nil, err +func newFakeTestTypes(fake *FakeExampleV2, namespace string) typedexamplev2.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v2.TestType, *v2.TestTypeList, *examplev2.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v2.SchemeGroupVersion.WithResource("testtypes"), + v2.SchemeGroupVersion.WithKind("TestType"), + func() *v2.TestType { return &v2.TestType{} }, + func() *v2.TestTypeList { return &v2.TestTypeList{} }, + func(dst, src *v2.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v2.TestTypeList) []*v2.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v2.TestTypeList, items []*v2.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*v2.TestType), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v2/generated_expansion.go b/examples/pkg/generated/clientset/versioned/typed/example/v2/generated_expansion.go index a00a9acf0..851edf094 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v2/generated_expansion.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v2/generated_expansion.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v2 diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v2/testtype.go b/examples/pkg/generated/clientset/versioned/typed/example/v2/testtype.go index 1a0babab1..1cca47bf7 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v2/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v2/testtype.go @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v2 import ( - "context" - "time" + context "context" + + examplev2 "acme.corp/pkg/apis/example/v2" + applyconfigurationsexamplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - v2 "acme.corp/pkg/apis/example/v2" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // TestTypesGetter has a method to return a TestTypeInterface. @@ -39,141 +39,33 @@ type TestTypesGetter interface { // TestTypeInterface has methods to work with TestType resources. type TestTypeInterface interface { - Create(ctx context.Context, testType *v2.TestType, opts v1.CreateOptions) (*v2.TestType, error) - Update(ctx context.Context, testType *v2.TestType, opts v1.UpdateOptions) (*v2.TestType, error) + Create(ctx context.Context, testType *examplev2.TestType, opts v1.CreateOptions) (*examplev2.TestType, error) + Update(ctx context.Context, testType *examplev2.TestType, opts v1.UpdateOptions) (*examplev2.TestType, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v2.TestType, error) - List(ctx context.Context, opts v1.ListOptions) (*v2.TestTypeList, error) + Get(ctx context.Context, name string, opts v1.GetOptions) (*examplev2.TestType, error) + List(ctx context.Context, opts v1.ListOptions) (*examplev2.TestTypeList, error) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.TestType, err error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *examplev2.TestType, err error) + Apply(ctx context.Context, testType *applyconfigurationsexamplev2.TestTypeApplyConfiguration, opts v1.ApplyOptions) (result *examplev2.TestType, err error) TestTypeExpansion } // testTypes implements TestTypeInterface type testTypes struct { - client rest.Interface - ns string + *gentype.ClientWithListAndApply[*examplev2.TestType, *examplev2.TestTypeList, *applyconfigurationsexamplev2.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *ExampleV2Client, namespace string) *testTypes { return &testTypes{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *testTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *v2.TestType, err error) { - result = &v2.TestType{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypes) List(ctx context.Context, opts v1.ListOptions) (result *v2.TestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v2.TestTypeList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *testTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + gentype.NewClientWithListAndApply[*examplev2.TestType, *examplev2.TestTypeList, *applyconfigurationsexamplev2.TestTypeApplyConfiguration]( + "testtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *examplev2.TestType { return &examplev2.TestType{} }, + func() *examplev2.TestTypeList { return &examplev2.TestTypeList{} }, + ), } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Create(ctx context.Context, testType *v2.TestType, opts v1.CreateOptions) (result *v2.TestType, err error) { - result = &v2.TestType{} - err = c.client.Post(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Update(ctx context.Context, testType *v2.TestType, opts v1.UpdateOptions) (result *v2.TestType, err error) { - result = &v2.TestType{} - err = c.client.Put(). - Namespace(c.ns). - Resource("testtypes"). - Name(testType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *testTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *testTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched testType. -func (c *testTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.TestType, err error) { - result = &v2.TestType{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return } diff --git a/examples/pkg/generated/clientset/versioned/typed/example3/v1/clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/example3/v1/clustertesttype.go index 4aabef003..cdb1e0930 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example3/v1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example3/v1/clustertesttype.go @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + + example3v1 "acme.corp/pkg/apis/example3/v1" + applyconfigurationsexample3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - v1 "acme.corp/pkg/apis/example3/v1" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // ClusterTestTypesGetter has a method to return a ClusterTestTypeInterface. @@ -39,147 +39,37 @@ type ClusterTestTypesGetter interface { // ClusterTestTypeInterface has methods to work with ClusterTestType resources. type ClusterTestTypeInterface interface { - Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (*v1.ClusterTestType, error) - Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) - UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) + Create(ctx context.Context, clusterTestType *example3v1.ClusterTestType, opts metav1.CreateOptions) (*example3v1.ClusterTestType, error) + Update(ctx context.Context, clusterTestType *example3v1.ClusterTestType, opts metav1.UpdateOptions) (*example3v1.ClusterTestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, clusterTestType *example3v1.ClusterTestType, opts metav1.UpdateOptions) (*example3v1.ClusterTestType, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.ClusterTestType, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.ClusterTestTypeList, error) + Get(ctx context.Context, name string, opts metav1.GetOptions) (*example3v1.ClusterTestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*example3v1.ClusterTestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *example3v1.ClusterTestType, err error) + Apply(ctx context.Context, clusterTestType *applyconfigurationsexample3v1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *example3v1.ClusterTestType, err error) + // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). + ApplyStatus(ctx context.Context, clusterTestType *applyconfigurationsexample3v1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *example3v1.ClusterTestType, err error) ClusterTestTypeExpansion } // clusterTestTypes implements ClusterTestTypeInterface type clusterTestTypes struct { - client rest.Interface + *gentype.ClientWithListAndApply[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList, *applyconfigurationsexample3v1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *Example3V1Client) *clusterTestTypes { return &clusterTestTypes{ - client: c.RESTClient(), + gentype.NewClientWithListAndApply[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList, *applyconfigurationsexample3v1.ClusterTestTypeApplyConfiguration]( + "clustertesttypes", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *example3v1.ClusterTestType { return &example3v1.ClusterTestType{} }, + func() *example3v1.ClusterTestTypeList { return &example3v1.ClusterTestTypeList{} }, + ), } } - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *clusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Get(). - Resource("clustertesttypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.ClusterTestTypeList{} - err = c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *clusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Post(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *clusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *clusterTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Resource("clustertesttypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *clusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Resource("clustertesttypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *clusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Patch(pt). - Resource("clustertesttypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/examples/pkg/generated/clientset/versioned/typed/example3/v1/doc.go b/examples/pkg/generated/clientset/versioned/typed/example3/v1/doc.go index 9d46e1563..278483ba7 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example3/v1/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/example3/v1/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated typed clients. package v1 diff --git a/examples/pkg/generated/clientset/versioned/typed/example3/v1/example3_client.go b/examples/pkg/generated/clientset/versioned/typed/example3/v1/example3_client.go index 10bcb88ee..f5d153dd2 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example3/v1/example3_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/example3/v1/example3_client.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - "net/http" + http "net/http" - rest "k8s.io/client-go/rest" + example3v1 "acme.corp/pkg/apis/example3/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" - v1 "acme.corp/pkg/apis/example3/v1" - "acme.corp/pkg/generated/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" ) type Example3V1Interface interface { @@ -51,9 +51,7 @@ func (c *Example3V1Client) TestTypes(namespace string) TestTypeInterface { // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*Example3V1Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err @@ -65,9 +63,7 @@ func NewForConfig(c *rest.Config) (*Example3V1Client, error) { // Note the http client provided takes precedence over the configured transport values. func NewForConfigAndClient(c *rest.Config, h *http.Client) (*Example3V1Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) client, err := rest.RESTClientForConfigAndClient(&config, h) if err != nil { return nil, err @@ -90,17 +86,15 @@ func New(c rest.Interface) *Example3V1Client { return &Example3V1Client{c} } -func setConfigDefaults(config *rest.Config) error { - gv := v1.SchemeGroupVersion +func setConfigDefaults(config *rest.Config) { + gv := example3v1.SchemeGroupVersion config.GroupVersion = &gv config.APIPath = "/apis" - config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() if config.UserAgent == "" { config.UserAgent = rest.DefaultKubernetesUserAgent() } - - return nil } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/doc.go b/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/doc.go index fbcf54bc4..e388f2918 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // Package fake has the automatically generated clients. package fake diff --git a/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/fake_clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/fake_clustertesttype.go index 36472ed9b..63c16b986 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/fake_clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/fake_clustertesttype.go @@ -14,121 +14,39 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" + v1 "acme.corp/pkg/apis/example3/v1" + example3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" + typedexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - - example3v1 "acme.corp/pkg/apis/example3/v1" + gentype "k8s.io/client-go/gentype" ) -// FakeClusterTestTypes implements ClusterTestTypeInterface -type FakeClusterTestTypes struct { +// fakeClusterTestTypes implements ClusterTestTypeInterface +type fakeClusterTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *example3v1.ClusterTestTypeApplyConfiguration] Fake *FakeExample3V1 } -var clustertesttypesResource = schema.GroupVersionResource{Group: "example3.some.corp", Version: "v1", Resource: "clustertesttypes"} - -var clustertesttypesKind = schema.GroupVersionKind{Group: "example3.some.corp", Version: "v1", Kind: "ClusterTestType"} - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *example3v1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootGetAction(clustertesttypesResource, name), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *FakeClusterTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *example3v1.ClusterTestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootListAction(clustertesttypesResource, clustertesttypesKind, opts), &example3v1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &example3v1.ClusterTestTypeList{ListMeta: obj.(*example3v1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*example3v1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchAction(clustertesttypesResource, opts)) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *example3v1.ClusterTestType, opts v1.CreateOptions) (result *example3v1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(clustertesttypesResource, clusterTestType), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *example3v1.ClusterTestType, opts v1.UpdateOptions) (result *example3v1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(clustertesttypesResource, clusterTestType), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *example3v1.ClusterTestType, opts v1.UpdateOptions) (*example3v1.ClusterTestType, error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(clustertesttypesResource, "status", clusterTestType), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &example3v1.ClusterTestType{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(clustertesttypesResource, listOpts) - - _, err := c.Fake.Invokes(action, &example3v1.ClusterTestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *example3v1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, name, pt, data, subresources...), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypes(fake *FakeExample3V1) typedexample3v1.ClusterTestTypeInterface { + return &fakeClusterTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *example3v1.ClusterTestTypeApplyConfiguration]( + fake.Fake, + "", + v1.SchemeGroupVersion.WithResource("clustertesttypes"), + v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *v1.ClusterTestType { return &v1.ClusterTestType{} }, + func() *v1.ClusterTestTypeList { return &v1.ClusterTestTypeList{} }, + func(dst, src *v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.ClusterTestTypeList) []*v1.ClusterTestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.ClusterTestTypeList, items []*v1.ClusterTestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*example3v1.ClusterTestType), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/fake_example3_client.go b/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/fake_example3_client.go index 142e273e2..cec86f866 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/fake_example3_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/fake_example3_client.go @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( + v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + rest "k8s.io/client-go/rest" testing "k8s.io/client-go/testing" - - v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" ) type FakeExample3V1 struct { @@ -30,11 +30,11 @@ type FakeExample3V1 struct { } func (c *FakeExample3V1) ClusterTestTypes() v1.ClusterTestTypeInterface { - return &FakeClusterTestTypes{c} + return newFakeClusterTestTypes(c) } func (c *FakeExample3V1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/fake_testtype.go b/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/fake_testtype.go index dcd3f2339..95eb67bf0 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/fake_testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example3/v1/fake/fake_testtype.go @@ -14,152 +14,78 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" + context "context" examplev1 "acme.corp/pkg/apis/example/v1" - example3v1 "acme.corp/pkg/apis/example3/v1" + v1 "acme.corp/pkg/apis/example3/v1" + example3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" + typedexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + gentype "k8s.io/client-go/gentype" + testing "k8s.io/client-go/testing" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *example3v1.TestTypeApplyConfiguration] Fake *FakeExample3V1 - ns string -} - -var testtypesResource = schema.GroupVersionResource{Group: "example3.some.corp", Version: "v1", Resource: "testtypes"} - -var testtypesKind = schema.GroupVersionKind{Group: "example3.some.corp", Version: "v1", Kind: "TestType"} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *example3v1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(testtypesResource, c.ns, name), &example3v1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *example3v1.TestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(testtypesResource, testtypesKind, c.ns, opts), &example3v1.TestTypeList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &example3v1.TestTypeList{ListMeta: obj.(*example3v1.TestTypeList).ListMeta} - for _, item := range obj.(*example3v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *example3v1.TestType, opts v1.CreateOptions) (result *example3v1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(testtypesResource, c.ns, testType), &example3v1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *example3v1.TestType, opts v1.UpdateOptions) (result *example3v1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(testtypesResource, c.ns, testType), &example3v1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &example3v1.TestType{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(testtypesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &example3v1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *example3v1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, name, pt, data, subresources...), &example3v1.TestType{}) - - if obj == nil { - return nil, err +func newFakeTestTypes(fake *FakeExample3V1, namespace string) typedexample3v1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *example3v1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*example3v1.TestType), err } // CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. -func (c *FakeTestTypes) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts v1.CreateOptions) (result *examplev1.Field, err error) { +func (c *fakeTestTypes) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} obj, err := c.Fake. - Invokes(testing.NewCreateSubresourceAction(testtypesResource, testTypeName, "field", c.ns, field), &examplev1.Field{}) + Invokes(testing.NewCreateSubresourceActionWithOptions(c.Resource(), testTypeName, "field", c.Namespace(), field, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } // UpdateField takes the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. -func (c *FakeTestTypes) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts v1.UpdateOptions) (result *examplev1.Field, err error) { +func (c *fakeTestTypes) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(testtypesResource, "field", c.ns, field), &examplev1.Field{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(c.Resource(), "field", c.Namespace(), field, opts), &examplev1.Field{}) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } // GetField takes name of the testType, and returns the corresponding field object, and an error if there is any. -func (c *FakeTestTypes) GetField(ctx context.Context, testTypeName string, options v1.GetOptions) (result *examplev1.Field, err error) { +func (c *fakeTestTypes) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} obj, err := c.Fake. - Invokes(testing.NewGetSubresourceAction(testtypesResource, c.ns, "field", testTypeName), &examplev1.Field{}) + Invokes(testing.NewGetSubresourceActionWithOptions(c.Resource(), c.Namespace(), "field", testTypeName, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/example3/v1/generated_expansion.go b/examples/pkg/generated/clientset/versioned/typed/example3/v1/generated_expansion.go index 683e7e27f..2b821d5ff 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example3/v1/generated_expansion.go +++ b/examples/pkg/generated/clientset/versioned/typed/example3/v1/generated_expansion.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/clientset/versioned/typed/example3/v1/testtype.go b/examples/pkg/generated/clientset/versioned/typed/example3/v1/testtype.go index 0659a85de..cc3ee725c 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example3/v1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example3/v1/testtype.go @@ -14,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + + examplev1 "acme.corp/pkg/apis/example/v1" + example3v1 "acme.corp/pkg/apis/example3/v1" + applyconfigurationsexample3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - examplev1 "acme.corp/pkg/apis/example/v1" - v1 "acme.corp/pkg/apis/example3/v1" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // TestTypesGetter has a method to return a TestTypeInterface. @@ -40,14 +40,15 @@ type TestTypesGetter interface { // TestTypeInterface has methods to work with TestType resources. type TestTypeInterface interface { - Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (*v1.TestType, error) - Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) + Create(ctx context.Context, testType *example3v1.TestType, opts metav1.CreateOptions) (*example3v1.TestType, error) + Update(ctx context.Context, testType *example3v1.TestType, opts metav1.UpdateOptions) (*example3v1.TestType, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.TestType, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.TestTypeList, error) + Get(ctx context.Context, name string, opts metav1.GetOptions) (*example3v1.TestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*example3v1.TestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *example3v1.TestType, err error) + Apply(ctx context.Context, testType *applyconfigurationsexample3v1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *example3v1.TestType, err error) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (*examplev1.Field, error) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (*examplev1.Field, error) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*examplev1.Field, error) @@ -57,137 +58,28 @@ type TestTypeInterface interface { // testTypes implements TestTypeInterface type testTypes struct { - client rest.Interface - ns string + *gentype.ClientWithListAndApply[*example3v1.TestType, *example3v1.TestTypeList, *applyconfigurationsexample3v1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *Example3V1Client, namespace string) *testTypes { return &testTypes{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *testTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.TestTypeList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *testTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Post(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Put(). - Namespace(c.ns). - Resource("testtypes"). - Name(testType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *testTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *testTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + gentype.NewClientWithListAndApply[*example3v1.TestType, *example3v1.TestTypeList, *applyconfigurationsexample3v1.TestTypeApplyConfiguration]( + "testtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *example3v1.TestType { return &example3v1.TestType{} }, + func() *example3v1.TestTypeList { return &example3v1.TestTypeList{} }, + ), } - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched testType. -func (c *testTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return } // CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. func (c *testTypes) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (result *examplev1.Field, err error) { result = &examplev1.Field{} - err = c.client.Post(). - Namespace(c.ns). + err = c.GetClient().Post(). + Namespace(c.GetNamespace()). Resource("testtypes"). Name(testTypeName). SubResource("field"). @@ -201,8 +93,8 @@ func (c *testTypes) CreateField(ctx context.Context, testTypeName string, field // UpdateField takes the top resource name and the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. func (c *testTypes) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (result *examplev1.Field, err error) { result = &examplev1.Field{} - err = c.client.Put(). - Namespace(c.ns). + err = c.GetClient().Put(). + Namespace(c.GetNamespace()). Resource("testtypes"). Name(testTypeName). SubResource("field"). @@ -216,8 +108,8 @@ func (c *testTypes) UpdateField(ctx context.Context, testTypeName string, field // GetField takes name of the testType, and returns the corresponding examplev1.Field object, and an error if there is any. func (c *testTypes) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (result *examplev1.Field, err error) { result = &examplev1.Field{} - err = c.client.Get(). - Namespace(c.ns). + err = c.GetClient().Get(). + Namespace(c.GetNamespace()). Resource("testtypes"). Name(testTypeName). SubResource("field"). diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..a86a3a3b7 --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/clustertesttype.go @@ -0,0 +1,75 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" +) + +// ClusterTestTypesGetter has a method to return a ClusterTestTypeInterface. +// A group's client should implement this interface. +type ClusterTestTypesGetter interface { + ClusterTestTypes() ClusterTestTypeInterface +} + +// ClusterTestTypeInterface has methods to work with ClusterTestType resources. +type ClusterTestTypeInterface interface { + Create(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.CreateOptions) (*exampledashedv1.ClusterTestType, error) + Update(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) + Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error + Get(ctx context.Context, name string, opts metav1.GetOptions) (*exampledashedv1.ClusterTestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *exampledashedv1.ClusterTestType, err error) + Apply(ctx context.Context, clusterTestType *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *exampledashedv1.ClusterTestType, err error) + // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). + ApplyStatus(ctx context.Context, clusterTestType *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *exampledashedv1.ClusterTestType, err error) + ClusterTestTypeExpansion +} + +// clusterTestTypes implements ClusterTestTypeInterface +type clusterTestTypes struct { + *gentype.ClientWithListAndApply[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList, *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration] +} + +// newClusterTestTypes returns a ClusterTestTypes +func newClusterTestTypes(c *ExampleDashedV1Client) *clusterTestTypes { + return &clusterTestTypes{ + gentype.NewClientWithListAndApply[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList, *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration]( + "clustertesttypes", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *exampledashedv1.ClusterTestType { return &exampledashedv1.ClusterTestType{} }, + func() *exampledashedv1.ClusterTestTypeList { return &exampledashedv1.ClusterTestTypeList{} }, + ), + } +} diff --git a/examples/pkg/generated/clientset/versioned/doc.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/doc.go similarity index 81% rename from examples/pkg/generated/clientset/versioned/doc.go rename to examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/doc.go index af41e7fdc..278483ba7 100644 --- a/examples/pkg/generated/clientset/versioned/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. -// This package has the automatically generated clientset. -package versioned +// This package has the automatically generated typed clients. +package v1 diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go new file mode 100644 index 000000000..2272cf769 --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go @@ -0,0 +1,107 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + http "net/http" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + + rest "k8s.io/client-go/rest" +) + +type ExampleDashedV1Interface interface { + RESTClient() rest.Interface + ClusterTestTypesGetter + TestTypesGetter +} + +// ExampleDashedV1Client is used to interact with features provided by the example-dashed.some.corp group. +type ExampleDashedV1Client struct { + restClient rest.Interface +} + +func (c *ExampleDashedV1Client) ClusterTestTypes() ClusterTestTypeInterface { + return newClusterTestTypes(c) +} + +func (c *ExampleDashedV1Client) TestTypes(namespace string) TestTypeInterface { + return newTestTypes(c, namespace) +} + +// NewForConfig creates a new ExampleDashedV1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExampleDashedV1Client, error) { + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new ExampleDashedV1Client for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleDashedV1Client, error) { + config := *c + setConfigDefaults(&config) + client, err := rest.RESTClientForConfigAndClient(&config, h) + if err != nil { + return nil, err + } + return &ExampleDashedV1Client{client}, nil +} + +// NewForConfigOrDie creates a new ExampleDashedV1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExampleDashedV1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new ExampleDashedV1Client for the given RESTClient. +func New(c rest.Interface) *ExampleDashedV1Client { + return &ExampleDashedV1Client{c} +} + +func setConfigDefaults(config *rest.Config) { + gv := exampledashedv1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExampleDashedV1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/doc.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/doc.go new file mode 100644 index 000000000..e388f2918 --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_clustertesttype.go new file mode 100644 index 000000000..11c4202bd --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_clustertesttype.go @@ -0,0 +1,52 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + typedexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + + gentype "k8s.io/client-go/gentype" +) + +// fakeClusterTestTypes implements ClusterTestTypeInterface +type fakeClusterTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *exampledashedv1.ClusterTestTypeApplyConfiguration] + Fake *FakeExampleDashedV1 +} + +func newFakeClusterTestTypes(fake *FakeExampleDashedV1) typedexampledashedv1.ClusterTestTypeInterface { + return &fakeClusterTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *exampledashedv1.ClusterTestTypeApplyConfiguration]( + fake.Fake, + "", + v1.SchemeGroupVersion.WithResource("clustertesttypes"), + v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *v1.ClusterTestType { return &v1.ClusterTestType{} }, + func() *v1.ClusterTestTypeList { return &v1.ClusterTestTypeList{} }, + func(dst, src *v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.ClusterTestTypeList) []*v1.ClusterTestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.ClusterTestTypeList, items []*v1.ClusterTestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, + } +} diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_exampledashed_client.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_exampledashed_client.go new file mode 100644 index 000000000..01b7fb988 --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_exampledashed_client.go @@ -0,0 +1,45 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeExampleDashedV1 struct { + *testing.Fake +} + +func (c *FakeExampleDashedV1) ClusterTestTypes() v1.ClusterTestTypeInterface { + return newFakeClusterTestTypes(c) +} + +func (c *FakeExampleDashedV1) TestTypes(namespace string) v1.TestTypeInterface { + return newFakeTestTypes(c, namespace) +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeExampleDashedV1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_testtype.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_testtype.go new file mode 100644 index 000000000..acfb0bc62 --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_testtype.go @@ -0,0 +1,91 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + context "context" + + examplev1 "acme.corp/pkg/apis/example/v1" + v1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + typedexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + gentype "k8s.io/client-go/gentype" + testing "k8s.io/client-go/testing" +) + +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *exampledashedv1.TestTypeApplyConfiguration] + Fake *FakeExampleDashedV1 +} + +func newFakeTestTypes(fake *FakeExampleDashedV1, namespace string) typedexampledashedv1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *exampledashedv1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, + } +} + +// CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. +func (c *fakeTestTypes) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake. + Invokes(testing.NewCreateSubresourceActionWithOptions(c.Resource(), testTypeName, "field", c.Namespace(), field, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} + +// UpdateField takes the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. +func (c *fakeTestTypes) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceActionWithOptions(c.Resource(), "field", c.Namespace(), field, opts), &examplev1.Field{}) + + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} + +// GetField takes name of the testType, and returns the corresponding field object, and an error if there is any. +func (c *fakeTestTypes) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake. + Invokes(testing.NewGetSubresourceActionWithOptions(c.Resource(), c.Namespace(), "field", testTypeName, options), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} diff --git a/examples/pkg/kcpexisting/clients/listers/example3/v1/testtype_expansion.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/generated_expansion.go similarity index 68% rename from examples/pkg/kcpexisting/clients/listers/example3/v1/testtype_expansion.go rename to examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/generated_expansion.go index 835da85d6..2b821d5ff 100644 --- a/examples/pkg/kcpexisting/clients/listers/example3/v1/testtype_expansion.go +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/generated_expansion.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,9 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 -// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. -type TestTypeClusterListerExpansion interface{} +type ClusterTestTypeExpansion interface{} + +type TestTypeExpansion interface{} diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/testtype.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/testtype.go new file mode 100644 index 000000000..516bddc05 --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/testtype.go @@ -0,0 +1,120 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + + examplev1 "acme.corp/pkg/apis/example/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" +) + +// TestTypesGetter has a method to return a TestTypeInterface. +// A group's client should implement this interface. +type TestTypesGetter interface { + TestTypes(namespace string) TestTypeInterface +} + +// TestTypeInterface has methods to work with TestType resources. +type TestTypeInterface interface { + Create(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.CreateOptions) (*exampledashedv1.TestType, error) + Update(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) + Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error + Get(ctx context.Context, name string, opts metav1.GetOptions) (*exampledashedv1.TestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *exampledashedv1.TestType, err error) + Apply(ctx context.Context, testType *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *exampledashedv1.TestType, err error) + CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (*examplev1.Field, error) + UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (*examplev1.Field, error) + GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*examplev1.Field, error) + + TestTypeExpansion +} + +// testTypes implements TestTypeInterface +type testTypes struct { + *gentype.ClientWithListAndApply[*exampledashedv1.TestType, *exampledashedv1.TestTypeList, *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration] +} + +// newTestTypes returns a TestTypes +func newTestTypes(c *ExampleDashedV1Client, namespace string) *testTypes { + return &testTypes{ + gentype.NewClientWithListAndApply[*exampledashedv1.TestType, *exampledashedv1.TestTypeList, *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration]( + "testtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *exampledashedv1.TestType { return &exampledashedv1.TestType{} }, + func() *exampledashedv1.TestTypeList { return &exampledashedv1.TestTypeList{} }, + ), + } +} + +// CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypes) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (result *examplev1.Field, err error) { + result = &examplev1.Field{} + err = c.GetClient().Post(). + Namespace(c.GetNamespace()). + Resource("testtypes"). + Name(testTypeName). + SubResource("field"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(field). + Do(ctx). + Into(result) + return +} + +// UpdateField takes the top resource name and the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypes) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (result *examplev1.Field, err error) { + result = &examplev1.Field{} + err = c.GetClient().Put(). + Namespace(c.GetNamespace()). + Resource("testtypes"). + Name(testTypeName). + SubResource("field"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(field). + Do(ctx). + Into(result) + return +} + +// GetField takes name of the testType, and returns the corresponding examplev1.Field object, and an error if there is any. +func (c *testTypes) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (result *examplev1.Field, err error) { + result = &examplev1.Field{} + err = c.GetClient().Get(). + Namespace(c.GetNamespace()). + Resource("testtypes"). + Name(testTypeName). + SubResource("field"). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} diff --git a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go index 43d2b645a..aefc4b821 100644 --- a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + applyconfigurationsexistinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - v1 "acme.corp/pkg/apis/existinginterfaces/v1" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // ClusterTestTypesGetter has a method to return a ClusterTestTypeInterface. @@ -39,147 +39,37 @@ type ClusterTestTypesGetter interface { // ClusterTestTypeInterface has methods to work with ClusterTestType resources. type ClusterTestTypeInterface interface { - Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (*v1.ClusterTestType, error) - Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) - UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) + Create(ctx context.Context, clusterTestType *existinginterfacesv1.ClusterTestType, opts metav1.CreateOptions) (*existinginterfacesv1.ClusterTestType, error) + Update(ctx context.Context, clusterTestType *existinginterfacesv1.ClusterTestType, opts metav1.UpdateOptions) (*existinginterfacesv1.ClusterTestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, clusterTestType *existinginterfacesv1.ClusterTestType, opts metav1.UpdateOptions) (*existinginterfacesv1.ClusterTestType, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.ClusterTestType, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.ClusterTestTypeList, error) + Get(ctx context.Context, name string, opts metav1.GetOptions) (*existinginterfacesv1.ClusterTestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.ClusterTestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *existinginterfacesv1.ClusterTestType, err error) + Apply(ctx context.Context, clusterTestType *applyconfigurationsexistinginterfacesv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *existinginterfacesv1.ClusterTestType, err error) + // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). + ApplyStatus(ctx context.Context, clusterTestType *applyconfigurationsexistinginterfacesv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *existinginterfacesv1.ClusterTestType, err error) ClusterTestTypeExpansion } // clusterTestTypes implements ClusterTestTypeInterface type clusterTestTypes struct { - client rest.Interface + *gentype.ClientWithListAndApply[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList, *applyconfigurationsexistinginterfacesv1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *ExistinginterfacesV1Client) *clusterTestTypes { return &clusterTestTypes{ - client: c.RESTClient(), + gentype.NewClientWithListAndApply[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList, *applyconfigurationsexistinginterfacesv1.ClusterTestTypeApplyConfiguration]( + "clustertesttypes", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *existinginterfacesv1.ClusterTestType { return &existinginterfacesv1.ClusterTestType{} }, + func() *existinginterfacesv1.ClusterTestTypeList { return &existinginterfacesv1.ClusterTestTypeList{} }, + ), } } - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *clusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Get(). - Resource("clustertesttypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.ClusterTestTypeList{} - err = c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *clusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Post(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *clusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *clusterTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Resource("clustertesttypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *clusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Resource("clustertesttypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *clusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Patch(pt). - Resource("clustertesttypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/doc.go b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/doc.go index 9d46e1563..278483ba7 100644 --- a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated typed clients. package v1 diff --git a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/existinginterfaces_client.go b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/existinginterfaces_client.go index 261d70145..7eb3174b5 100644 --- a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/existinginterfaces_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/existinginterfaces_client.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - "net/http" + http "net/http" - rest "k8s.io/client-go/rest" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" - v1 "acme.corp/pkg/apis/existinginterfaces/v1" - "acme.corp/pkg/generated/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" ) type ExistinginterfacesV1Interface interface { @@ -51,9 +51,7 @@ func (c *ExistinginterfacesV1Client) TestTypes(namespace string) TestTypeInterfa // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExistinginterfacesV1Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err @@ -65,9 +63,7 @@ func NewForConfig(c *rest.Config) (*ExistinginterfacesV1Client, error) { // Note the http client provided takes precedence over the configured transport values. func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExistinginterfacesV1Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) client, err := rest.RESTClientForConfigAndClient(&config, h) if err != nil { return nil, err @@ -90,17 +86,15 @@ func New(c rest.Interface) *ExistinginterfacesV1Client { return &ExistinginterfacesV1Client{c} } -func setConfigDefaults(config *rest.Config) error { - gv := v1.SchemeGroupVersion +func setConfigDefaults(config *rest.Config) { + gv := existinginterfacesv1.SchemeGroupVersion config.GroupVersion = &gv config.APIPath = "/apis" - config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() if config.UserAgent == "" { config.UserAgent = rest.DefaultKubernetesUserAgent() } - - return nil } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/doc.go b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/doc.go index fbcf54bc4..e388f2918 100644 --- a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // Package fake has the automatically generated clients. package fake diff --git a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/fake_clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/fake_clustertesttype.go index a76ece7fa..5c9be5c5b 100644 --- a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/fake_clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/fake_clustertesttype.go @@ -14,121 +14,39 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" + v1 "acme.corp/pkg/apis/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" + typedexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + gentype "k8s.io/client-go/gentype" ) -// FakeClusterTestTypes implements ClusterTestTypeInterface -type FakeClusterTestTypes struct { +// fakeClusterTestTypes implements ClusterTestTypeInterface +type fakeClusterTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *existinginterfacesv1.ClusterTestTypeApplyConfiguration] Fake *FakeExistinginterfacesV1 } -var clustertesttypesResource = schema.GroupVersionResource{Group: "existinginterfaces.acme.corp", Version: "v1", Resource: "clustertesttypes"} - -var clustertesttypesKind = schema.GroupVersionKind{Group: "existinginterfaces.acme.corp", Version: "v1", Kind: "ClusterTestType"} - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *existinginterfacesv1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootGetAction(clustertesttypesResource, name), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *FakeClusterTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *existinginterfacesv1.ClusterTestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootListAction(clustertesttypesResource, clustertesttypesKind, opts), &existinginterfacesv1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &existinginterfacesv1.ClusterTestTypeList{ListMeta: obj.(*existinginterfacesv1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*existinginterfacesv1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchAction(clustertesttypesResource, opts)) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *existinginterfacesv1.ClusterTestType, opts v1.CreateOptions) (result *existinginterfacesv1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(clustertesttypesResource, clusterTestType), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *existinginterfacesv1.ClusterTestType, opts v1.UpdateOptions) (result *existinginterfacesv1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(clustertesttypesResource, clusterTestType), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *existinginterfacesv1.ClusterTestType, opts v1.UpdateOptions) (*existinginterfacesv1.ClusterTestType, error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(clustertesttypesResource, "status", clusterTestType), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &existinginterfacesv1.ClusterTestType{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(clustertesttypesResource, listOpts) - - _, err := c.Fake.Invokes(action, &existinginterfacesv1.ClusterTestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *existinginterfacesv1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, name, pt, data, subresources...), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypes(fake *FakeExistinginterfacesV1) typedexistinginterfacesv1.ClusterTestTypeInterface { + return &fakeClusterTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *existinginterfacesv1.ClusterTestTypeApplyConfiguration]( + fake.Fake, + "", + v1.SchemeGroupVersion.WithResource("clustertesttypes"), + v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *v1.ClusterTestType { return &v1.ClusterTestType{} }, + func() *v1.ClusterTestTypeList { return &v1.ClusterTestTypeList{} }, + func(dst, src *v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.ClusterTestTypeList) []*v1.ClusterTestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.ClusterTestTypeList, items []*v1.ClusterTestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*existinginterfacesv1.ClusterTestType), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/fake_existinginterfaces_client.go b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/fake_existinginterfaces_client.go index 1f9ca44de..7a528c36b 100644 --- a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/fake_existinginterfaces_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/fake_existinginterfaces_client.go @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( + v1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + rest "k8s.io/client-go/rest" testing "k8s.io/client-go/testing" - - v1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" ) type FakeExistinginterfacesV1 struct { @@ -30,11 +30,11 @@ type FakeExistinginterfacesV1 struct { } func (c *FakeExistinginterfacesV1) ClusterTestTypes() v1.ClusterTestTypeInterface { - return &FakeClusterTestTypes{c} + return newFakeClusterTestTypes(c) } func (c *FakeExistinginterfacesV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/fake_testtype.go b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/fake_testtype.go index d90d18d06..97182dcb7 100644 --- a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/fake_testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake/fake_testtype.go @@ -14,118 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" + v1 "acme.corp/pkg/apis/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" + typedexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + gentype "k8s.io/client-go/gentype" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *existinginterfacesv1.TestTypeApplyConfiguration] Fake *FakeExistinginterfacesV1 - ns string -} - -var testtypesResource = schema.GroupVersionResource{Group: "existinginterfaces.acme.corp", Version: "v1", Resource: "testtypes"} - -var testtypesKind = schema.GroupVersionKind{Group: "existinginterfaces.acme.corp", Version: "v1", Kind: "TestType"} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *existinginterfacesv1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(testtypesResource, c.ns, name), &existinginterfacesv1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *existinginterfacesv1.TestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(testtypesResource, testtypesKind, c.ns, opts), &existinginterfacesv1.TestTypeList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &existinginterfacesv1.TestTypeList{ListMeta: obj.(*existinginterfacesv1.TestTypeList).ListMeta} - for _, item := range obj.(*existinginterfacesv1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *existinginterfacesv1.TestType, opts v1.CreateOptions) (result *existinginterfacesv1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(testtypesResource, c.ns, testType), &existinginterfacesv1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *existinginterfacesv1.TestType, opts v1.UpdateOptions) (result *existinginterfacesv1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(testtypesResource, c.ns, testType), &existinginterfacesv1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &existinginterfacesv1.TestType{}) - - return err } -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(testtypesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &existinginterfacesv1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *existinginterfacesv1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, name, pt, data, subresources...), &existinginterfacesv1.TestType{}) - - if obj == nil { - return nil, err +func newFakeTestTypes(fake *FakeExistinginterfacesV1, namespace string) typedexistinginterfacesv1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *existinginterfacesv1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*existinginterfacesv1.TestType), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/generated_expansion.go b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/generated_expansion.go index 683e7e27f..2b821d5ff 100644 --- a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/generated_expansion.go +++ b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/generated_expansion.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/testtype.go b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/testtype.go index f5de2b2a8..3b0f72ef3 100644 --- a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/testtype.go @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + applyconfigurationsexistinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - v1 "acme.corp/pkg/apis/existinginterfaces/v1" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // TestTypesGetter has a method to return a TestTypeInterface. @@ -39,141 +39,33 @@ type TestTypesGetter interface { // TestTypeInterface has methods to work with TestType resources. type TestTypeInterface interface { - Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (*v1.TestType, error) - Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) + Create(ctx context.Context, testType *existinginterfacesv1.TestType, opts metav1.CreateOptions) (*existinginterfacesv1.TestType, error) + Update(ctx context.Context, testType *existinginterfacesv1.TestType, opts metav1.UpdateOptions) (*existinginterfacesv1.TestType, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.TestType, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.TestTypeList, error) + Get(ctx context.Context, name string, opts metav1.GetOptions) (*existinginterfacesv1.TestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.TestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *existinginterfacesv1.TestType, err error) + Apply(ctx context.Context, testType *applyconfigurationsexistinginterfacesv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *existinginterfacesv1.TestType, err error) TestTypeExpansion } // testTypes implements TestTypeInterface type testTypes struct { - client rest.Interface - ns string + *gentype.ClientWithListAndApply[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList, *applyconfigurationsexistinginterfacesv1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *ExistinginterfacesV1Client, namespace string) *testTypes { return &testTypes{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *testTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.TestTypeList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *testTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + gentype.NewClientWithListAndApply[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList, *applyconfigurationsexistinginterfacesv1.TestTypeApplyConfiguration]( + "testtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *existinginterfacesv1.TestType { return &existinginterfacesv1.TestType{} }, + func() *existinginterfacesv1.TestTypeList { return &existinginterfacesv1.TestTypeList{} }, + ), } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Post(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Put(). - Namespace(c.ns). - Resource("testtypes"). - Name(testType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *testTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *testTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched testType. -func (c *testTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return } diff --git a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/clustertesttype.go index 89e8a0ae5..a44d98118 100644 --- a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/clustertesttype.go @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + applyconfigurationssecondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - v1 "acme.corp/pkg/apis/secondexample/v1" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // ClusterTestTypesGetter has a method to return a ClusterTestTypeInterface. @@ -39,147 +39,37 @@ type ClusterTestTypesGetter interface { // ClusterTestTypeInterface has methods to work with ClusterTestType resources. type ClusterTestTypeInterface interface { - Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (*v1.ClusterTestType, error) - Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) - UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) + Create(ctx context.Context, clusterTestType *secondexamplev1.ClusterTestType, opts metav1.CreateOptions) (*secondexamplev1.ClusterTestType, error) + Update(ctx context.Context, clusterTestType *secondexamplev1.ClusterTestType, opts metav1.UpdateOptions) (*secondexamplev1.ClusterTestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, clusterTestType *secondexamplev1.ClusterTestType, opts metav1.UpdateOptions) (*secondexamplev1.ClusterTestType, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.ClusterTestType, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.ClusterTestTypeList, error) + Get(ctx context.Context, name string, opts metav1.GetOptions) (*secondexamplev1.ClusterTestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.ClusterTestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *secondexamplev1.ClusterTestType, err error) + Apply(ctx context.Context, clusterTestType *applyconfigurationssecondexamplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *secondexamplev1.ClusterTestType, err error) + // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). + ApplyStatus(ctx context.Context, clusterTestType *applyconfigurationssecondexamplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *secondexamplev1.ClusterTestType, err error) ClusterTestTypeExpansion } // clusterTestTypes implements ClusterTestTypeInterface type clusterTestTypes struct { - client rest.Interface + *gentype.ClientWithListAndApply[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList, *applyconfigurationssecondexamplev1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *SecondexampleV1Client) *clusterTestTypes { return &clusterTestTypes{ - client: c.RESTClient(), + gentype.NewClientWithListAndApply[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList, *applyconfigurationssecondexamplev1.ClusterTestTypeApplyConfiguration]( + "clustertesttypes", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *secondexamplev1.ClusterTestType { return &secondexamplev1.ClusterTestType{} }, + func() *secondexamplev1.ClusterTestTypeList { return &secondexamplev1.ClusterTestTypeList{} }, + ), } } - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *clusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Get(). - Resource("clustertesttypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.ClusterTestTypeList{} - err = c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *clusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Post(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *clusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *clusterTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Resource("clustertesttypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *clusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Resource("clustertesttypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *clusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Patch(pt). - Resource("clustertesttypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/doc.go b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/doc.go index 9d46e1563..278483ba7 100644 --- a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated typed clients. package v1 diff --git a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/doc.go b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/doc.go index fbcf54bc4..e388f2918 100644 --- a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. // Package fake has the automatically generated clients. package fake diff --git a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/fake_clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/fake_clustertesttype.go index 2de76872f..fde4b1977 100644 --- a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/fake_clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/fake_clustertesttype.go @@ -14,121 +14,39 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" + v1 "acme.corp/pkg/apis/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" + typedsecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + gentype "k8s.io/client-go/gentype" ) -// FakeClusterTestTypes implements ClusterTestTypeInterface -type FakeClusterTestTypes struct { +// fakeClusterTestTypes implements ClusterTestTypeInterface +type fakeClusterTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *secondexamplev1.ClusterTestTypeApplyConfiguration] Fake *FakeSecondexampleV1 } -var clustertesttypesResource = schema.GroupVersionResource{Group: "secondexample", Version: "v1", Resource: "clustertesttypes"} - -var clustertesttypesKind = schema.GroupVersionKind{Group: "secondexample", Version: "v1", Kind: "ClusterTestType"} - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *secondexamplev1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootGetAction(clustertesttypesResource, name), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *FakeClusterTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *secondexamplev1.ClusterTestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootListAction(clustertesttypesResource, clustertesttypesKind, opts), &secondexamplev1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &secondexamplev1.ClusterTestTypeList{ListMeta: obj.(*secondexamplev1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*secondexamplev1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchAction(clustertesttypesResource, opts)) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *secondexamplev1.ClusterTestType, opts v1.CreateOptions) (result *secondexamplev1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(clustertesttypesResource, clusterTestType), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *secondexamplev1.ClusterTestType, opts v1.UpdateOptions) (result *secondexamplev1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(clustertesttypesResource, clusterTestType), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *secondexamplev1.ClusterTestType, opts v1.UpdateOptions) (*secondexamplev1.ClusterTestType, error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(clustertesttypesResource, "status", clusterTestType), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &secondexamplev1.ClusterTestType{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(clustertesttypesResource, listOpts) - - _, err := c.Fake.Invokes(action, &secondexamplev1.ClusterTestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *secondexamplev1.ClusterTestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, name, pt, data, subresources...), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypes(fake *FakeSecondexampleV1) typedsecondexamplev1.ClusterTestTypeInterface { + return &fakeClusterTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *secondexamplev1.ClusterTestTypeApplyConfiguration]( + fake.Fake, + "", + v1.SchemeGroupVersion.WithResource("clustertesttypes"), + v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *v1.ClusterTestType { return &v1.ClusterTestType{} }, + func() *v1.ClusterTestTypeList { return &v1.ClusterTestTypeList{} }, + func(dst, src *v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.ClusterTestTypeList) []*v1.ClusterTestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.ClusterTestTypeList, items []*v1.ClusterTestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*secondexamplev1.ClusterTestType), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/fake_secondexample_client.go b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/fake_secondexample_client.go index cbc10add4..3bbfb8677 100644 --- a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/fake_secondexample_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/fake_secondexample_client.go @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( + v1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + rest "k8s.io/client-go/rest" testing "k8s.io/client-go/testing" - - v1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" ) type FakeSecondexampleV1 struct { @@ -30,11 +30,11 @@ type FakeSecondexampleV1 struct { } func (c *FakeSecondexampleV1) ClusterTestTypes() v1.ClusterTestTypeInterface { - return &FakeClusterTestTypes{c} + return newFakeClusterTestTypes(c) } func (c *FakeSecondexampleV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/fake_testtype.go b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/fake_testtype.go index 5596b2678..0623cc9a2 100644 --- a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/fake_testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/fake/fake_testtype.go @@ -14,118 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake import ( - "context" + v1 "acme.corp/pkg/apis/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" + typedsecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + gentype "k8s.io/client-go/gentype" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *secondexamplev1.TestTypeApplyConfiguration] Fake *FakeSecondexampleV1 - ns string -} - -var testtypesResource = schema.GroupVersionResource{Group: "secondexample", Version: "v1", Resource: "testtypes"} - -var testtypesKind = schema.GroupVersionKind{Group: "secondexample", Version: "v1", Kind: "TestType"} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options v1.GetOptions) (result *secondexamplev1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(testtypesResource, c.ns, name), &secondexamplev1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *secondexamplev1.TestTypeList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(testtypesResource, testtypesKind, c.ns, opts), &secondexamplev1.TestTypeList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &secondexamplev1.TestTypeList{ListMeta: obj.(*secondexamplev1.TestTypeList).ListMeta} - for _, item := range obj.(*secondexamplev1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *secondexamplev1.TestType, opts v1.CreateOptions) (result *secondexamplev1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(testtypesResource, c.ns, testType), &secondexamplev1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *secondexamplev1.TestType, opts v1.UpdateOptions) (result *secondexamplev1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(testtypesResource, c.ns, testType), &secondexamplev1.TestType{}) - - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &secondexamplev1.TestType{}) - - return err } -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(testtypesResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &secondexamplev1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *secondexamplev1.TestType, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, name, pt, data, subresources...), &secondexamplev1.TestType{}) - - if obj == nil { - return nil, err +func newFakeTestTypes(fake *FakeSecondexampleV1, namespace string) typedsecondexamplev1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *secondexamplev1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*secondexamplev1.TestType), err } diff --git a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/generated_expansion.go b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/generated_expansion.go index 683e7e27f..2b821d5ff 100644 --- a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/generated_expansion.go +++ b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/generated_expansion.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/secondexample_client.go b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/secondexample_client.go index 8906e070c..fb3787267 100644 --- a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/secondexample_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/secondexample_client.go @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - "net/http" + http "net/http" - rest "k8s.io/client-go/rest" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" - v1 "acme.corp/pkg/apis/secondexample/v1" - "acme.corp/pkg/generated/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" ) type SecondexampleV1Interface interface { @@ -33,7 +33,7 @@ type SecondexampleV1Interface interface { TestTypesGetter } -// SecondexampleV1Client is used to interact with features provided by the secondexample group. +// SecondexampleV1Client is used to interact with features provided by the secondexample.dev group. type SecondexampleV1Client struct { restClient rest.Interface } @@ -51,9 +51,7 @@ func (c *SecondexampleV1Client) TestTypes(namespace string) TestTypeInterface { // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*SecondexampleV1Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err @@ -65,9 +63,7 @@ func NewForConfig(c *rest.Config) (*SecondexampleV1Client, error) { // Note the http client provided takes precedence over the configured transport values. func NewForConfigAndClient(c *rest.Config, h *http.Client) (*SecondexampleV1Client, error) { config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } + setConfigDefaults(&config) client, err := rest.RESTClientForConfigAndClient(&config, h) if err != nil { return nil, err @@ -90,17 +86,15 @@ func New(c rest.Interface) *SecondexampleV1Client { return &SecondexampleV1Client{c} } -func setConfigDefaults(config *rest.Config) error { - gv := v1.SchemeGroupVersion +func setConfigDefaults(config *rest.Config) { + gv := secondexamplev1.SchemeGroupVersion config.GroupVersion = &gv config.APIPath = "/apis" - config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() if config.UserAgent == "" { config.UserAgent = rest.DefaultKubernetesUserAgent() } - - return nil } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/testtype.go b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/testtype.go index ac1160caa..d2630cff5 100644 --- a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/testtype.go @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.26.3. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + applyconfigurationssecondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - - v1 "acme.corp/pkg/apis/secondexample/v1" - scheme "acme.corp/pkg/generated/clientset/versioned/scheme" + gentype "k8s.io/client-go/gentype" ) // TestTypesGetter has a method to return a TestTypeInterface. @@ -39,141 +39,33 @@ type TestTypesGetter interface { // TestTypeInterface has methods to work with TestType resources. type TestTypeInterface interface { - Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (*v1.TestType, error) - Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) + Create(ctx context.Context, testType *secondexamplev1.TestType, opts metav1.CreateOptions) (*secondexamplev1.TestType, error) + Update(ctx context.Context, testType *secondexamplev1.TestType, opts metav1.UpdateOptions) (*secondexamplev1.TestType, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.TestType, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.TestTypeList, error) + Get(ctx context.Context, name string, opts metav1.GetOptions) (*secondexamplev1.TestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.TestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *secondexamplev1.TestType, err error) + Apply(ctx context.Context, testType *applyconfigurationssecondexamplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *secondexamplev1.TestType, err error) TestTypeExpansion } // testTypes implements TestTypeInterface type testTypes struct { - client rest.Interface - ns string + *gentype.ClientWithListAndApply[*secondexamplev1.TestType, *secondexamplev1.TestTypeList, *applyconfigurationssecondexamplev1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *SecondexampleV1Client, namespace string) *testTypes { return &testTypes{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *testTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.TestTypeList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *testTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + gentype.NewClientWithListAndApply[*secondexamplev1.TestType, *secondexamplev1.TestTypeList, *applyconfigurationssecondexamplev1.TestTypeApplyConfiguration]( + "testtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *secondexamplev1.TestType { return &secondexamplev1.TestType{} }, + func() *secondexamplev1.TestTypeList { return &secondexamplev1.TestTypeList{} }, + ), } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Post(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Put(). - Namespace(c.ns). - Resource("testtypes"). - Name(testType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *testTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *testTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched testType. -func (c *testTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return } diff --git a/examples/pkg/generated/informers/externalversions/example/interface.go b/examples/pkg/generated/informers/externalversions/example/interface.go index 34015c280..588d01f44 100644 --- a/examples/pkg/generated/informers/externalversions/example/interface.go +++ b/examples/pkg/generated/informers/externalversions/example/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package example diff --git a/examples/pkg/generated/informers/externalversions/example/v1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example/v1/clustertesttype.go index a9b443548..f124ccb54 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1/clustertesttype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" time "time" + apisexamplev1 "acme.corp/pkg/apis/example/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + examplev1 "acme.corp/pkg/generated/listers/example/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - examplev1 "acme.corp/pkg/apis/example/v1" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/example/v1" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.ClusterTestTypeLister + Lister() examplev1.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -62,16 +62,28 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV1().ClusterTestTypes().Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1().ClusterTestTypes().List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1().ClusterTestTypes().Watch(ctx, options) }, }, - &examplev1.ClusterTestType{}, + &apisexamplev1.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +94,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev1.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v1.ClusterTestTypeLister { - return v1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() examplev1.ClusterTestTypeLister { + return examplev1.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v1/interface.go b/examples/pkg/generated/informers/externalversions/example/v1/interface.go index 6bb09cd81..4ba2de328 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1/interface.go +++ b/examples/pkg/generated/informers/externalversions/example/v1/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/example/v1/testtype.go b/examples/pkg/generated/informers/externalversions/example/v1/testtype.go index 19af4b813..d5dbd31c0 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1/testtype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" time "time" + apisexamplev1 "acme.corp/pkg/apis/example/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + examplev1 "acme.corp/pkg/generated/listers/example/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - examplev1 "acme.corp/pkg/apis/example/v1" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/example/v1" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.TestTypeLister + Lister() examplev1.TestTypeLister } type testTypeInformer struct { @@ -63,16 +63,28 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().TestTypes(namespace).List(context.TODO(), options) + return client.ExampleV1().TestTypes(namespace).List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().TestTypes(namespace).Watch(context.TODO(), options) + return client.ExampleV1().TestTypes(namespace).Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1().TestTypes(namespace).List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1().TestTypes(namespace).Watch(ctx, options) }, }, - &examplev1.TestType{}, + &apisexamplev1.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +95,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev1.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v1.TestTypeLister { - return v1.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() examplev1.TestTypeLister { + return examplev1.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v1alpha1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example/v1alpha1/clustertesttype.go index f6eb145db..8d2ced289 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1alpha1/clustertesttype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1alpha1 import ( - "context" + context "context" time "time" + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + examplev1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1alpha1.ClusterTestTypeLister + Lister() examplev1alpha1.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -62,16 +62,28 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV1alpha1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV1alpha1().ClusterTestTypes().Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1alpha1().ClusterTestTypes().List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1alpha1().ClusterTestTypes().Watch(ctx, options) }, }, - &examplev1alpha1.ClusterTestType{}, + &apisexamplev1alpha1.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +94,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1alpha1.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev1alpha1.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v1alpha1.ClusterTestTypeLister { - return v1alpha1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() examplev1alpha1.ClusterTestTypeLister { + return examplev1alpha1.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v1alpha1/interface.go b/examples/pkg/generated/informers/externalversions/example/v1alpha1/interface.go index 90155db64..f21773dae 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1alpha1/interface.go +++ b/examples/pkg/generated/informers/externalversions/example/v1alpha1/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1alpha1 diff --git a/examples/pkg/generated/informers/externalversions/example/v1alpha1/testtype.go b/examples/pkg/generated/informers/externalversions/example/v1alpha1/testtype.go index 2f1a602ac..d56fee2f9 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1alpha1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1alpha1/testtype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1alpha1 import ( - "context" + context "context" time "time" + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + examplev1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1alpha1.TestTypeLister + Lister() examplev1alpha1.TestTypeLister } type testTypeInformer struct { @@ -63,16 +63,28 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().TestTypes(namespace).List(context.TODO(), options) + return client.ExampleV1alpha1().TestTypes(namespace).List(context.Background(), options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().TestTypes(namespace).Watch(context.TODO(), options) + return client.ExampleV1alpha1().TestTypes(namespace).Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1alpha1().TestTypes(namespace).List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1alpha1().TestTypes(namespace).Watch(ctx, options) }, }, - &examplev1alpha1.TestType{}, + &apisexamplev1alpha1.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +95,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1alpha1.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev1alpha1.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v1alpha1.TestTypeLister { - return v1alpha1.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() examplev1alpha1.TestTypeLister { + return examplev1alpha1.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v1beta1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example/v1beta1/clustertesttype.go index c54a3d916..53606d43d 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1beta1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1beta1/clustertesttype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1beta1 import ( - "context" + context "context" time "time" + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + examplev1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1beta1.ClusterTestTypeLister + Lister() examplev1beta1.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -62,16 +62,28 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1beta1().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV1beta1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1beta1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV1beta1().ClusterTestTypes().Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1beta1().ClusterTestTypes().List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1beta1().ClusterTestTypes().Watch(ctx, options) }, }, - &examplev1beta1.ClusterTestType{}, + &apisexamplev1beta1.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +94,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1beta1.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev1beta1.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v1beta1.ClusterTestTypeLister { - return v1beta1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() examplev1beta1.ClusterTestTypeLister { + return examplev1beta1.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v1beta1/interface.go b/examples/pkg/generated/informers/externalversions/example/v1beta1/interface.go index 5e9f38737..0dadec24f 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1beta1/interface.go +++ b/examples/pkg/generated/informers/externalversions/example/v1beta1/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1beta1 @@ -26,6 +26,8 @@ import ( type Interface interface { // ClusterTestTypes returns a ClusterTestTypeInformer. ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer } type version struct { @@ -43,3 +45,8 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList func (v *version) ClusterTestTypes() ClusterTestTypeInformer { return &clusterTestTypeInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeInformer. +func (v *version) TestTypes() TestTypeInformer { + return &testTypeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/generated/informers/externalversions/example/v1beta1/testtype.go b/examples/pkg/generated/informers/externalversions/example/v1beta1/testtype.go new file mode 100644 index 000000000..b4c960252 --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/example/v1beta1/testtype.go @@ -0,0 +1,103 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + context "context" + time "time" + + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + examplev1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev1beta1.TestTypeLister +} + +type testTypeInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTestTypeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1beta1().TestTypes(namespace).List(context.Background(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1beta1().TestTypes(namespace).Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1beta1().TestTypes(namespace).List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1beta1().TestTypes(namespace).Watch(ctx, options) + }, + }, + &apisexamplev1beta1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&apisexamplev1beta1.TestType{}, f.defaultInformer) +} + +func (f *testTypeInformer) Lister() examplev1beta1.TestTypeLister { + return examplev1beta1.NewTestTypeLister(f.Informer().GetIndexer()) +} diff --git a/examples/pkg/generated/informers/externalversions/example/v2/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example/v2/clustertesttype.go index ce7a8fcd3..455e7dc8a 100644 --- a/examples/pkg/generated/informers/externalversions/example/v2/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/example/v2/clustertesttype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v2 import ( - "context" + context "context" time "time" + apisexamplev2 "acme.corp/pkg/apis/example/v2" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + examplev2 "acme.corp/pkg/generated/listers/example/v2" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - examplev2 "acme.corp/pkg/apis/example/v2" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v2 "acme.corp/pkg/generated/listers/example/v2" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v2.ClusterTestTypeLister + Lister() examplev2.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -62,16 +62,28 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV2().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV2().ClusterTestTypes().Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV2().ClusterTestTypes().List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV2().ClusterTestTypes().Watch(ctx, options) }, }, - &examplev2.ClusterTestType{}, + &apisexamplev2.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +94,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev2.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev2.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v2.ClusterTestTypeLister { - return v2.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() examplev2.ClusterTestTypeLister { + return examplev2.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v2/interface.go b/examples/pkg/generated/informers/externalversions/example/v2/interface.go index 7bde7c88e..c96ac9643 100644 --- a/examples/pkg/generated/informers/externalversions/example/v2/interface.go +++ b/examples/pkg/generated/informers/externalversions/example/v2/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v2 diff --git a/examples/pkg/generated/informers/externalversions/example/v2/testtype.go b/examples/pkg/generated/informers/externalversions/example/v2/testtype.go index faccfdaf0..9482b6fa2 100644 --- a/examples/pkg/generated/informers/externalversions/example/v2/testtype.go +++ b/examples/pkg/generated/informers/externalversions/example/v2/testtype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v2 import ( - "context" + context "context" time "time" + apisexamplev2 "acme.corp/pkg/apis/example/v2" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + examplev2 "acme.corp/pkg/generated/listers/example/v2" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - examplev2 "acme.corp/pkg/apis/example/v2" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v2 "acme.corp/pkg/generated/listers/example/v2" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v2.TestTypeLister + Lister() examplev2.TestTypeLister } type testTypeInformer struct { @@ -63,16 +63,28 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().TestTypes(namespace).List(context.TODO(), options) + return client.ExampleV2().TestTypes(namespace).List(context.Background(), options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().TestTypes(namespace).Watch(context.TODO(), options) + return client.ExampleV2().TestTypes(namespace).Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV2().TestTypes(namespace).List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV2().TestTypes(namespace).Watch(ctx, options) }, }, - &examplev2.TestType{}, + &apisexamplev2.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +95,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev2.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev2.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v2.TestTypeLister { - return v2.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() examplev2.TestTypeLister { + return examplev2.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example3/interface.go b/examples/pkg/generated/informers/externalversions/example3/interface.go index a9ddd7cf7..ca19864d2 100644 --- a/examples/pkg/generated/informers/externalversions/example3/interface.go +++ b/examples/pkg/generated/informers/externalversions/example3/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package example3 diff --git a/examples/pkg/generated/informers/externalversions/example3/v1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example3/v1/clustertesttype.go index db7ec19a3..7b084a367 100644 --- a/examples/pkg/generated/informers/externalversions/example3/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/example3/v1/clustertesttype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" time "time" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + example3v1 "acme.corp/pkg/generated/listers/example3/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - example3v1 "acme.corp/pkg/apis/example3/v1" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/example3/v1" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.ClusterTestTypeLister + Lister() example3v1.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -62,16 +62,28 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().ClusterTestTypes().List(context.TODO(), options) + return client.Example3V1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().ClusterTestTypes().Watch(context.TODO(), options) + return client.Example3V1().ClusterTestTypes().Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Example3V1().ClusterTestTypes().List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Example3V1().ClusterTestTypes().Watch(ctx, options) }, }, - &example3v1.ClusterTestType{}, + &apisexample3v1.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +94,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&example3v1.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexample3v1.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v1.ClusterTestTypeLister { - return v1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() example3v1.ClusterTestTypeLister { + return example3v1.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example3/v1/interface.go b/examples/pkg/generated/informers/externalversions/example3/v1/interface.go index 6bb09cd81..4ba2de328 100644 --- a/examples/pkg/generated/informers/externalversions/example3/v1/interface.go +++ b/examples/pkg/generated/informers/externalversions/example3/v1/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/example3/v1/testtype.go b/examples/pkg/generated/informers/externalversions/example3/v1/testtype.go index 63dffd57f..1c374114d 100644 --- a/examples/pkg/generated/informers/externalversions/example3/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/example3/v1/testtype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" time "time" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + example3v1 "acme.corp/pkg/generated/listers/example3/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - example3v1 "acme.corp/pkg/apis/example3/v1" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/example3/v1" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.TestTypeLister + Lister() example3v1.TestTypeLister } type testTypeInformer struct { @@ -63,16 +63,28 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().TestTypes(namespace).List(context.TODO(), options) + return client.Example3V1().TestTypes(namespace).List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().TestTypes(namespace).Watch(context.TODO(), options) + return client.Example3V1().TestTypes(namespace).Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Example3V1().TestTypes(namespace).List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Example3V1().TestTypes(namespace).Watch(ctx, options) }, }, - &example3v1.TestType{}, + &apisexample3v1.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +95,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&example3v1.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexample3v1.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v1.TestTypeLister { - return v1.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() example3v1.TestTypeLister { + return example3v1.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/exampledashed/interface.go b/examples/pkg/generated/informers/externalversions/exampledashed/interface.go new file mode 100644 index 000000000..d794d48ae --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/exampledashed/interface.go @@ -0,0 +1,46 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package exampledashed + +import ( + v1 "acme.corp/pkg/generated/informers/externalversions/exampledashed/v1" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.Interface. +func (g *group) V1() v1.Interface { + return v1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/examples/pkg/generated/informers/externalversions/exampledashed/v1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..19b83eb8b --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/exampledashed/v1/clustertesttype.go @@ -0,0 +1,102 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + time "time" + + apisexampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + exampledashedv1 "acme.corp/pkg/generated/listers/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() exampledashedv1.ClusterTestTypeLister +} + +type clusterTestTypeInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewClusterTestTypeInformer constructs a new informer for ClusterTestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewClusterTestTypeInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().List(context.Background(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().Watch(ctx, options) + }, + }, + &apisexampledashedv1.ClusterTestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&apisexampledashedv1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeInformer) Lister() exampledashedv1.ClusterTestTypeLister { + return exampledashedv1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +} diff --git a/examples/pkg/generated/informers/externalversions/exampledashed/v1/interface.go b/examples/pkg/generated/informers/externalversions/exampledashed/v1/interface.go new file mode 100644 index 000000000..4ba2de328 --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/exampledashed/v1/interface.go @@ -0,0 +1,52 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // ClusterTestTypes returns a ClusterTestTypeInformer. + ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// ClusterTestTypes returns a ClusterTestTypeInformer. +func (v *version) ClusterTestTypes() ClusterTestTypeInformer { + return &clusterTestTypeInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// TestTypes returns a TestTypeInformer. +func (v *version) TestTypes() TestTypeInformer { + return &testTypeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/generated/informers/externalversions/exampledashed/v1/testtype.go b/examples/pkg/generated/informers/externalversions/exampledashed/v1/testtype.go new file mode 100644 index 000000000..3b261876a --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/exampledashed/v1/testtype.go @@ -0,0 +1,103 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + time "time" + + apisexampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + exampledashedv1 "acme.corp/pkg/generated/listers/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() exampledashedv1.TestTypeLister +} + +type testTypeInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTestTypeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes(namespace).List(context.Background(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes(namespace).Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes(namespace).List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes(namespace).Watch(ctx, options) + }, + }, + &apisexampledashedv1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&apisexampledashedv1.TestType{}, f.defaultInformer) +} + +func (f *testTypeInformer) Lister() exampledashedv1.TestTypeLister { + return exampledashedv1.NewTestTypeLister(f.Informer().GetIndexer()) +} diff --git a/examples/pkg/generated/informers/externalversions/existinginterfaces/interface.go b/examples/pkg/generated/informers/externalversions/existinginterfaces/interface.go index 5f50c62e1..5e61cbd2c 100644 --- a/examples/pkg/generated/informers/externalversions/existinginterfaces/interface.go +++ b/examples/pkg/generated/informers/externalversions/existinginterfaces/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package existinginterfaces diff --git a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/clustertesttype.go index 6e81db9f3..025516cb3 100644 --- a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/clustertesttype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" time "time" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + existinginterfacesv1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.ClusterTestTypeLister + Lister() existinginterfacesv1.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -62,16 +62,28 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().ClusterTestTypes().List(context.TODO(), options) + return client.ExistinginterfacesV1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExistinginterfacesV1().ClusterTestTypes().Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExistinginterfacesV1().ClusterTestTypes().List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExistinginterfacesV1().ClusterTestTypes().Watch(ctx, options) }, }, - &existinginterfacesv1.ClusterTestType{}, + &apisexistinginterfacesv1.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +94,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&existinginterfacesv1.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexistinginterfacesv1.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v1.ClusterTestTypeLister { - return v1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() existinginterfacesv1.ClusterTestTypeLister { + return existinginterfacesv1.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/interface.go b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/interface.go index 6bb09cd81..4ba2de328 100644 --- a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/interface.go +++ b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/testtype.go b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/testtype.go index 61822f543..d823f60c9 100644 --- a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/testtype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" time "time" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + existinginterfacesv1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.TestTypeLister + Lister() existinginterfacesv1.TestTypeLister } type testTypeInformer struct { @@ -63,16 +63,28 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().TestTypes(namespace).List(context.TODO(), options) + return client.ExistinginterfacesV1().TestTypes(namespace).List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().TestTypes(namespace).Watch(context.TODO(), options) + return client.ExistinginterfacesV1().TestTypes(namespace).Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExistinginterfacesV1().TestTypes(namespace).List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExistinginterfacesV1().TestTypes(namespace).Watch(ctx, options) }, }, - &existinginterfacesv1.TestType{}, + &apisexistinginterfacesv1.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +95,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&existinginterfacesv1.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexistinginterfacesv1.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v1.TestTypeLister { - return v1.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() existinginterfacesv1.TestTypeLister { + return existinginterfacesv1.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/factory.go b/examples/pkg/generated/informers/externalversions/factory.go index f3e8189b9..aee5eaa7f 100644 --- a/examples/pkg/generated/informers/externalversions/factory.go +++ b/examples/pkg/generated/informers/externalversions/factory.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package externalversions @@ -23,17 +23,18 @@ import ( sync "sync" time "time" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - cache "k8s.io/client-go/tools/cache" - versioned "acme.corp/pkg/generated/clientset/versioned" example "acme.corp/pkg/generated/informers/externalversions/example" example3 "acme.corp/pkg/generated/informers/externalversions/example3" + exampledashed "acme.corp/pkg/generated/informers/externalversions/exampledashed" existinginterfaces "acme.corp/pkg/generated/informers/externalversions/existinginterfaces" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" secondexample "acme.corp/pkg/generated/informers/externalversions/secondexample" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" ) // SharedInformerOption defines the functional option type for SharedInformerFactory. @@ -46,6 +47,7 @@ type sharedInformerFactory struct { lock sync.Mutex defaultResync time.Duration customResync map[reflect.Type]time.Duration + transform cache.TransformFunc informers map[reflect.Type]cache.SharedIndexInformer // startedInformers is used for tracking which informers have been started. @@ -84,6 +86,14 @@ func WithNamespace(namespace string) SharedInformerOption { } } +// WithTransform sets a transform on all informers. +func WithTransform(transform cache.TransformFunc) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.transform = transform + return factory + } +} + // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { return NewSharedInformerFactoryWithOptions(client, defaultResync) @@ -170,7 +180,7 @@ func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[ref return res } -// InternalInformerFor returns the SharedIndexInformer for obj using an internal +// InformerFor returns the SharedIndexInformer for obj using an internal // client. func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { f.lock.Lock() @@ -188,6 +198,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal } informer = newFunc(f.client, resyncPeriod) + informer.SetTransform(f.transform) f.informers[informerType] = informer return informer @@ -222,6 +233,7 @@ type SharedInformerFactory interface { // Start initializes all requested informers. They are handled in goroutines // which run until the stop channel gets closed. + // Warning: Start does not block. When run in a go-routine, it will race with a later WaitForCacheSync. Start(stopCh <-chan struct{}) // Shutdown marks a factory as shutting down. At that point no new @@ -243,12 +255,13 @@ type SharedInformerFactory interface { // ForResource gives generic access to a shared informer of the matching type. ForResource(resource schema.GroupVersionResource) (GenericInformer, error) - // InternalInformerFor returns the SharedIndexInformer for obj using an internal + // InformerFor returns the SharedIndexInformer for obj using an internal // client. InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer Example() example.Interface Example3() example3.Interface + ExampleDashed() exampledashed.Interface Existinginterfaces() existinginterfaces.Interface Secondexample() secondexample.Interface } @@ -261,6 +274,10 @@ func (f *sharedInformerFactory) Example3() example3.Interface { return example3.New(f, f.namespace, f.tweakListOptions) } +func (f *sharedInformerFactory) ExampleDashed() exampledashed.Interface { + return exampledashed.New(f, f.namespace, f.tweakListOptions) +} + func (f *sharedInformerFactory) Existinginterfaces() existinginterfaces.Interface { return existinginterfaces.New(f, f.namespace, f.tweakListOptions) } diff --git a/examples/pkg/generated/informers/externalversions/generic.go b/examples/pkg/generated/informers/externalversions/generic.go index aacd7ee8a..b875bb45d 100644 --- a/examples/pkg/generated/informers/externalversions/generic.go +++ b/examples/pkg/generated/informers/externalversions/generic.go @@ -14,23 +14,24 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package externalversions import ( - "fmt" + fmt "fmt" - schema "k8s.io/apimachinery/pkg/runtime/schema" - cache "k8s.io/client-go/tools/cache" - - v1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/apis/example/v1" v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" v1beta1 "acme.corp/pkg/apis/example/v1beta1" v2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + v1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" ) // GenericInformer is type of SharedIndexInformer which will locate and delegate to other @@ -59,23 +60,31 @@ func (f *genericInformer) Lister() cache.GenericLister { // TODO extend this to unknown resources with a client pool func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { - // Group=example, Version=v1 + // Group=example-dashed.some.corp, Version=v1 case v1.SchemeGroupVersion.WithResource("clustertesttypes"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1().ClusterTestTypes().Informer()}, nil + return &genericInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().ClusterTestTypes().Informer()}, nil case v1.SchemeGroupVersion.WithResource("testtypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().TestTypes().Informer()}, nil + + // Group=example.dev, Version=v1 + case examplev1.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1().ClusterTestTypes().Informer()}, nil + case examplev1.SchemeGroupVersion.WithResource("testtypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1().TestTypes().Informer()}, nil - // Group=example, Version=v1alpha1 + // Group=example.dev, Version=v1alpha1 case v1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1alpha1().ClusterTestTypes().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("testtypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1alpha1().TestTypes().Informer()}, nil - // Group=example, Version=v1beta1 + // Group=example.dev, Version=v1beta1 case v1beta1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().ClusterTestTypes().Informer()}, nil + case v1beta1.SchemeGroupVersion.WithResource("testtypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().TestTypes().Informer()}, nil - // Group=example, Version=v2 + // Group=example.dev, Version=v2 case v2.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V2().ClusterTestTypes().Informer()}, nil case v2.SchemeGroupVersion.WithResource("testtypes"): @@ -93,7 +102,7 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case existinginterfacesv1.SchemeGroupVersion.WithResource("testtypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Existinginterfaces().V1().TestTypes().Informer()}, nil - // Group=secondexample, Version=v1 + // Group=secondexample.dev, Version=v1 case secondexamplev1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Secondexample().V1().ClusterTestTypes().Informer()}, nil case secondexamplev1.SchemeGroupVersion.WithResource("testtypes"): diff --git a/examples/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go b/examples/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go index e65bdfcc6..40343e75a 100644 --- a/examples/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/examples/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -14,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package internalinterfaces import ( time "time" + versioned "acme.corp/pkg/generated/clientset/versioned" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" cache "k8s.io/client-go/tools/cache" - - versioned "acme.corp/pkg/generated/clientset/versioned" ) // NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. diff --git a/examples/pkg/generated/informers/externalversions/secondexample/interface.go b/examples/pkg/generated/informers/externalversions/secondexample/interface.go index 0d2374a7d..e76c43ed9 100644 --- a/examples/pkg/generated/informers/externalversions/secondexample/interface.go +++ b/examples/pkg/generated/informers/externalversions/secondexample/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package secondexample diff --git a/examples/pkg/generated/informers/externalversions/secondexample/v1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/secondexample/v1/clustertesttype.go index f84dc29d8..5d4df3ccb 100644 --- a/examples/pkg/generated/informers/externalversions/secondexample/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/secondexample/v1/clustertesttype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" time "time" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + secondexamplev1 "acme.corp/pkg/generated/listers/secondexample/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/secondexample/v1" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.ClusterTestTypeLister + Lister() secondexamplev1.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -62,16 +62,28 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().ClusterTestTypes().List(context.TODO(), options) + return client.SecondexampleV1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().ClusterTestTypes().Watch(context.TODO(), options) + return client.SecondexampleV1().ClusterTestTypes().Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SecondexampleV1().ClusterTestTypes().List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SecondexampleV1().ClusterTestTypes().Watch(ctx, options) }, }, - &secondexamplev1.ClusterTestType{}, + &apissecondexamplev1.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +94,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&secondexamplev1.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apissecondexamplev1.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v1.ClusterTestTypeLister { - return v1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() secondexamplev1.ClusterTestTypeLister { + return secondexamplev1.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/secondexample/v1/interface.go b/examples/pkg/generated/informers/externalversions/secondexample/v1/interface.go index 6bb09cd81..4ba2de328 100644 --- a/examples/pkg/generated/informers/externalversions/secondexample/v1/interface.go +++ b/examples/pkg/generated/informers/externalversions/secondexample/v1/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/secondexample/v1/testtype.go b/examples/pkg/generated/informers/externalversions/secondexample/v1/testtype.go index e7f098e11..cdcb809b2 100644 --- a/examples/pkg/generated/informers/externalversions/secondexample/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/secondexample/v1/testtype.go @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by informer-gen-v0.26.3. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" time "time" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + secondexamplev1 "acme.corp/pkg/generated/listers/secondexample/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - versioned "acme.corp/pkg/generated/clientset/versioned" - internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/secondexample/v1" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.TestTypeLister + Lister() secondexamplev1.TestTypeLister } type testTypeInformer struct { @@ -63,16 +63,28 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().TestTypes(namespace).List(context.TODO(), options) + return client.SecondexampleV1().TestTypes(namespace).List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().TestTypes(namespace).Watch(context.TODO(), options) + return client.SecondexampleV1().TestTypes(namespace).Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SecondexampleV1().TestTypes(namespace).List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SecondexampleV1().TestTypes(namespace).Watch(ctx, options) }, }, - &secondexamplev1.TestType{}, + &apissecondexamplev1.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +95,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&secondexamplev1.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apissecondexamplev1.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v1.TestTypeLister { - return v1.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() secondexamplev1.TestTypeLister { + return secondexamplev1.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/listers/example/v1/clustertesttype.go b/examples/pkg/generated/listers/example/v1/clustertesttype.go index 70c197b00..a5c1f6f82 100644 --- a/examples/pkg/generated/listers/example/v1/clustertesttype.go +++ b/examples/pkg/generated/listers/example/v1/clustertesttype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + examplev1 "acme.corp/pkg/apis/example/v1" - v1 "acme.corp/pkg/apis/example/v1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // ClusterTestTypeLister helps list ClusterTestTypes. @@ -31,39 +31,19 @@ import ( type ClusterTestTypeLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) + List(selector labels.Selector) (ret []*examplev1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the index for a given name. // Objects returned here must be treated as read-only. - Get(name string) (*v1.ClusterTestType, error) + Get(name string) (*examplev1.ClusterTestType, error) ClusterTestTypeListerExpansion } // clusterTestTypeLister implements the ClusterTestTypeLister interface. type clusterTestTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*examplev1.ClusterTestType] } // NewClusterTestTypeLister returns a new ClusterTestTypeLister. func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the index for a given name. -func (s *clusterTestTypeLister) Get(name string) (*v1.ClusterTestType, error) { - obj, exists, err := s.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("clustertesttype"), name) - } - return obj.(*v1.ClusterTestType), nil + return &clusterTestTypeLister{listers.New[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype"))} } diff --git a/examples/pkg/generated/listers/example/v1/expansion_generated.go b/examples/pkg/generated/listers/example/v1/expansion_generated.go index d3b52039e..de4b7a08d 100644 --- a/examples/pkg/generated/listers/example/v1/expansion_generated.go +++ b/examples/pkg/generated/listers/example/v1/expansion_generated.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/example/v1/testtype.go b/examples/pkg/generated/listers/example/v1/testtype.go index 5fbefede8..5b4c1382d 100644 --- a/examples/pkg/generated/listers/example/v1/testtype.go +++ b/examples/pkg/generated/listers/example/v1/testtype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + examplev1 "acme.corp/pkg/apis/example/v1" - v1 "acme.corp/pkg/apis/example/v1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // TestTypeLister helps list TestTypes. @@ -31,7 +31,7 @@ import ( type TestTypeLister interface { // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.TestType, err error) + List(selector labels.Selector) (ret []*examplev1.TestType, err error) // TestTypes returns an object that can list and get TestTypes. TestTypes(namespace string) TestTypeNamespaceLister TestTypeListerExpansion @@ -39,25 +39,17 @@ type TestTypeLister interface { // testTypeLister implements the TestTypeLister interface. type testTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*examplev1.TestType] } // NewTestTypeLister returns a new TestTypeLister. func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer. -func (s *testTypeLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TestType)) - }) - return ret, err + return &testTypeLister{listers.New[*examplev1.TestType](indexer, examplev1.Resource("testtype"))} } // TestTypes returns an object that can list and get TestTypes. func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return testTypeNamespaceLister{indexer: s.indexer, namespace: namespace} + return testTypeNamespaceLister{listers.NewNamespaced[*examplev1.TestType](s.ResourceIndexer, namespace)} } // TestTypeNamespaceLister helps list and get TestTypes. @@ -65,36 +57,15 @@ func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { type TestTypeNamespaceLister interface { // List lists all TestTypes in the indexer for a given namespace. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.TestType, err error) + List(selector labels.Selector) (ret []*examplev1.TestType, err error) // Get retrieves the TestType from the indexer for a given namespace and name. // Objects returned here must be treated as read-only. - Get(name string) (*v1.TestType, error) + Get(name string) (*examplev1.TestType, error) TestTypeNamespaceListerExpansion } // testTypeNamespaceLister implements the TestTypeNamespaceLister // interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given namespace. -func (s testTypeNamespaceLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given namespace and name. -func (s testTypeNamespaceLister) Get(name string) (*v1.TestType, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("testtype"), name) - } - return obj.(*v1.TestType), nil + listers.ResourceIndexer[*examplev1.TestType] } diff --git a/examples/pkg/generated/listers/example/v1/withoutverbtype.go b/examples/pkg/generated/listers/example/v1/withoutverbtype.go index c5dc7ccb5..72fb8fd03 100644 --- a/examples/pkg/generated/listers/example/v1/withoutverbtype.go +++ b/examples/pkg/generated/listers/example/v1/withoutverbtype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + examplev1 "acme.corp/pkg/apis/example/v1" - v1 "acme.corp/pkg/apis/example/v1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // WithoutVerbTypeLister helps list WithoutVerbTypes. @@ -31,7 +31,7 @@ import ( type WithoutVerbTypeLister interface { // List lists all WithoutVerbTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.WithoutVerbType, err error) + List(selector labels.Selector) (ret []*examplev1.WithoutVerbType, err error) // WithoutVerbTypes returns an object that can list and get WithoutVerbTypes. WithoutVerbTypes(namespace string) WithoutVerbTypeNamespaceLister WithoutVerbTypeListerExpansion @@ -39,25 +39,17 @@ type WithoutVerbTypeLister interface { // withoutVerbTypeLister implements the WithoutVerbTypeLister interface. type withoutVerbTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*examplev1.WithoutVerbType] } // NewWithoutVerbTypeLister returns a new WithoutVerbTypeLister. func NewWithoutVerbTypeLister(indexer cache.Indexer) WithoutVerbTypeLister { - return &withoutVerbTypeLister{indexer: indexer} -} - -// List lists all WithoutVerbTypes in the indexer. -func (s *withoutVerbTypeLister) List(selector labels.Selector) (ret []*v1.WithoutVerbType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.WithoutVerbType)) - }) - return ret, err + return &withoutVerbTypeLister{listers.New[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype"))} } // WithoutVerbTypes returns an object that can list and get WithoutVerbTypes. func (s *withoutVerbTypeLister) WithoutVerbTypes(namespace string) WithoutVerbTypeNamespaceLister { - return withoutVerbTypeNamespaceLister{indexer: s.indexer, namespace: namespace} + return withoutVerbTypeNamespaceLister{listers.NewNamespaced[*examplev1.WithoutVerbType](s.ResourceIndexer, namespace)} } // WithoutVerbTypeNamespaceLister helps list and get WithoutVerbTypes. @@ -65,36 +57,15 @@ func (s *withoutVerbTypeLister) WithoutVerbTypes(namespace string) WithoutVerbTy type WithoutVerbTypeNamespaceLister interface { // List lists all WithoutVerbTypes in the indexer for a given namespace. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.WithoutVerbType, err error) + List(selector labels.Selector) (ret []*examplev1.WithoutVerbType, err error) // Get retrieves the WithoutVerbType from the indexer for a given namespace and name. // Objects returned here must be treated as read-only. - Get(name string) (*v1.WithoutVerbType, error) + Get(name string) (*examplev1.WithoutVerbType, error) WithoutVerbTypeNamespaceListerExpansion } // withoutVerbTypeNamespaceLister implements the WithoutVerbTypeNamespaceLister // interface. type withoutVerbTypeNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all WithoutVerbTypes in the indexer for a given namespace. -func (s withoutVerbTypeNamespaceLister) List(selector labels.Selector) (ret []*v1.WithoutVerbType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.WithoutVerbType)) - }) - return ret, err -} - -// Get retrieves the WithoutVerbType from the indexer for a given namespace and name. -func (s withoutVerbTypeNamespaceLister) Get(name string) (*v1.WithoutVerbType, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("withoutverbtype"), name) - } - return obj.(*v1.WithoutVerbType), nil + listers.ResourceIndexer[*examplev1.WithoutVerbType] } diff --git a/examples/pkg/generated/listers/example/v1alpha1/clustertesttype.go b/examples/pkg/generated/listers/example/v1alpha1/clustertesttype.go index 7b125c190..3206fa6db 100644 --- a/examples/pkg/generated/listers/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/generated/listers/example/v1alpha1/clustertesttype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1alpha1 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // ClusterTestTypeLister helps list ClusterTestTypes. @@ -31,39 +31,19 @@ import ( type ClusterTestTypeLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha1.ClusterTestType, err error) + List(selector labels.Selector) (ret []*examplev1alpha1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the index for a given name. // Objects returned here must be treated as read-only. - Get(name string) (*v1alpha1.ClusterTestType, error) + Get(name string) (*examplev1alpha1.ClusterTestType, error) ClusterTestTypeListerExpansion } // clusterTestTypeLister implements the ClusterTestTypeLister interface. type clusterTestTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*examplev1alpha1.ClusterTestType] } // NewClusterTestTypeLister returns a new ClusterTestTypeLister. func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*v1alpha1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the index for a given name. -func (s *clusterTestTypeLister) Get(name string) (*v1alpha1.ClusterTestType, error) { - obj, exists, err := s.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("clustertesttype"), name) - } - return obj.(*v1alpha1.ClusterTestType), nil + return &clusterTestTypeLister{listers.New[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype"))} } diff --git a/examples/pkg/generated/listers/example/v1alpha1/expansion_generated.go b/examples/pkg/generated/listers/example/v1alpha1/expansion_generated.go index 4eab86c2f..7602d5f70 100644 --- a/examples/pkg/generated/listers/example/v1alpha1/expansion_generated.go +++ b/examples/pkg/generated/listers/example/v1alpha1/expansion_generated.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1alpha1 diff --git a/examples/pkg/generated/listers/example/v1alpha1/testtype.go b/examples/pkg/generated/listers/example/v1alpha1/testtype.go index e0c767b80..ef5ddd6ca 100644 --- a/examples/pkg/generated/listers/example/v1alpha1/testtype.go +++ b/examples/pkg/generated/listers/example/v1alpha1/testtype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1alpha1 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // TestTypeLister helps list TestTypes. @@ -31,7 +31,7 @@ import ( type TestTypeLister interface { // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha1.TestType, err error) + List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) // TestTypes returns an object that can list and get TestTypes. TestTypes(namespace string) TestTypeNamespaceLister TestTypeListerExpansion @@ -39,25 +39,17 @@ type TestTypeLister interface { // testTypeLister implements the TestTypeLister interface. type testTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*examplev1alpha1.TestType] } // NewTestTypeLister returns a new TestTypeLister. func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer. -func (s *testTypeLister) List(selector labels.Selector) (ret []*v1alpha1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.TestType)) - }) - return ret, err + return &testTypeLister{listers.New[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype"))} } // TestTypes returns an object that can list and get TestTypes. func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return testTypeNamespaceLister{indexer: s.indexer, namespace: namespace} + return testTypeNamespaceLister{listers.NewNamespaced[*examplev1alpha1.TestType](s.ResourceIndexer, namespace)} } // TestTypeNamespaceLister helps list and get TestTypes. @@ -65,36 +57,15 @@ func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { type TestTypeNamespaceLister interface { // List lists all TestTypes in the indexer for a given namespace. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha1.TestType, err error) + List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) // Get retrieves the TestType from the indexer for a given namespace and name. // Objects returned here must be treated as read-only. - Get(name string) (*v1alpha1.TestType, error) + Get(name string) (*examplev1alpha1.TestType, error) TestTypeNamespaceListerExpansion } // testTypeNamespaceLister implements the TestTypeNamespaceLister // interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given namespace. -func (s testTypeNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given namespace and name. -func (s testTypeNamespaceLister) Get(name string) (*v1alpha1.TestType, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("testtype"), name) - } - return obj.(*v1alpha1.TestType), nil + listers.ResourceIndexer[*examplev1alpha1.TestType] } diff --git a/examples/pkg/generated/listers/example/v1beta1/clustertesttype.go b/examples/pkg/generated/listers/example/v1beta1/clustertesttype.go index c7419795c..ad5041f04 100644 --- a/examples/pkg/generated/listers/example/v1beta1/clustertesttype.go +++ b/examples/pkg/generated/listers/example/v1beta1/clustertesttype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1beta1 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - v1beta1 "acme.corp/pkg/apis/example/v1beta1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // ClusterTestTypeLister helps list ClusterTestTypes. @@ -31,39 +31,19 @@ import ( type ClusterTestTypeLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1beta1.ClusterTestType, err error) + List(selector labels.Selector) (ret []*examplev1beta1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the index for a given name. // Objects returned here must be treated as read-only. - Get(name string) (*v1beta1.ClusterTestType, error) + Get(name string) (*examplev1beta1.ClusterTestType, error) ClusterTestTypeListerExpansion } // clusterTestTypeLister implements the ClusterTestTypeLister interface. type clusterTestTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*examplev1beta1.ClusterTestType] } // NewClusterTestTypeLister returns a new ClusterTestTypeLister. func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*v1beta1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the index for a given name. -func (s *clusterTestTypeLister) Get(name string) (*v1beta1.ClusterTestType, error) { - obj, exists, err := s.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1beta1.Resource("clustertesttype"), name) - } - return obj.(*v1beta1.ClusterTestType), nil + return &clusterTestTypeLister{listers.New[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype"))} } diff --git a/examples/pkg/generated/listers/example/v1beta1/expansion_generated.go b/examples/pkg/generated/listers/example/v1beta1/expansion_generated.go index 541811b16..de94ad494 100644 --- a/examples/pkg/generated/listers/example/v1beta1/expansion_generated.go +++ b/examples/pkg/generated/listers/example/v1beta1/expansion_generated.go @@ -14,10 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1beta1 // ClusterTestTypeListerExpansion allows custom methods to be added to // ClusterTestTypeLister. type ClusterTestTypeListerExpansion interface{} + +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. +type TestTypeListerExpansion interface{} + +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. +type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/generated/listers/example/v1beta1/testtype.go b/examples/pkg/generated/listers/example/v1beta1/testtype.go new file mode 100644 index 000000000..bf47b5e74 --- /dev/null +++ b/examples/pkg/generated/listers/example/v1beta1/testtype.go @@ -0,0 +1,71 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1beta1 + +import ( + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" +) + +// TestTypeLister helps list TestTypes. +// All objects returned here must be treated as read-only. +type TestTypeLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*examplev1beta1.TestType, err error) + // TestTypes returns an object that can list and get TestTypes. + TestTypes(namespace string) TestTypeNamespaceLister + TestTypeListerExpansion +} + +// testTypeLister implements the TestTypeLister interface. +type testTypeLister struct { + listers.ResourceIndexer[*examplev1beta1.TestType] +} + +// NewTestTypeLister returns a new TestTypeLister. +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{listers.New[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype"))} +} + +// TestTypes returns an object that can list and get TestTypes. +func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return testTypeNamespaceLister{listers.NewNamespaced[*examplev1beta1.TestType](s.ResourceIndexer, namespace)} +} + +// TestTypeNamespaceLister helps list and get TestTypes. +// All objects returned here must be treated as read-only. +type TestTypeNamespaceLister interface { + // List lists all TestTypes in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*examplev1beta1.TestType, err error) + // Get retrieves the TestType from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*examplev1beta1.TestType, error) + TestTypeNamespaceListerExpansion +} + +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + listers.ResourceIndexer[*examplev1beta1.TestType] +} diff --git a/examples/pkg/generated/listers/example/v2/clustertesttype.go b/examples/pkg/generated/listers/example/v2/clustertesttype.go index 4aa4ad919..ae2dcc7a5 100644 --- a/examples/pkg/generated/listers/example/v2/clustertesttype.go +++ b/examples/pkg/generated/listers/example/v2/clustertesttype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v2 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + examplev2 "acme.corp/pkg/apis/example/v2" - v2 "acme.corp/pkg/apis/example/v2" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // ClusterTestTypeLister helps list ClusterTestTypes. @@ -31,39 +31,19 @@ import ( type ClusterTestTypeLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v2.ClusterTestType, err error) + List(selector labels.Selector) (ret []*examplev2.ClusterTestType, err error) // Get retrieves the ClusterTestType from the index for a given name. // Objects returned here must be treated as read-only. - Get(name string) (*v2.ClusterTestType, error) + Get(name string) (*examplev2.ClusterTestType, error) ClusterTestTypeListerExpansion } // clusterTestTypeLister implements the ClusterTestTypeLister interface. type clusterTestTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*examplev2.ClusterTestType] } // NewClusterTestTypeLister returns a new ClusterTestTypeLister. func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*v2.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v2.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the index for a given name. -func (s *clusterTestTypeLister) Get(name string) (*v2.ClusterTestType, error) { - obj, exists, err := s.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v2.Resource("clustertesttype"), name) - } - return obj.(*v2.ClusterTestType), nil + return &clusterTestTypeLister{listers.New[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype"))} } diff --git a/examples/pkg/generated/listers/example/v2/expansion_generated.go b/examples/pkg/generated/listers/example/v2/expansion_generated.go index 5329655e2..8715bf222 100644 --- a/examples/pkg/generated/listers/example/v2/expansion_generated.go +++ b/examples/pkg/generated/listers/example/v2/expansion_generated.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v2 diff --git a/examples/pkg/generated/listers/example/v2/testtype.go b/examples/pkg/generated/listers/example/v2/testtype.go index 1e3f3d6dd..a2fa81e97 100644 --- a/examples/pkg/generated/listers/example/v2/testtype.go +++ b/examples/pkg/generated/listers/example/v2/testtype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v2 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + examplev2 "acme.corp/pkg/apis/example/v2" - v2 "acme.corp/pkg/apis/example/v2" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // TestTypeLister helps list TestTypes. @@ -31,7 +31,7 @@ import ( type TestTypeLister interface { // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v2.TestType, err error) + List(selector labels.Selector) (ret []*examplev2.TestType, err error) // TestTypes returns an object that can list and get TestTypes. TestTypes(namespace string) TestTypeNamespaceLister TestTypeListerExpansion @@ -39,25 +39,17 @@ type TestTypeLister interface { // testTypeLister implements the TestTypeLister interface. type testTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*examplev2.TestType] } // NewTestTypeLister returns a new TestTypeLister. func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer. -func (s *testTypeLister) List(selector labels.Selector) (ret []*v2.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v2.TestType)) - }) - return ret, err + return &testTypeLister{listers.New[*examplev2.TestType](indexer, examplev2.Resource("testtype"))} } // TestTypes returns an object that can list and get TestTypes. func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return testTypeNamespaceLister{indexer: s.indexer, namespace: namespace} + return testTypeNamespaceLister{listers.NewNamespaced[*examplev2.TestType](s.ResourceIndexer, namespace)} } // TestTypeNamespaceLister helps list and get TestTypes. @@ -65,36 +57,15 @@ func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { type TestTypeNamespaceLister interface { // List lists all TestTypes in the indexer for a given namespace. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v2.TestType, err error) + List(selector labels.Selector) (ret []*examplev2.TestType, err error) // Get retrieves the TestType from the indexer for a given namespace and name. // Objects returned here must be treated as read-only. - Get(name string) (*v2.TestType, error) + Get(name string) (*examplev2.TestType, error) TestTypeNamespaceListerExpansion } // testTypeNamespaceLister implements the TestTypeNamespaceLister // interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given namespace. -func (s testTypeNamespaceLister) List(selector labels.Selector) (ret []*v2.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v2.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given namespace and name. -func (s testTypeNamespaceLister) Get(name string) (*v2.TestType, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v2.Resource("testtype"), name) - } - return obj.(*v2.TestType), nil + listers.ResourceIndexer[*examplev2.TestType] } diff --git a/examples/pkg/generated/listers/example3/v1/clustertesttype.go b/examples/pkg/generated/listers/example3/v1/clustertesttype.go index c9267d1a7..887d03c52 100644 --- a/examples/pkg/generated/listers/example3/v1/clustertesttype.go +++ b/examples/pkg/generated/listers/example3/v1/clustertesttype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + example3v1 "acme.corp/pkg/apis/example3/v1" - v1 "acme.corp/pkg/apis/example3/v1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // ClusterTestTypeLister helps list ClusterTestTypes. @@ -31,39 +31,19 @@ import ( type ClusterTestTypeLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) + List(selector labels.Selector) (ret []*example3v1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the index for a given name. // Objects returned here must be treated as read-only. - Get(name string) (*v1.ClusterTestType, error) + Get(name string) (*example3v1.ClusterTestType, error) ClusterTestTypeListerExpansion } // clusterTestTypeLister implements the ClusterTestTypeLister interface. type clusterTestTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*example3v1.ClusterTestType] } // NewClusterTestTypeLister returns a new ClusterTestTypeLister. func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the index for a given name. -func (s *clusterTestTypeLister) Get(name string) (*v1.ClusterTestType, error) { - obj, exists, err := s.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("clustertesttype"), name) - } - return obj.(*v1.ClusterTestType), nil + return &clusterTestTypeLister{listers.New[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype"))} } diff --git a/examples/pkg/generated/listers/example3/v1/expansion_generated.go b/examples/pkg/generated/listers/example3/v1/expansion_generated.go index 83daaf706..6080bffc0 100644 --- a/examples/pkg/generated/listers/example3/v1/expansion_generated.go +++ b/examples/pkg/generated/listers/example3/v1/expansion_generated.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/example3/v1/testtype.go b/examples/pkg/generated/listers/example3/v1/testtype.go index 7250e7535..1ac233f4a 100644 --- a/examples/pkg/generated/listers/example3/v1/testtype.go +++ b/examples/pkg/generated/listers/example3/v1/testtype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + example3v1 "acme.corp/pkg/apis/example3/v1" - v1 "acme.corp/pkg/apis/example3/v1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // TestTypeLister helps list TestTypes. @@ -31,7 +31,7 @@ import ( type TestTypeLister interface { // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.TestType, err error) + List(selector labels.Selector) (ret []*example3v1.TestType, err error) // TestTypes returns an object that can list and get TestTypes. TestTypes(namespace string) TestTypeNamespaceLister TestTypeListerExpansion @@ -39,25 +39,17 @@ type TestTypeLister interface { // testTypeLister implements the TestTypeLister interface. type testTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*example3v1.TestType] } // NewTestTypeLister returns a new TestTypeLister. func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer. -func (s *testTypeLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TestType)) - }) - return ret, err + return &testTypeLister{listers.New[*example3v1.TestType](indexer, example3v1.Resource("testtype"))} } // TestTypes returns an object that can list and get TestTypes. func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return testTypeNamespaceLister{indexer: s.indexer, namespace: namespace} + return testTypeNamespaceLister{listers.NewNamespaced[*example3v1.TestType](s.ResourceIndexer, namespace)} } // TestTypeNamespaceLister helps list and get TestTypes. @@ -65,36 +57,15 @@ func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { type TestTypeNamespaceLister interface { // List lists all TestTypes in the indexer for a given namespace. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.TestType, err error) + List(selector labels.Selector) (ret []*example3v1.TestType, err error) // Get retrieves the TestType from the indexer for a given namespace and name. // Objects returned here must be treated as read-only. - Get(name string) (*v1.TestType, error) + Get(name string) (*example3v1.TestType, error) TestTypeNamespaceListerExpansion } // testTypeNamespaceLister implements the TestTypeNamespaceLister // interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given namespace. -func (s testTypeNamespaceLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given namespace and name. -func (s testTypeNamespaceLister) Get(name string) (*v1.TestType, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("testtype"), name) - } - return obj.(*v1.TestType), nil + listers.ResourceIndexer[*example3v1.TestType] } diff --git a/examples/pkg/generated/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/generated/listers/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..dfc566624 --- /dev/null +++ b/examples/pkg/generated/listers/exampledashed/v1/clustertesttype.go @@ -0,0 +1,49 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +import ( + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" +) + +// ClusterTestTypeLister helps list ClusterTestTypes. +// All objects returned here must be treated as read-only. +type ClusterTestTypeLister interface { + // List lists all ClusterTestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) + // Get retrieves the ClusterTestType from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*exampledashedv1.ClusterTestType, error) + ClusterTestTypeListerExpansion +} + +// clusterTestTypeLister implements the ClusterTestTypeLister interface. +type clusterTestTypeLister struct { + listers.ResourceIndexer[*exampledashedv1.ClusterTestType] +} + +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{listers.New[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype"))} +} diff --git a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype_expansion.go b/examples/pkg/generated/listers/exampledashed/v1/expansion_generated.go similarity index 65% rename from examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype_expansion.go rename to examples/pkg/generated/listers/exampledashed/v1/expansion_generated.go index 3f50c325f..6080bffc0 100644 --- a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype_expansion.go +++ b/examples/pkg/generated/listers/exampledashed/v1/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,15 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 -// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. -type TestTypeClusterListerExpansion interface{} +// ClusterTestTypeListerExpansion allows custom methods to be added to +// ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} -// TestTypeListerExpansion allows custom methods to be added to TestTypeLister. +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. type TestTypeListerExpansion interface{} -// TestTypeNamespaceListerExpansion allows custom methods to be added to TestTypeNamespaceLister. +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/generated/listers/exampledashed/v1/testtype.go b/examples/pkg/generated/listers/exampledashed/v1/testtype.go new file mode 100644 index 000000000..0e1cb9b2e --- /dev/null +++ b/examples/pkg/generated/listers/exampledashed/v1/testtype.go @@ -0,0 +1,71 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +import ( + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" +) + +// TestTypeLister helps list TestTypes. +// All objects returned here must be treated as read-only. +type TestTypeLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) + // TestTypes returns an object that can list and get TestTypes. + TestTypes(namespace string) TestTypeNamespaceLister + TestTypeListerExpansion +} + +// testTypeLister implements the TestTypeLister interface. +type testTypeLister struct { + listers.ResourceIndexer[*exampledashedv1.TestType] +} + +// NewTestTypeLister returns a new TestTypeLister. +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{listers.New[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype"))} +} + +// TestTypes returns an object that can list and get TestTypes. +func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return testTypeNamespaceLister{listers.NewNamespaced[*exampledashedv1.TestType](s.ResourceIndexer, namespace)} +} + +// TestTypeNamespaceLister helps list and get TestTypes. +// All objects returned here must be treated as read-only. +type TestTypeNamespaceLister interface { + // List lists all TestTypes in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) + // Get retrieves the TestType from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*exampledashedv1.TestType, error) + TestTypeNamespaceListerExpansion +} + +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + listers.ResourceIndexer[*exampledashedv1.TestType] +} diff --git a/examples/pkg/generated/listers/existinginterfaces/v1/clustertesttype.go b/examples/pkg/generated/listers/existinginterfaces/v1/clustertesttype.go index 12e332d36..844fb4cb5 100644 --- a/examples/pkg/generated/listers/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/generated/listers/existinginterfaces/v1/clustertesttype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - v1 "acme.corp/pkg/apis/existinginterfaces/v1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // ClusterTestTypeLister helps list ClusterTestTypes. @@ -31,39 +31,19 @@ import ( type ClusterTestTypeLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) + List(selector labels.Selector) (ret []*existinginterfacesv1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the index for a given name. // Objects returned here must be treated as read-only. - Get(name string) (*v1.ClusterTestType, error) + Get(name string) (*existinginterfacesv1.ClusterTestType, error) ClusterTestTypeListerExpansion } // clusterTestTypeLister implements the ClusterTestTypeLister interface. type clusterTestTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*existinginterfacesv1.ClusterTestType] } // NewClusterTestTypeLister returns a new ClusterTestTypeLister. func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the index for a given name. -func (s *clusterTestTypeLister) Get(name string) (*v1.ClusterTestType, error) { - obj, exists, err := s.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("clustertesttype"), name) - } - return obj.(*v1.ClusterTestType), nil + return &clusterTestTypeLister{listers.New[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype"))} } diff --git a/examples/pkg/generated/listers/existinginterfaces/v1/expansion_generated.go b/examples/pkg/generated/listers/existinginterfaces/v1/expansion_generated.go index 83daaf706..6080bffc0 100644 --- a/examples/pkg/generated/listers/existinginterfaces/v1/expansion_generated.go +++ b/examples/pkg/generated/listers/existinginterfaces/v1/expansion_generated.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/existinginterfaces/v1/testtype.go b/examples/pkg/generated/listers/existinginterfaces/v1/testtype.go index 733fd734a..6aa44aee5 100644 --- a/examples/pkg/generated/listers/existinginterfaces/v1/testtype.go +++ b/examples/pkg/generated/listers/existinginterfaces/v1/testtype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - v1 "acme.corp/pkg/apis/existinginterfaces/v1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // TestTypeLister helps list TestTypes. @@ -31,7 +31,7 @@ import ( type TestTypeLister interface { // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.TestType, err error) + List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) // TestTypes returns an object that can list and get TestTypes. TestTypes(namespace string) TestTypeNamespaceLister TestTypeListerExpansion @@ -39,25 +39,17 @@ type TestTypeLister interface { // testTypeLister implements the TestTypeLister interface. type testTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*existinginterfacesv1.TestType] } // NewTestTypeLister returns a new TestTypeLister. func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer. -func (s *testTypeLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TestType)) - }) - return ret, err + return &testTypeLister{listers.New[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype"))} } // TestTypes returns an object that can list and get TestTypes. func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return testTypeNamespaceLister{indexer: s.indexer, namespace: namespace} + return testTypeNamespaceLister{listers.NewNamespaced[*existinginterfacesv1.TestType](s.ResourceIndexer, namespace)} } // TestTypeNamespaceLister helps list and get TestTypes. @@ -65,36 +57,15 @@ func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { type TestTypeNamespaceLister interface { // List lists all TestTypes in the indexer for a given namespace. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.TestType, err error) + List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) // Get retrieves the TestType from the indexer for a given namespace and name. // Objects returned here must be treated as read-only. - Get(name string) (*v1.TestType, error) + Get(name string) (*existinginterfacesv1.TestType, error) TestTypeNamespaceListerExpansion } // testTypeNamespaceLister implements the TestTypeNamespaceLister // interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given namespace. -func (s testTypeNamespaceLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given namespace and name. -func (s testTypeNamespaceLister) Get(name string) (*v1.TestType, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("testtype"), name) - } - return obj.(*v1.TestType), nil + listers.ResourceIndexer[*existinginterfacesv1.TestType] } diff --git a/examples/pkg/generated/listers/secondexample/v1/clustertesttype.go b/examples/pkg/generated/listers/secondexample/v1/clustertesttype.go index 31a95b8d6..e40bb599e 100644 --- a/examples/pkg/generated/listers/secondexample/v1/clustertesttype.go +++ b/examples/pkg/generated/listers/secondexample/v1/clustertesttype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - v1 "acme.corp/pkg/apis/secondexample/v1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // ClusterTestTypeLister helps list ClusterTestTypes. @@ -31,39 +31,19 @@ import ( type ClusterTestTypeLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) + List(selector labels.Selector) (ret []*secondexamplev1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the index for a given name. // Objects returned here must be treated as read-only. - Get(name string) (*v1.ClusterTestType, error) + Get(name string) (*secondexamplev1.ClusterTestType, error) ClusterTestTypeListerExpansion } // clusterTestTypeLister implements the ClusterTestTypeLister interface. type clusterTestTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*secondexamplev1.ClusterTestType] } // NewClusterTestTypeLister returns a new ClusterTestTypeLister. func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the index for a given name. -func (s *clusterTestTypeLister) Get(name string) (*v1.ClusterTestType, error) { - obj, exists, err := s.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("clustertesttype"), name) - } - return obj.(*v1.ClusterTestType), nil + return &clusterTestTypeLister{listers.New[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype"))} } diff --git a/examples/pkg/generated/listers/secondexample/v1/expansion_generated.go b/examples/pkg/generated/listers/secondexample/v1/expansion_generated.go index 83daaf706..6080bffc0 100644 --- a/examples/pkg/generated/listers/secondexample/v1/expansion_generated.go +++ b/examples/pkg/generated/listers/secondexample/v1/expansion_generated.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/secondexample/v1/testtype.go b/examples/pkg/generated/listers/secondexample/v1/testtype.go index 2d637d067..291604c6a 100644 --- a/examples/pkg/generated/listers/secondexample/v1/testtype.go +++ b/examples/pkg/generated/listers/secondexample/v1/testtype.go @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by lister-gen-v0.26.3. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - v1 "acme.corp/pkg/apis/secondexample/v1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" ) // TestTypeLister helps list TestTypes. @@ -31,7 +31,7 @@ import ( type TestTypeLister interface { // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.TestType, err error) + List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) // TestTypes returns an object that can list and get TestTypes. TestTypes(namespace string) TestTypeNamespaceLister TestTypeListerExpansion @@ -39,25 +39,17 @@ type TestTypeLister interface { // testTypeLister implements the TestTypeLister interface. type testTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*secondexamplev1.TestType] } // NewTestTypeLister returns a new TestTypeLister. func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer. -func (s *testTypeLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TestType)) - }) - return ret, err + return &testTypeLister{listers.New[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype"))} } // TestTypes returns an object that can list and get TestTypes. func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return testTypeNamespaceLister{indexer: s.indexer, namespace: namespace} + return testTypeNamespaceLister{listers.NewNamespaced[*secondexamplev1.TestType](s.ResourceIndexer, namespace)} } // TestTypeNamespaceLister helps list and get TestTypes. @@ -65,36 +57,15 @@ func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { type TestTypeNamespaceLister interface { // List lists all TestTypes in the indexer for a given namespace. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.TestType, err error) + List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) // Get retrieves the TestType from the indexer for a given namespace and name. // Objects returned here must be treated as read-only. - Get(name string) (*v1.TestType, error) + Get(name string) (*secondexamplev1.TestType, error) TestTypeNamespaceListerExpansion } // testTypeNamespaceLister implements the TestTypeNamespaceLister // interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given namespace. -func (s testTypeNamespaceLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given namespace and name. -func (s testTypeNamespaceLister) Get(name string) (*v1.TestType, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("testtype"), name) - } - return obj.(*v1.TestType), nil + listers.ResourceIndexer[*secondexamplev1.TestType] } diff --git a/examples/pkg/kcp/clients/clientset/versioned/clientset.go b/examples/pkg/kcp/clients/clientset/versioned/clientset.go index aa4ccb8f9..3c65faf63 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/clientset.go +++ b/examples/pkg/kcp/clients/clientset/versioned/clientset.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,20 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. -package clientset +package versioned import ( - "fmt" - "net/http" - - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" - - "k8s.io/client-go/discovery" - "k8s.io/client-go/rest" - "k8s.io/client-go/util/flowcontrol" + fmt "fmt" + http "net/http" client "acme.corp/pkg/generated/clientset/versioned" examplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1" @@ -38,36 +28,46 @@ import ( examplev1beta1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1" + + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type ClusterInterface interface { Cluster(logicalcluster.Path) client.Interface Discovery() discovery.DiscoveryInterface - Example3V1() example3v1.Example3V1ClusterInterface ExampleV1() examplev1.ExampleV1ClusterInterface ExampleV1alpha1() examplev1alpha1.ExampleV1alpha1ClusterInterface ExampleV1beta1() examplev1beta1.ExampleV1beta1ClusterInterface ExampleV2() examplev2.ExampleV2ClusterInterface + Example3V1() example3v1.Example3V1ClusterInterface + ExampleDashedV1() exampledashedv1.ExampleDashedV1ClusterInterface ExistinginterfacesV1() existinginterfacesv1.ExistinginterfacesV1ClusterInterface SecondexampleV1() secondexamplev1.SecondexampleV1ClusterInterface } -// ClusterClientset contains the clients for groups. +// ClusterClientset contains the cluster clients for groups. type ClusterClientset struct { *discovery.DiscoveryClient clientCache kcpclient.Cache[*client.Clientset] - example3V1 *example3v1.Example3V1ClusterClient exampleV1 *examplev1.ExampleV1ClusterClient exampleV1alpha1 *examplev1alpha1.ExampleV1alpha1ClusterClient exampleV1beta1 *examplev1beta1.ExampleV1beta1ClusterClient exampleV2 *examplev2.ExampleV2ClusterClient + example3V1 *example3v1.Example3V1ClusterClient + exampleDashedV1 *exampledashedv1.ExampleDashedV1ClusterClient existinginterfacesV1 *existinginterfacesv1.ExistinginterfacesV1ClusterClient secondexampleV1 *secondexamplev1.SecondexampleV1ClusterClient } -// Discovery retrieves the DiscoveryClient +// Discovery retrieves the DiscoveryClient. func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { if c == nil { return nil @@ -75,11 +75,6 @@ func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { return c.DiscoveryClient } -// Example3V1 retrieves the Example3V1ClusterClient. -func (c *ClusterClientset) Example3V1() example3v1.Example3V1ClusterInterface { - return c.example3V1 -} - // ExampleV1 retrieves the ExampleV1ClusterClient. func (c *ClusterClientset) ExampleV1() examplev1.ExampleV1ClusterInterface { return c.exampleV1 @@ -100,6 +95,16 @@ func (c *ClusterClientset) ExampleV2() examplev2.ExampleV2ClusterInterface { return c.exampleV2 } +// Example3V1 retrieves the Example3V1ClusterClient. +func (c *ClusterClientset) Example3V1() example3v1.Example3V1ClusterInterface { + return c.example3V1 +} + +// ExampleDashedV1 retrieves the ExampleDashedV1ClusterClient. +func (c *ClusterClientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1ClusterInterface { + return c.exampleDashedV1 +} + // ExistinginterfacesV1 retrieves the ExistinginterfacesV1ClusterClient. func (c *ClusterClientset) ExistinginterfacesV1() existinginterfacesv1.ExistinginterfacesV1ClusterInterface { return c.existinginterfacesV1 @@ -162,10 +167,6 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli var cs ClusterClientset cs.clientCache = cache var err error - cs.example3V1, err = example3v1.NewForConfigAndClient(&configShallowCopy, httpClient) - if err != nil { - return nil, err - } cs.exampleV1, err = examplev1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err @@ -182,6 +183,14 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli if err != nil { return nil, err } + cs.example3V1, err = example3v1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } + cs.exampleDashedV1, err = exampledashedv1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } cs.existinginterfacesV1, err = existinginterfacesv1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err @@ -207,3 +216,19 @@ func NewForConfigOrDie(c *rest.Config) *ClusterClientset { } return cs } + +// New creates a new ClusterClientset for the given RESTClient. +func New(c *rest.Config) *ClusterClientset { + var cs ClusterClientset + cs.exampleV1 = examplev1.NewForConfigOrDie(c) + cs.exampleV1alpha1 = examplev1alpha1.NewForConfigOrDie(c) + cs.exampleV1beta1 = examplev1beta1.NewForConfigOrDie(c) + cs.exampleV2 = examplev2.NewForConfigOrDie(c) + cs.example3V1 = example3v1.NewForConfigOrDie(c) + cs.exampleDashedV1 = exampledashedv1.NewForConfigOrDie(c) + cs.existinginterfacesV1 = existinginterfacesv1.NewForConfigOrDie(c) + cs.secondexampleV1 = secondexamplev1.NewForConfigOrDie(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) + return &cs +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go b/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go index 0ee45174b..5c3ee839f 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go +++ b/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,69 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcpfakediscovery "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/discovery/fake" - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/client-go/discovery" - - client "acme.corp/pkg/generated/clientset/versioned" - clientscheme "acme.corp/pkg/generated/clientset/versioned/scheme" + applyconfigurations "acme.corp/pkg/generated/applyconfigurations" + clientset "acme.corp/pkg/generated/clientset/versioned" examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" - kcpclient "acme.corp/pkg/kcp/clients/clientset/versioned" + kcpclientset "acme.corp/pkg/kcp/clients/clientset/versioned" + kcpclientscheme "acme.corp/pkg/kcp/clients/clientset/versioned/scheme" kcpexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1" - fakeexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake" + kcpfakeexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake" kcpexamplev1alpha1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1" - fakeexamplev1alpha1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake" + kcpfakeexamplev1alpha1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake" kcpexamplev1beta1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1" - fakeexamplev1beta1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake" + kcpfakeexamplev1beta1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake" kcpexamplev2 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v2" - fakeexamplev2 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake" + kcpfakeexamplev2 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake" kcpexample3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1" - fakeexample3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake" + kcpfakeexample3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake" + kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" + kcpfakeexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake" kcpexistinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1" - fakeexistinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake" + kcpfakeexistinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake" kcpsecondexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1" - fakesecondexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake" + kcpfakesecondexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake" + + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/discovery" + + kcpfakediscovery "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/discovery/fake" + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) // NewSimpleClientset returns a clientset that will respond with the provided objects. // It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement +// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement // for a real clientset and is mostly useful in simple unit tests. +// +// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves +// server side apply testing. NewClientset is only available when apply configurations are generated (e.g. +// via --with-applyconfig). func NewSimpleClientset(objects ...runtime.Object) *ClusterClientset { - o := kcptesting.NewObjectTracker(clientscheme.Scheme, clientscheme.Codecs.UniversalDecoder()) + o := kcptesting.NewObjectTracker(kcpclientscheme.Scheme, kcpclientscheme.Codecs.UniversalDecoder()) o.AddAll(objects...) - cs := &ClusterClientset{Fake: &kcptesting.Fake{}, tracker: o} - cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: cs.Fake, ClusterPath: logicalcluster.Wildcard} + cs := &ClusterClientset{Fake: kcptesting.Fake{}, tracker: o} + cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: &cs.Fake, ClusterPath: logicalcluster.Wildcard} cs.AddReactor("*", "*", kcptesting.ObjectReaction(o)) cs.AddWatchReactor("*", kcptesting.WatchReaction(o)) return cs } -var _ kcpclient.ClusterInterface = (*ClusterClientset)(nil) - // ClusterClientset contains the clients for groups. type ClusterClientset struct { - *kcptesting.Fake + kcptesting.Fake discovery *kcpfakediscovery.FakeDiscovery tracker kcptesting.ObjectTracker } +var _ kcpclientset.ClusterInterface = (*ClusterClientset)(nil) + // Discovery retrieves the DiscoveryClient func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { return c.discovery @@ -89,57 +94,62 @@ func (c *ClusterClientset) Tracker() kcptesting.ObjectTracker { return c.tracker } -// Example3V1 retrieves the Example3V1ClusterClient. -func (c *ClusterClientset) Example3V1() kcpexample3v1.Example3V1ClusterInterface { - return &fakeexample3v1.Example3V1ClusterClient{Fake: c.Fake} +// Cluster scopes this clientset to one cluster. +func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) clientset.Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &Clientset{ + Fake: &c.Fake, + discovery: &kcpfakediscovery.FakeDiscovery{Fake: &c.Fake, ClusterPath: clusterPath}, + tracker: c.tracker.Cluster(clusterPath), + clusterPath: clusterPath, + } } -// ExampleV1 retrieves the ExampleV1ClusterClient. +// ExampleV1 retrieves the ExampleV1ClusterClient func (c *ClusterClientset) ExampleV1() kcpexamplev1.ExampleV1ClusterInterface { - return &fakeexamplev1.ExampleV1ClusterClient{Fake: c.Fake} + return &kcpfakeexamplev1.ExampleV1ClusterClient{Fake: &c.Fake} } -// ExampleV1alpha1 retrieves the ExampleV1alpha1ClusterClient. +// ExampleV1alpha1 retrieves the ExampleV1alpha1ClusterClient func (c *ClusterClientset) ExampleV1alpha1() kcpexamplev1alpha1.ExampleV1alpha1ClusterInterface { - return &fakeexamplev1alpha1.ExampleV1alpha1ClusterClient{Fake: c.Fake} + return &kcpfakeexamplev1alpha1.ExampleV1alpha1ClusterClient{Fake: &c.Fake} } -// ExampleV1beta1 retrieves the ExampleV1beta1ClusterClient. +// ExampleV1beta1 retrieves the ExampleV1beta1ClusterClient func (c *ClusterClientset) ExampleV1beta1() kcpexamplev1beta1.ExampleV1beta1ClusterInterface { - return &fakeexamplev1beta1.ExampleV1beta1ClusterClient{Fake: c.Fake} + return &kcpfakeexamplev1beta1.ExampleV1beta1ClusterClient{Fake: &c.Fake} } -// ExampleV2 retrieves the ExampleV2ClusterClient. +// ExampleV2 retrieves the ExampleV2ClusterClient func (c *ClusterClientset) ExampleV2() kcpexamplev2.ExampleV2ClusterInterface { - return &fakeexamplev2.ExampleV2ClusterClient{Fake: c.Fake} + return &kcpfakeexamplev2.ExampleV2ClusterClient{Fake: &c.Fake} } -// ExistinginterfacesV1 retrieves the ExistinginterfacesV1ClusterClient. -func (c *ClusterClientset) ExistinginterfacesV1() kcpexistinginterfacesv1.ExistinginterfacesV1ClusterInterface { - return &fakeexistinginterfacesv1.ExistinginterfacesV1ClusterClient{Fake: c.Fake} +// Example3V1 retrieves the Example3V1ClusterClient +func (c *ClusterClientset) Example3V1() kcpexample3v1.Example3V1ClusterInterface { + return &kcpfakeexample3v1.Example3V1ClusterClient{Fake: &c.Fake} } -// SecondexampleV1 retrieves the SecondexampleV1ClusterClient. -func (c *ClusterClientset) SecondexampleV1() kcpsecondexamplev1.SecondexampleV1ClusterInterface { - return &fakesecondexamplev1.SecondexampleV1ClusterClient{Fake: c.Fake} +// ExampleDashedV1 retrieves the ExampleDashedV1ClusterClient +func (c *ClusterClientset) ExampleDashedV1() kcpexampledashedv1.ExampleDashedV1ClusterInterface { + return &kcpfakeexampledashedv1.ExampleDashedV1ClusterClient{Fake: &c.Fake} } -// Cluster scopes this clientset to one cluster. -func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - return &Clientset{ - Fake: c.Fake, - discovery: &kcpfakediscovery.FakeDiscovery{Fake: c.Fake, ClusterPath: clusterPath}, - tracker: c.tracker.Cluster(clusterPath), - clusterPath: clusterPath, - } +// ExistinginterfacesV1 retrieves the ExistinginterfacesV1ClusterClient +func (c *ClusterClientset) ExistinginterfacesV1() kcpexistinginterfacesv1.ExistinginterfacesV1ClusterInterface { + return &kcpfakeexistinginterfacesv1.ExistinginterfacesV1ClusterClient{Fake: &c.Fake} } -var _ client.Interface = (*Clientset)(nil) +// SecondexampleV1 retrieves the SecondexampleV1ClusterClient +func (c *ClusterClientset) SecondexampleV1() kcpsecondexamplev1.SecondexampleV1ClusterInterface { + return &kcpfakesecondexamplev1.SecondexampleV1ClusterClient{Fake: &c.Fake} +} -// Clientset contains the clients for groups. +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. type Clientset struct { *kcptesting.Fake discovery *kcpfakediscovery.FakeDiscovery @@ -147,7 +157,11 @@ type Clientset struct { clusterPath logicalcluster.Path } -// Discovery retrieves the DiscoveryClient +var ( + _ clientset.Interface = &Clientset{} + _ kcptesting.FakeScopedClient = &Clientset{} +) + func (c *Clientset) Discovery() discovery.DiscoveryInterface { return c.discovery } @@ -156,37 +170,62 @@ func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { return c.tracker } -// Example3V1 retrieves the Example3V1Client. -func (c *Clientset) Example3V1() example3v1.Example3V1Interface { - return &fakeexample3v1.Example3V1Client{Fake: c.Fake, ClusterPath: c.clusterPath} +// NewClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewClientset(objects ...runtime.Object) *ClusterClientset { + o := kcptesting.NewFieldManagedObjectTracker( + kcpclientscheme.Scheme, + kcpclientscheme.Codecs.UniversalDecoder(), + applyconfigurations.NewTypeConverter(kcpclientscheme.Scheme), + ) + o.AddAll(objects...) + + cs := &ClusterClientset{Fake: kcptesting.Fake{}, tracker: o} + cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: &cs.Fake, ClusterPath: logicalcluster.Wildcard} + cs.AddReactor("*", "*", kcptesting.ObjectReaction(o)) + cs.AddWatchReactor("*", kcptesting.WatchReaction(o)) + + return cs } -// ExampleV1 retrieves the ExampleV1Client. +// ExampleV1 retrieves the ExampleV1Client func (c *Clientset) ExampleV1() examplev1.ExampleV1Interface { - return &fakeexamplev1.ExampleV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} + return &kcpfakeexamplev1.ExampleV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } -// ExampleV1alpha1 retrieves the ExampleV1alpha1Client. +// ExampleV1alpha1 retrieves the ExampleV1alpha1Client func (c *Clientset) ExampleV1alpha1() examplev1alpha1.ExampleV1alpha1Interface { - return &fakeexamplev1alpha1.ExampleV1alpha1Client{Fake: c.Fake, ClusterPath: c.clusterPath} + return &kcpfakeexamplev1alpha1.ExampleV1alpha1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } -// ExampleV1beta1 retrieves the ExampleV1beta1Client. +// ExampleV1beta1 retrieves the ExampleV1beta1Client func (c *Clientset) ExampleV1beta1() examplev1beta1.ExampleV1beta1Interface { - return &fakeexamplev1beta1.ExampleV1beta1Client{Fake: c.Fake, ClusterPath: c.clusterPath} + return &kcpfakeexamplev1beta1.ExampleV1beta1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } -// ExampleV2 retrieves the ExampleV2Client. +// ExampleV2 retrieves the ExampleV2Client func (c *Clientset) ExampleV2() examplev2.ExampleV2Interface { - return &fakeexamplev2.ExampleV2Client{Fake: c.Fake, ClusterPath: c.clusterPath} + return &kcpfakeexamplev2.ExampleV2Client{Fake: c.Fake, ClusterPath: c.clusterPath} +} + +// Example3V1 retrieves the Example3V1Client +func (c *Clientset) Example3V1() example3v1.Example3V1Interface { + return &kcpfakeexample3v1.Example3V1Client{Fake: c.Fake, ClusterPath: c.clusterPath} +} + +// ExampleDashedV1 retrieves the ExampleDashedV1Client +func (c *Clientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1Interface { + return &kcpfakeexampledashedv1.ExampleDashedV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } -// ExistinginterfacesV1 retrieves the ExistinginterfacesV1Client. +// ExistinginterfacesV1 retrieves the ExistinginterfacesV1Client func (c *Clientset) ExistinginterfacesV1() existinginterfacesv1.ExistinginterfacesV1Interface { - return &fakeexistinginterfacesv1.ExistinginterfacesV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} + return &kcpfakeexistinginterfacesv1.ExistinginterfacesV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } -// SecondexampleV1 retrieves the SecondexampleV1Client. +// SecondexampleV1 retrieves the SecondexampleV1Client func (c *Clientset) SecondexampleV1() secondexamplev1.SecondexampleV1Interface { - return &fakesecondexamplev1.SecondexampleV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} + return &kcpfakesecondexamplev1.SecondexampleV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } diff --git a/examples/pkg/kcp/clients/clientset/versioned/fake/doc.go b/examples/pkg/kcp/clients/clientset/versioned/fake/doc.go new file mode 100644 index 000000000..95b1bc650 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated fake clientset. +package fake diff --git a/examples/pkg/kcp/clients/clientset/versioned/fake/register.go b/examples/pkg/kcp/clients/clientset/versioned/fake/register.go new file mode 100644 index 000000000..7d674fea4 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/fake/register.go @@ -0,0 +1,71 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package fake + +import ( + examplev1 "acme.corp/pkg/apis/example/v1" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + examplev2 "acme.corp/pkg/apis/example/v2" + example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) + +var localSchemeBuilder = runtime.SchemeBuilder{ + examplev1.AddToScheme, + examplev1alpha1.AddToScheme, + examplev1beta1.AddToScheme, + examplev2.AddToScheme, + example3v1.AddToScheme, + exampledashedv1.AddToScheme, + existinginterfacesv1.AddToScheme, + secondexamplev1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(scheme)) +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/scheme/doc.go b/examples/pkg/kcp/clients/clientset/versioned/scheme/doc.go new file mode 100644 index 000000000..928f59990 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/scheme/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go b/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go index 2a57d2e75..203e3b2d6 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go +++ b/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,35 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package scheme import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/runtime/serializer" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - examplev1 "acme.corp/pkg/apis/example/v1" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" ) var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - example3v1.AddToScheme, examplev1.AddToScheme, examplev1alpha1.AddToScheme, examplev1beta1.AddToScheme, examplev2.AddToScheme, + example3v1.AddToScheme, + exampledashedv1.AddToScheme, existinginterfacesv1.AddToScheme, secondexamplev1.AddToScheme, } @@ -67,6 +66,6 @@ var localSchemeBuilder = runtime.SchemeBuilder{ var AddToScheme = localSchemeBuilder.AddToScheme func init() { - metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) utilruntime.Must(AddToScheme(Scheme)) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/clustertesttype.go index e11f623f4..47ed6e3e6 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - examplev1 "acme.corp/pkg/apis/example/v1" - examplev1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a examplev1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a examplev1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) examplev1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*examplev1.ClusterTestTypeList, error) + Cluster(logicalcluster.Path) examplev1.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*apisexamplev1.ClusterTestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1client.ExampleV1Client] + clientCache kcpclient.Cache[*examplev1.ExampleV1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev1client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev1.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,7 +60,7 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*examplev1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*apisexamplev1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/doc.go new file mode 100644 index 000000000..dc2c8e634 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/example_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/example_client.go index e1ef8111c..7b447da1f 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/example_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,25 +14,27 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + scheme "acme.corp/pkg/kcp/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type ExampleV1ClusterInterface interface { ExampleV1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter WithoutVerbTypesClusterGetter } @@ -43,6 +42,7 @@ type ExampleV1ClusterScoper interface { Cluster(logicalcluster.Path) examplev1.ExampleV1Interface } +// ExampleV1ClusterClient is used to interact with features provided by the example.dev group. type ExampleV1ClusterClient struct { clientCache kcpclient.Cache[*examplev1.ExampleV1Client] } @@ -54,14 +54,14 @@ func (c *ExampleV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampl return c.clientCache.ClusterOrDie(clusterPath) } -func (c *ExampleV1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *ExampleV1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *ExampleV1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + func (c *ExampleV1ClusterClient) WithoutVerbTypes() WithoutVerbTypeClusterInterface { return &withoutVerbTypesClusterInterface{clientCache: c.clientCache} } @@ -70,11 +70,13 @@ func (c *ExampleV1ClusterClient) WithoutVerbTypes() WithoutVerbTypeClusterInterf // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExampleV1ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new ExampleV1ClusterClient for the given config and http client. @@ -86,6 +88,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV1ClusterCli if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &ExampleV1ClusterClient{clientCache: cache}, nil } @@ -98,3 +101,14 @@ func NewForConfigOrDie(c *rest.Config) *ExampleV1ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apisexamplev1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/clustertesttype.go index 225988045..60bc87548 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev1 "acme.corp/pkg/apis/example/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/example/v1" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + typedkcpexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - examplev1 "acme.corp/pkg/apis/example/v1" - applyconfigurationsexamplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" - examplev1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) examplev1client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &examplev1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1.ClusterTestTypeList{ListMeta: obj.(*examplev1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *ExampleV1ClusterClient) typedkcpexamplev1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList]( + fake.Fake, + examplev1.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev1.ClusterTestType { return &examplev1.ClusterTestType{} }, + func() *examplev1.ClusterTestTypeList { return &examplev1.ClusterTestTypeList{} }, + func(dst, src *examplev1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1.ClusterTestTypeList) []*examplev1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1.ClusterTestTypeList, items []*examplev1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexamplev1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *examplev1.ClusterTestType, opts metav1.CreateOptions) (*examplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *examplev1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *examplev1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &examplev1.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &examplev1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1.ClusterTestTypeList{ListMeta: obj.(*examplev1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexamplev1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + examplev1.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev1.ClusterTestType { return &examplev1.ClusterTestType{} }, + func() *examplev1.ClusterTestTypeList { return &examplev1.ClusterTestTypeList{} }, + func(dst, src *examplev1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1.ClusterTestTypeList) []*examplev1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1.ClusterTestTypeList, items []*examplev1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev1.ClusterTestType), err } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/example_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/example_client.go index 4d17ddb58..e67ee2d71 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/example_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" kcpexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpexamplev1.ExampleV1ClusterInterface = (*ExampleV1ClusterClient)(nil) @@ -44,38 +41,38 @@ func (c *ExampleV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampl return &ExampleV1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *ExampleV1ClusterClient) TestTypes() kcpexamplev1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} +func (c *ExampleV1ClusterClient) ClusterTestTypes() kcpexamplev1.ClusterTestTypeClusterInterface { + return newFakeClusterTestTypeClusterClient(c) } -func (c *ExampleV1ClusterClient) ClusterTestTypes() kcpexamplev1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} +func (c *ExampleV1ClusterClient) TestTypes() kcpexamplev1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) } func (c *ExampleV1ClusterClient) WithoutVerbTypes() kcpexamplev1.WithoutVerbTypeClusterInterface { - return &withoutVerbTypesClusterClient{Fake: c.Fake} + return newFakeWithoutVerbTypeClusterClient(c) } -var _ examplev1.ExampleV1Interface = (*ExampleV1Client)(nil) - type ExampleV1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *ExampleV1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *ExampleV1Client) ClusterTestTypes() examplev1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *ExampleV1Client) TestTypes(namespace string) examplev1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExampleV1Client) ClusterTestTypes() examplev1.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +func (c *ExampleV1Client) WithoutVerbTypes(namespace string) examplev1.WithoutVerbTypeInterface { + return newFakeWithoutVerbTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExampleV1Client) WithoutVerbTypes(namespace string) examplev1.WithoutVerbTypeInterface { - return &withoutVerbTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExampleV1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/testtype.go index 7225b9188..d9ac537b9 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,221 +14,116 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" + context "context" - "github.com/kcp-dev/logicalcluster/v3" + examplev1 "acme.corp/pkg/apis/example/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/example/v1" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + typedkcpexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1" - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - examplev1 "acme.corp/pkg/apis/example/v1" - applyconfigurationsexamplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" - examplev1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" - kcpexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) -var testTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1.TestType, *examplev1.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexamplev1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. -func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &examplev1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1.TestTypeList{ListMeta: obj.(*examplev1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeTestTypeClusterClient(fake *ExampleV1ClusterClient) typedkcpexamplev1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev1.TestType, *examplev1.TestTypeList]( + fake.Fake, + examplev1.SchemeGroupVersion.WithResource("testtypes"), + examplev1.SchemeGroupVersion.WithKind("TestType"), + func() *examplev1.TestType { return &examplev1.TestType{} }, + func() *examplev1.TestTypeList { return &examplev1.TestTypeList{} }, + func(dst, src *examplev1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1.TestTypeList) []*examplev1.TestType { return kcpgentype.ToPointerSlice(list.Items) }, + func(list *examplev1.TestTypeList, items []*examplev1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested TestTypes across all clusters. -func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexamplev1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -type testTypesNamespacer struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexamplev1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1.TestType, *examplev1.TestTypeList, *v1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *examplev1.TestType, opts metav1.CreateOptions) (*examplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *examplev1.TestType, opts metav1.UpdateOptions) (*examplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *examplev1.TestType, opts metav1.UpdateOptions) (*examplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &examplev1.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &examplev1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1.TestTypeList{ListMeta: obj.(*examplev1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err } -func (c *testTypesClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (*examplev1.Field, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(testTypesResource, c.ClusterPath, testTypeName, "field", c.Namespace, field), &examplev1.Field{}) +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexamplev1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev1.TestType, *examplev1.TestTypeList, *v1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + examplev1.SchemeGroupVersion.WithResource("testtypes"), + examplev1.SchemeGroupVersion.WithKind("TestType"), + func() *examplev1.TestType { return &examplev1.TestType{} }, + func() *examplev1.TestTypeList { return &examplev1.TestTypeList{} }, + func(dst, src *examplev1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1.TestTypeList) []*examplev1.TestType { return kcpgentype.ToPointerSlice(list.Items) }, + func(list *examplev1.TestTypeList, items []*examplev1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, + } +} + +// CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypeScopedClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, _ metav1.CreateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(c.Resource(), c.ClusterPath, testTypeName, "field", c.Namespace(), field), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } -func (c *testTypesClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (*examplev1.Field, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, field), &examplev1.Field{}) +// UpdateField takes the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypeScopedClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, _ metav1.UpdateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(c.Resource(), c.ClusterPath, "field", c.Namespace(), field), &examplev1.Field{}) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } -func (c *testTypesClient) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*examplev1.Field, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, testTypeName), &examplev1.Field{}) +// GetField takes name of the testType, and returns the corresponding field object, and an error if there is any. +func (c *testTypeScopedClient) GetField(ctx context.Context, testTypeName string, _ metav1.GetOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(c.Resource(), c.ClusterPath, c.Namespace(), "field", testTypeName), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/withoutverbtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/withoutverbtype.go index 583dd9c06..09e5a86a1 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/withoutverbtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake/withoutverbtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,47 +14,69 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" + examplev1 "acme.corp/pkg/apis/example/v1" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + typedkcpexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/apimachinery/pkg/runtime/schema" - - examplev1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" - kcpexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var withoutVerbTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1", Resource: "withoutverbtypes"} -var withoutVerbTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1", Kind: "WithoutVerbType"} - -type withoutVerbTypesClusterClient struct { - *kcptesting.Fake +// withoutVerbTypeClusterClient implements WithoutVerbTypeClusterInterface +type withoutVerbTypeClusterClient struct { + *kcpgentype.FakeClusterClient[*examplev1.WithoutVerbType] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *withoutVerbTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexamplev1.WithoutVerbTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +func newFakeWithoutVerbTypeClusterClient(fake *ExampleV1ClusterClient) typedkcpexamplev1.WithoutVerbTypeClusterInterface { + return &withoutVerbTypeClusterClient{ + kcpgentype.NewFakeClusterClient[*examplev1.WithoutVerbType]( + fake.Fake, + examplev1.SchemeGroupVersion.WithResource("withoutverbtypes"), + examplev1.SchemeGroupVersion.WithKind("WithoutVerbType"), + func() *examplev1.WithoutVerbType { return &examplev1.WithoutVerbType{} }, + ), + fake.Fake, } +} - return &withoutVerbTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +func (c *withoutVerbTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexamplev1.WithoutVerbTypesNamespacer { + return &withoutVerbTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -type withoutVerbTypesNamespacer struct { +type withoutVerbTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *withoutVerbTypesNamespacer) Namespace(namespace string) examplev1client.WithoutVerbTypeInterface { - return &withoutVerbTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *withoutVerbTypeNamespacer) Namespace(namespace string) typedexamplev1.WithoutVerbTypeInterface { + return newFakeWithoutVerbTypeClient(n.Fake, namespace, n.ClusterPath) } -type withoutVerbTypesClient struct { - *kcptesting.Fake +// withoutVerbTypeScopedClient implements WithoutVerbTypeInterface +type withoutVerbTypeScopedClient struct { + *kcpgentype.FakeClient[*examplev1.WithoutVerbType] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string +} + +func newFakeWithoutVerbTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexamplev1.WithoutVerbTypeInterface { + return &withoutVerbTypeScopedClient{ + kcpgentype.NewFakeClient[*examplev1.WithoutVerbType]( + fake, + clusterPath, + namespace, + examplev1.SchemeGroupVersion.WithResource("withoutverbtypes"), + examplev1.SchemeGroupVersion.WithKind("WithoutVerbType"), + func() *examplev1.WithoutVerbType { return &examplev1.WithoutVerbType{} }, + ), + fake, + clusterPath, + } } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1/testtype_expansion.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/generated_expansion.go similarity index 68% rename from examples/pkg/kcpexisting/clients/listers/example/v1/testtype_expansion.go rename to examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/generated_expansion.go index 835da85d6..1a36817ad 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1/testtype_expansion.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/generated_expansion.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,9 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 -// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. -type TestTypeClusterListerExpansion interface{} +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} + +type WithoutVerbTypeClusterExpansion interface{} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/testtype.go index c8776540b..42521942e 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + examplev1 "acme.corp/pkg/apis/example/v1" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - examplev1 "acme.corp/pkg/apis/example/v1" - examplev1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -46,10 +43,11 @@ type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer List(ctx context.Context, opts metav1.ListOptions) (*examplev1.TestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1client.ExampleV1Client] + clientCache kcpclient.Cache[*typedexamplev1.ExampleV1Client] } // Cluster scopes the client down to a particular cluster. @@ -71,16 +69,16 @@ func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListO return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) } -// TestTypesNamespacer can scope to objects within a namespace, returning a examplev1client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexamplev1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) examplev1client.TestTypeInterface + Namespace(string) typedexamplev1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*examplev1client.ExampleV1Client] + clientCache kcpclient.Cache[*typedexamplev1.ExampleV1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev1client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedexamplev1.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/withoutverbtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/withoutverbtype.go index b4d4329bd..e17b7629c 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/withoutverbtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1/withoutverbtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( + examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" "github.com/kcp-dev/logicalcluster/v3" - - examplev1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" ) // WithoutVerbTypesClusterGetter has a method to return a WithoutVerbTypeClusterInterface. @@ -37,10 +34,12 @@ type WithoutVerbTypesClusterGetter interface { // WithoutVerbTypeClusterInterface can scope down to one cluster and return a WithoutVerbTypesNamespacer. type WithoutVerbTypeClusterInterface interface { Cluster(logicalcluster.Path) WithoutVerbTypesNamespacer + + WithoutVerbTypeClusterExpansion } type withoutVerbTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1client.ExampleV1Client] + clientCache kcpclient.Cache[*examplev1.ExampleV1Client] } // Cluster scopes the client down to a particular cluster. @@ -52,16 +51,16 @@ func (c *withoutVerbTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa return &withoutVerbTypesNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} } -// WithoutVerbTypesNamespacer can scope to objects within a namespace, returning a examplev1client.WithoutVerbTypeInterface. +// WithoutVerbTypesNamespacer can scope to objects within a namespace, returning a examplev1.WithoutVerbTypeInterface. type WithoutVerbTypesNamespacer interface { - Namespace(string) examplev1client.WithoutVerbTypeInterface + Namespace(string) examplev1.WithoutVerbTypeInterface } type withoutVerbTypesNamespacer struct { - clientCache kcpclient.Cache[*examplev1client.ExampleV1Client] + clientCache kcpclient.Cache[*examplev1.ExampleV1Client] clusterPath logicalcluster.Path } -func (n *withoutVerbTypesNamespacer) Namespace(namespace string) examplev1client.WithoutVerbTypeInterface { +func (n *withoutVerbTypesNamespacer) Namespace(namespace string) examplev1.WithoutVerbTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).WithoutVerbTypes(namespace) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/clustertesttype.go index c0f2bba07..b426fa385 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1alpha1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - examplev1alpha1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a examplev1alpha1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a examplev1alpha1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) examplev1alpha1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.ClusterTestTypeList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Cluster(logicalcluster.Path) examplev1alpha1.ClusterTestTypeInterface + List(ctx context.Context, opts v1.ListOptions) (*apisexamplev1alpha1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1alpha1client.ExampleV1alpha1Client] + clientCache kcpclient.Cache[*examplev1alpha1.ExampleV1alpha1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev1alpha1client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev1alpha1.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,11 +60,11 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts v1.ListOptions) (*apisexamplev1alpha1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } // Watch begins to watch all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { +func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().Watch(ctx, opts) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/doc.go new file mode 100644 index 000000000..ca5a1c141 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1alpha1 diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/example_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/example_client.go index e45f76c49..060006f01 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/example_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1alpha1 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + scheme "acme.corp/pkg/kcp/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type ExampleV1alpha1ClusterInterface interface { ExampleV1alpha1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter } type ExampleV1alpha1ClusterScoper interface { Cluster(logicalcluster.Path) examplev1alpha1.ExampleV1alpha1Interface } +// ExampleV1alpha1ClusterClient is used to interact with features provided by the example.dev group. type ExampleV1alpha1ClusterClient struct { clientCache kcpclient.Cache[*examplev1alpha1.ExampleV1alpha1Client] } @@ -53,23 +53,25 @@ func (c *ExampleV1alpha1ClusterClient) Cluster(clusterPath logicalcluster.Path) return c.clientCache.ClusterOrDie(clusterPath) } -func (c *ExampleV1alpha1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *ExampleV1alpha1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *ExampleV1alpha1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new ExampleV1alpha1ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExampleV1alpha1ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new ExampleV1alpha1ClusterClient for the given config and http client. @@ -81,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV1alpha1Clus if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &ExampleV1alpha1ClusterClient{clientCache: cache}, nil } @@ -93,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *ExampleV1alpha1ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apisexamplev1alpha1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/clustertesttype.go index e28612369..1083415f3 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + v1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" + typedexamplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + typedkcpexamplev1alpha1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - applyconfigurationsexamplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" - examplev1alpha1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1alpha1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1alpha1", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) examplev1alpha1client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &examplev1alpha1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1alpha1.ClusterTestTypeList{ListMeta: obj.(*examplev1alpha1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1alpha1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *ExampleV1alpha1ClusterClient) typedkcpexamplev1alpha1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList]( + fake.Fake, + examplev1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev1alpha1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev1alpha1.ClusterTestType { return &examplev1alpha1.ClusterTestType{} }, + func() *examplev1alpha1.ClusterTestTypeList { return &examplev1alpha1.ClusterTestTypeList{} }, + func(dst, src *examplev1alpha1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1alpha1.ClusterTestTypeList) []*examplev1alpha1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1alpha1.ClusterTestTypeList, items []*examplev1alpha1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexamplev1alpha1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList, *v1alpha1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *examplev1alpha1.ClusterTestType, opts metav1.CreateOptions) (*examplev1alpha1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *examplev1alpha1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1alpha1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *examplev1alpha1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1alpha1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &examplev1alpha1.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1alpha1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev1alpha1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &examplev1alpha1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1alpha1.ClusterTestTypeList{ListMeta: obj.(*examplev1alpha1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1alpha1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev1alpha1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1alpha1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1alpha1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1alpha1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1alpha1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexamplev1alpha1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList, *v1alpha1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + examplev1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev1alpha1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev1alpha1.ClusterTestType { return &examplev1alpha1.ClusterTestType{} }, + func() *examplev1alpha1.ClusterTestTypeList { return &examplev1alpha1.ClusterTestTypeList{} }, + func(dst, src *examplev1alpha1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1alpha1.ClusterTestTypeList) []*examplev1alpha1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1alpha1.ClusterTestTypeList, items []*examplev1alpha1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev1alpha1.ClusterTestType), err } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/example_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/example_client.go index dfe8f2c45..3f49c05b4 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/example_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" kcpexamplev1alpha1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpexamplev1alpha1.ExampleV1alpha1ClusterInterface = (*ExampleV1alpha1ClusterClient)(nil) @@ -44,30 +41,30 @@ func (c *ExampleV1alpha1ClusterClient) Cluster(clusterPath logicalcluster.Path) return &ExampleV1alpha1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *ExampleV1alpha1ClusterClient) TestTypes() kcpexamplev1alpha1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *ExampleV1alpha1ClusterClient) ClusterTestTypes() kcpexamplev1alpha1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ examplev1alpha1.ExampleV1alpha1Interface = (*ExampleV1alpha1Client)(nil) +func (c *ExampleV1alpha1ClusterClient) TestTypes() kcpexamplev1alpha1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type ExampleV1alpha1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *ExampleV1alpha1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *ExampleV1alpha1Client) ClusterTestTypes() examplev1alpha1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *ExampleV1alpha1Client) TestTypes(namespace string) examplev1alpha1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExampleV1alpha1Client) ClusterTestTypes() examplev1alpha1.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExampleV1alpha1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/testtype.go index 0fabc3f82..07b5abbe2 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,197 +14,86 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + v1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" + typedexamplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + typedkcpexamplev1alpha1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - applyconfigurationsexamplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" - examplev1alpha1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" - kcpexamplev1alpha1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1" + "github.com/kcp-dev/logicalcluster/v3" ) -var testTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1alpha1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1alpha1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexamplev1alpha1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +func newFakeTestTypeClusterClient(fake *ExampleV1alpha1ClusterClient) typedkcpexamplev1alpha1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList]( + fake.Fake, + examplev1alpha1.SchemeGroupVersion.WithResource("testtypes"), + examplev1alpha1.SchemeGroupVersion.WithKind("TestType"), + func() *examplev1alpha1.TestType { return &examplev1alpha1.TestType{} }, + func() *examplev1alpha1.TestTypeList { return &examplev1alpha1.TestTypeList{} }, + func(dst, src *examplev1alpha1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1alpha1.TestTypeList) []*examplev1alpha1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1alpha1.TestTypeList, items []*examplev1alpha1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. -func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &examplev1alpha1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1alpha1.TestTypeList{ListMeta: obj.(*examplev1alpha1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1alpha1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexamplev1alpha1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -// Watch returns a watch.Interface that watches the requested TestTypes across all clusters. -func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) -} - -type testTypesNamespacer struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev1alpha1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexamplev1alpha1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList, *v1alpha1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *examplev1alpha1.TestType, opts metav1.CreateOptions) (*examplev1alpha1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *examplev1alpha1.TestType, opts metav1.UpdateOptions) (*examplev1alpha1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *examplev1alpha1.TestType, opts metav1.UpdateOptions) (*examplev1alpha1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &examplev1alpha1.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1alpha1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev1alpha1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.TestType), err } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &examplev1alpha1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1alpha1.TestTypeList{ListMeta: obj.(*examplev1alpha1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1alpha1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev1alpha1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1alpha1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1alpha1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1alpha1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1alpha1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexamplev1alpha1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList, *v1alpha1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + examplev1alpha1.SchemeGroupVersion.WithResource("testtypes"), + examplev1alpha1.SchemeGroupVersion.WithKind("TestType"), + func() *examplev1alpha1.TestType { return &examplev1alpha1.TestType{} }, + func() *examplev1alpha1.TestTypeList { return &examplev1alpha1.TestTypeList{} }, + func(dst, src *examplev1alpha1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1alpha1.TestTypeList) []*examplev1alpha1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1alpha1.TestTypeList, items []*examplev1alpha1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev1alpha1.TestType), err } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype_expansion.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/generated_expansion.go similarity index 68% rename from examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype_expansion.go rename to examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/generated_expansion.go index be863ecd0..c17c3f326 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype_expansion.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/generated_expansion.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,9 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1alpha1 -// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. -type TestTypeClusterListerExpansion interface{} +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/testtype.go index f181d3aab..ca4bc2048 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1alpha1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + typedexamplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - examplev1alpha1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -44,12 +41,13 @@ type TestTypesClusterGetter interface { // or scope down to one cluster and return a TestTypesNamespacer. type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer - List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.TestTypeList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + List(ctx context.Context, opts v1.ListOptions) (*examplev1alpha1.TestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1alpha1client.ExampleV1alpha1Client] + clientCache kcpclient.Cache[*typedexamplev1alpha1.ExampleV1alpha1Client] } // Cluster scopes the client down to a particular cluster. @@ -62,25 +60,25 @@ func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) Tes } // List returns the entire collection of all TestTypes across all clusters. -func (c *testTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.TestTypeList, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).List(ctx, opts) +func (c *testTypesClusterInterface) List(ctx context.Context, opts v1.ListOptions) (*examplev1alpha1.TestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(v1.NamespaceAll).List(ctx, opts) } // Watch begins to watch all TestTypes across all clusters. -func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) +func (c *testTypesClusterInterface) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(v1.NamespaceAll).Watch(ctx, opts) } -// TestTypesNamespacer can scope to objects within a namespace, returning a examplev1alpha1client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexamplev1alpha1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) examplev1alpha1client.TestTypeInterface + Namespace(string) typedexamplev1alpha1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*examplev1alpha1client.ExampleV1alpha1Client] + clientCache kcpclient.Cache[*typedexamplev1alpha1.ExampleV1alpha1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev1alpha1client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedexamplev1alpha1.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/clustertesttype.go index ac21c7549..6dd9f85bb 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1beta1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - examplev1beta1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a examplev1beta1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a examplev1beta1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) examplev1beta1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*examplev1beta1.ClusterTestTypeList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Cluster(logicalcluster.Path) examplev1beta1.ClusterTestTypeInterface + List(ctx context.Context, opts v1.ListOptions) (*apisexamplev1beta1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1beta1client.ExampleV1beta1Client] + clientCache kcpclient.Cache[*examplev1beta1.ExampleV1beta1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev1beta1client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev1beta1.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,11 +60,11 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*examplev1beta1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts v1.ListOptions) (*apisexamplev1beta1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } // Watch begins to watch all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { +func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().Watch(ctx, opts) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/doc.go new file mode 100644 index 000000000..e0406a6b9 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1beta1 diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/example_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/example_client.go index 9d720f2bd..faa9e3d8c 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/example_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1beta1 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + scheme "acme.corp/pkg/kcp/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type ExampleV1beta1ClusterInterface interface { ExampleV1beta1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter } type ExampleV1beta1ClusterScoper interface { Cluster(logicalcluster.Path) examplev1beta1.ExampleV1beta1Interface } +// ExampleV1beta1ClusterClient is used to interact with features provided by the example.dev group. type ExampleV1beta1ClusterClient struct { clientCache kcpclient.Cache[*examplev1beta1.ExampleV1beta1Client] } @@ -53,23 +53,25 @@ func (c *ExampleV1beta1ClusterClient) Cluster(clusterPath logicalcluster.Path) e return c.clientCache.ClusterOrDie(clusterPath) } -func (c *ExampleV1beta1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *ExampleV1beta1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *ExampleV1beta1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new ExampleV1beta1ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExampleV1beta1ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new ExampleV1beta1ClusterClient for the given config and http client. @@ -81,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV1beta1Clust if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &ExampleV1beta1ClusterClient{clientCache: cache}, nil } @@ -93,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *ExampleV1beta1ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apisexamplev1beta1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/clustertesttype.go index 898b28710..fc5a78f8b 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + v1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" + typedexamplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + typedkcpexamplev1beta1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - applyconfigurationsexamplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" - examplev1beta1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1beta1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1beta1", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) examplev1beta1client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1beta1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &examplev1beta1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1beta1.ClusterTestTypeList{ListMeta: obj.(*examplev1beta1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1beta1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *ExampleV1beta1ClusterClient) typedkcpexamplev1beta1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList]( + fake.Fake, + examplev1beta1.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev1beta1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev1beta1.ClusterTestType { return &examplev1beta1.ClusterTestType{} }, + func() *examplev1beta1.ClusterTestTypeList { return &examplev1beta1.ClusterTestTypeList{} }, + func(dst, src *examplev1beta1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1beta1.ClusterTestTypeList) []*examplev1beta1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1beta1.ClusterTestTypeList, items []*examplev1beta1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexamplev1beta1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList, *v1beta1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *examplev1beta1.ClusterTestType, opts metav1.CreateOptions) (*examplev1beta1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *examplev1beta1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1beta1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *examplev1beta1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1beta1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &examplev1beta1.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1beta1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev1beta1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1beta1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &examplev1beta1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1beta1.ClusterTestTypeList{ListMeta: obj.(*examplev1beta1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1beta1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev1beta1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1beta1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1beta1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1beta1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1beta1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexamplev1beta1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList, *v1beta1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + examplev1beta1.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev1beta1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev1beta1.ClusterTestType { return &examplev1beta1.ClusterTestType{} }, + func() *examplev1beta1.ClusterTestTypeList { return &examplev1beta1.ClusterTestTypeList{} }, + func(dst, src *examplev1beta1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1beta1.ClusterTestTypeList) []*examplev1beta1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1beta1.ClusterTestTypeList, items []*examplev1beta1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev1beta1.ClusterTestType), err } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/example_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/example_client.go index 740c72a82..32616a228 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/example_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" kcpexamplev1beta1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpexamplev1beta1.ExampleV1beta1ClusterInterface = (*ExampleV1beta1ClusterClient)(nil) @@ -44,30 +41,30 @@ func (c *ExampleV1beta1ClusterClient) Cluster(clusterPath logicalcluster.Path) e return &ExampleV1beta1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *ExampleV1beta1ClusterClient) TestTypes() kcpexamplev1beta1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *ExampleV1beta1ClusterClient) ClusterTestTypes() kcpexamplev1beta1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ examplev1beta1.ExampleV1beta1Interface = (*ExampleV1beta1Client)(nil) +func (c *ExampleV1beta1ClusterClient) TestTypes() kcpexamplev1beta1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type ExampleV1beta1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *ExampleV1beta1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *ExampleV1beta1Client) ClusterTestTypes() examplev1beta1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *ExampleV1beta1Client) TestTypes(namespace string) examplev1beta1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExampleV1beta1Client) ClusterTestTypes() examplev1beta1.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExampleV1beta1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go index 577bc4d7b..ca1bfd3fc 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,145 +14,86 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + v1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" + typedexamplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + typedkcpexamplev1beta1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - applyconfigurationsexamplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" - examplev1beta1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" - kcpexamplev1beta1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1" + "github.com/kcp-dev/logicalcluster/v3" ) -var testTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1beta1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1beta1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1beta1.TestType, *examplev1beta1.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexamplev1beta1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +func newFakeTestTypeClusterClient(fake *ExampleV1beta1ClusterClient) typedkcpexamplev1beta1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev1beta1.TestType, *examplev1beta1.TestTypeList]( + fake.Fake, + examplev1beta1.SchemeGroupVersion.WithResource("testtypes"), + examplev1beta1.SchemeGroupVersion.WithKind("TestType"), + func() *examplev1beta1.TestType { return &examplev1beta1.TestType{} }, + func() *examplev1beta1.TestTypeList { return &examplev1beta1.TestTypeList{} }, + func(dst, src *examplev1beta1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1beta1.TestTypeList) []*examplev1beta1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1beta1.TestTypeList, items []*examplev1beta1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} } -type testTypesNamespacer struct { - *kcptesting.Fake - ClusterPath logicalcluster.Path +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexamplev1beta1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -func (n *testTypesNamespacer) Namespace(namespace string) examplev1beta1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} -} - -type testTypesClient struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *examplev1beta1.TestType, opts metav1.CreateOptions) (*examplev1beta1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *examplev1beta1.TestType, opts metav1.UpdateOptions) (*examplev1beta1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.TestType), err } -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *examplev1beta1.TestType, opts metav1.UpdateOptions) (*examplev1beta1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &examplev1beta1.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1beta1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev1beta1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.TestType), err -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev1beta1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.TestType), err +func (n *testTypeNamespacer) Namespace(namespace string) typedexamplev1beta1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1beta1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1beta1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.TestType), err +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1beta1.TestType, *examplev1beta1.TestTypeList, *v1beta1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake + ClusterPath logicalcluster.Path } -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1beta1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1beta1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexamplev1beta1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev1beta1.TestType, *examplev1beta1.TestTypeList, *v1beta1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + examplev1beta1.SchemeGroupVersion.WithResource("testtypes"), + examplev1beta1.SchemeGroupVersion.WithKind("TestType"), + func() *examplev1beta1.TestType { return &examplev1beta1.TestType{} }, + func() *examplev1beta1.TestTypeList { return &examplev1beta1.TestTypeList{} }, + func(dst, src *examplev1beta1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1beta1.TestTypeList) []*examplev1beta1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1beta1.TestTypeList, items []*examplev1beta1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev1beta1.TestType), err } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/generated_expansion.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/generated_expansion.go new file mode 100644 index 000000000..f6728dd2e --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1beta1 + +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/testtype.go index cfae770e1..e0be63235 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,15 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1beta1 import ( + context "context" + + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + typedexamplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" "github.com/kcp-dev/logicalcluster/v3" - - examplev1beta1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -34,13 +37,17 @@ type TestTypesClusterGetter interface { TestTypes() TestTypeClusterInterface } -// TestTypeClusterInterface can scope down to one cluster and return a TestTypesNamespacer. +// TestTypeClusterInterface can operate on TestTypes across all clusters, +// or scope down to one cluster and return a TestTypesNamespacer. type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer + List(ctx context.Context, opts v1.ListOptions) (*examplev1beta1.TestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1beta1client.ExampleV1beta1Client] + clientCache kcpclient.Cache[*typedexamplev1beta1.ExampleV1beta1Client] } // Cluster scopes the client down to a particular cluster. @@ -52,16 +59,26 @@ func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) Tes return &testTypesNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} } -// TestTypesNamespacer can scope to objects within a namespace, returning a examplev1beta1client.TestTypeInterface. +// List returns the entire collection of all TestTypes across all clusters. +func (c *testTypesClusterInterface) List(ctx context.Context, opts v1.ListOptions) (*examplev1beta1.TestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(v1.NamespaceAll).List(ctx, opts) +} + +// Watch begins to watch all TestTypes across all clusters. +func (c *testTypesClusterInterface) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(v1.NamespaceAll).Watch(ctx, opts) +} + +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexamplev1beta1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) examplev1beta1client.TestTypeInterface + Namespace(string) typedexamplev1beta1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*examplev1beta1client.ExampleV1beta1Client] + clientCache kcpclient.Cache[*typedexamplev1beta1.ExampleV1beta1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev1beta1client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedexamplev1beta1.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/clustertesttype.go index c2bc48817..2960a3925 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v2 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev2 "acme.corp/pkg/apis/example/v2" + examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" - examplev2 "acme.corp/pkg/apis/example/v2" - examplev2client "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a examplev2client.ClusterTestTypeInterface. +// or scope down to one cluster and return a examplev2.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) examplev2client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*examplev2.ClusterTestTypeList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Cluster(logicalcluster.Path) examplev2.ClusterTestTypeInterface + List(ctx context.Context, opts v1.ListOptions) (*apisexamplev2.ClusterTestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev2client.ExampleV2Client] + clientCache kcpclient.Cache[*examplev2.ExampleV2Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev2client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev2.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,11 +60,11 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*examplev2.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts v1.ListOptions) (*apisexamplev2.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } // Watch begins to watch all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { +func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().Watch(ctx, opts) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/doc.go new file mode 100644 index 000000000..ad8aa3bd4 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v2 diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/example_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/example_client.go index 5096e3628..58cf509a3 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/example_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v2 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev2 "acme.corp/pkg/apis/example/v2" + examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + scheme "acme.corp/pkg/kcp/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type ExampleV2ClusterInterface interface { ExampleV2ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter } type ExampleV2ClusterScoper interface { Cluster(logicalcluster.Path) examplev2.ExampleV2Interface } +// ExampleV2ClusterClient is used to interact with features provided by the example.dev group. type ExampleV2ClusterClient struct { clientCache kcpclient.Cache[*examplev2.ExampleV2Client] } @@ -53,23 +53,25 @@ func (c *ExampleV2ClusterClient) Cluster(clusterPath logicalcluster.Path) exampl return c.clientCache.ClusterOrDie(clusterPath) } -func (c *ExampleV2ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *ExampleV2ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *ExampleV2ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new ExampleV2ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExampleV2ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new ExampleV2ClusterClient for the given config and http client. @@ -81,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV2ClusterCli if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &ExampleV2ClusterClient{clientCache: cache}, nil } @@ -93,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *ExampleV2ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apisexamplev2.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/clustertesttype.go index 50ed201a6..492fa83ee 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev2 "acme.corp/pkg/apis/example/v2" + v2 "acme.corp/pkg/generated/applyconfigurations/example/v2" + typedexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + typedkcpexamplev2 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v2" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - examplev2 "acme.corp/pkg/apis/example/v2" - applyconfigurationsexamplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" - examplev2client "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example", Version: "v2", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example", Version: "v2", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) examplev2client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev2.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &examplev2.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev2.ClusterTestTypeList{ListMeta: obj.(*examplev2.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev2.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *ExampleV2ClusterClient) typedkcpexamplev2.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList]( + fake.Fake, + examplev2.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev2.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev2.ClusterTestType { return &examplev2.ClusterTestType{} }, + func() *examplev2.ClusterTestTypeList { return &examplev2.ClusterTestTypeList{} }, + func(dst, src *examplev2.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev2.ClusterTestTypeList) []*examplev2.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev2.ClusterTestTypeList, items []*examplev2.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexamplev2.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList, *v2.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *examplev2.ClusterTestType, opts metav1.CreateOptions) (*examplev2.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *examplev2.ClusterTestType, opts metav1.UpdateOptions) (*examplev2.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *examplev2.ClusterTestType, opts metav1.UpdateOptions) (*examplev2.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &examplev2.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &examplev2.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev2.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev2.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &examplev2.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev2.ClusterTestTypeList{ListMeta: obj.(*examplev2.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev2.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev2.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev2.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev2.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev2.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev2.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexamplev2.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList, *v2.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + examplev2.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev2.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev2.ClusterTestType { return &examplev2.ClusterTestType{} }, + func() *examplev2.ClusterTestTypeList { return &examplev2.ClusterTestTypeList{} }, + func(dst, src *examplev2.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev2.ClusterTestTypeList) []*examplev2.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev2.ClusterTestTypeList, items []*examplev2.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev2.ClusterTestType), err } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/example_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/example_client.go index 1f236aa43..d0db31ca7 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/example_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" kcpexamplev2 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v2" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpexamplev2.ExampleV2ClusterInterface = (*ExampleV2ClusterClient)(nil) @@ -44,30 +41,30 @@ func (c *ExampleV2ClusterClient) Cluster(clusterPath logicalcluster.Path) exampl return &ExampleV2Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *ExampleV2ClusterClient) TestTypes() kcpexamplev2.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *ExampleV2ClusterClient) ClusterTestTypes() kcpexamplev2.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ examplev2.ExampleV2Interface = (*ExampleV2Client)(nil) +func (c *ExampleV2ClusterClient) TestTypes() kcpexamplev2.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type ExampleV2Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *ExampleV2Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *ExampleV2Client) ClusterTestTypes() examplev2.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *ExampleV2Client) TestTypes(namespace string) examplev2.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExampleV2Client) ClusterTestTypes() examplev2.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExampleV2Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/testtype.go index f565b8a4c..5fa081412 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,197 +14,82 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev2 "acme.corp/pkg/apis/example/v2" + v2 "acme.corp/pkg/generated/applyconfigurations/example/v2" + typedexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + typedkcpexamplev2 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v2" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - examplev2 "acme.corp/pkg/apis/example/v2" - applyconfigurationsexamplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" - examplev2client "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" - kcpexamplev2 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v2" + "github.com/kcp-dev/logicalcluster/v3" ) -var testTypesResource = schema.GroupVersionResource{Group: "example", Version: "v2", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example", Version: "v2", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev2.TestType, *examplev2.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexamplev2.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +func newFakeTestTypeClusterClient(fake *ExampleV2ClusterClient) typedkcpexamplev2.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev2.TestType, *examplev2.TestTypeList]( + fake.Fake, + examplev2.SchemeGroupVersion.WithResource("testtypes"), + examplev2.SchemeGroupVersion.WithKind("TestType"), + func() *examplev2.TestType { return &examplev2.TestType{} }, + func() *examplev2.TestTypeList { return &examplev2.TestTypeList{} }, + func(dst, src *examplev2.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev2.TestTypeList) []*examplev2.TestType { return kcpgentype.ToPointerSlice(list.Items) }, + func(list *examplev2.TestTypeList, items []*examplev2.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. -func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev2.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &examplev2.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev2.TestTypeList{ListMeta: obj.(*examplev2.TestTypeList).ListMeta} - for _, item := range obj.(*examplev2.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexamplev2.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -// Watch returns a watch.Interface that watches the requested TestTypes across all clusters. -func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) -} - -type testTypesNamespacer struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev2client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexamplev2.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev2.TestType, *examplev2.TestTypeList, *v2.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *examplev2.TestType, opts metav1.CreateOptions) (*examplev2.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev2.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *examplev2.TestType, opts metav1.UpdateOptions) (*examplev2.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev2.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *examplev2.TestType, opts metav1.UpdateOptions) (*examplev2.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &examplev2.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &examplev2.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &examplev2.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev2.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &examplev2.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.TestType), err } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev2.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &examplev2.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev2.TestTypeList{ListMeta: obj.(*examplev2.TestTypeList).ListMeta} - for _, item := range obj.(*examplev2.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev2.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &examplev2.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev2.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev2.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &examplev2.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev2.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev2.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &examplev2.TestType{}) - if obj == nil { - return nil, err +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexamplev2.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev2.TestType, *examplev2.TestTypeList, *v2.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + examplev2.SchemeGroupVersion.WithResource("testtypes"), + examplev2.SchemeGroupVersion.WithKind("TestType"), + func() *examplev2.TestType { return &examplev2.TestType{} }, + func() *examplev2.TestTypeList { return &examplev2.TestTypeList{} }, + func(dst, src *examplev2.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev2.TestTypeList) []*examplev2.TestType { return kcpgentype.ToPointerSlice(list.Items) }, + func(list *examplev2.TestTypeList, items []*examplev2.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev2.TestType), err } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v2/testtype_expansion.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/generated_expansion.go similarity index 68% rename from examples/pkg/kcpexisting/clients/listers/example/v2/testtype_expansion.go rename to examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/generated_expansion.go index 68f6a8cb3..a324d34f5 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v2/testtype_expansion.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/generated_expansion.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,9 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v2 -// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. -type TestTypeClusterListerExpansion interface{} +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/testtype.go index d140c37d5..2efdd7058 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v2/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v2 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + examplev2 "acme.corp/pkg/apis/example/v2" + typedexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" - examplev2 "acme.corp/pkg/apis/example/v2" - examplev2client "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -44,12 +41,13 @@ type TestTypesClusterGetter interface { // or scope down to one cluster and return a TestTypesNamespacer. type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer - List(ctx context.Context, opts metav1.ListOptions) (*examplev2.TestTypeList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + List(ctx context.Context, opts v1.ListOptions) (*examplev2.TestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev2client.ExampleV2Client] + clientCache kcpclient.Cache[*typedexamplev2.ExampleV2Client] } // Cluster scopes the client down to a particular cluster. @@ -62,25 +60,25 @@ func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) Tes } // List returns the entire collection of all TestTypes across all clusters. -func (c *testTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*examplev2.TestTypeList, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).List(ctx, opts) +func (c *testTypesClusterInterface) List(ctx context.Context, opts v1.ListOptions) (*examplev2.TestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(v1.NamespaceAll).List(ctx, opts) } // Watch begins to watch all TestTypes across all clusters. -func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) +func (c *testTypesClusterInterface) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(v1.NamespaceAll).Watch(ctx, opts) } -// TestTypesNamespacer can scope to objects within a namespace, returning a examplev2client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexamplev2.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) examplev2client.TestTypeInterface + Namespace(string) typedexamplev2.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*examplev2client.ExampleV2Client] + clientCache kcpclient.Cache[*typedexamplev2.ExampleV2Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev2client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedexamplev2.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/clustertesttype.go index adde1fd08..b03688276 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" + example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - example3v1 "acme.corp/pkg/apis/example3/v1" - example3v1client "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a example3v1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a example3v1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) example3v1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*example3v1.ClusterTestTypeList, error) + Cluster(logicalcluster.Path) example3v1.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*apisexample3v1.ClusterTestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*example3v1client.Example3V1Client] + clientCache kcpclient.Cache[*example3v1.Example3V1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) example3v1client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) example3v1.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,7 +60,7 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*example3v1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*apisexample3v1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/doc.go new file mode 100644 index 000000000..dc2c8e634 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/example3_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/example3_client.go index 2285f2cf5..5978dec46 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/example3_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/example3_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" + example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + scheme "acme.corp/pkg/kcp/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type Example3V1ClusterInterface interface { Example3V1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter } type Example3V1ClusterScoper interface { Cluster(logicalcluster.Path) example3v1.Example3V1Interface } +// Example3V1ClusterClient is used to interact with features provided by the example3.some.corp group. type Example3V1ClusterClient struct { clientCache kcpclient.Cache[*example3v1.Example3V1Client] } @@ -53,23 +53,25 @@ func (c *Example3V1ClusterClient) Cluster(clusterPath logicalcluster.Path) examp return c.clientCache.ClusterOrDie(clusterPath) } -func (c *Example3V1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *Example3V1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *Example3V1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new Example3V1ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*Example3V1ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new Example3V1ClusterClient for the given config and http client. @@ -81,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*Example3V1ClusterCl if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &Example3V1ClusterClient{clientCache: cache}, nil } @@ -93,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *Example3V1ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apisexample3v1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go index 5905b6d77..01af25efc 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + example3v1 "acme.corp/pkg/apis/example3/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" + typedexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + typedkcpexample3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - example3v1 "acme.corp/pkg/apis/example3/v1" - applyconfigurationsexample3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" - example3v1client "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example3.some.corp", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example3.some.corp", Version: "v1", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) example3v1client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*example3v1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &example3v1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &example3v1.ClusterTestTypeList{ListMeta: obj.(*example3v1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*example3v1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *Example3V1ClusterClient) typedkcpexample3v1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList]( + fake.Fake, + example3v1.SchemeGroupVersion.WithResource("clustertesttypes"), + example3v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *example3v1.ClusterTestType { return &example3v1.ClusterTestType{} }, + func() *example3v1.ClusterTestTypeList { return &example3v1.ClusterTestTypeList{} }, + func(dst, src *example3v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *example3v1.ClusterTestTypeList) []*example3v1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *example3v1.ClusterTestTypeList, items []*example3v1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexample3v1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *example3v1.ClusterTestType, opts metav1.CreateOptions) (*example3v1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *example3v1.ClusterTestType, opts metav1.UpdateOptions) (*example3v1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *example3v1.ClusterTestType, opts metav1.UpdateOptions) (*example3v1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &example3v1.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &example3v1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*example3v1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*example3v1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &example3v1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &example3v1.ClusterTestTypeList{ListMeta: obj.(*example3v1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*example3v1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*example3v1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexample3v1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*example3v1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexample3v1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*example3v1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexample3v1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + example3v1.SchemeGroupVersion.WithResource("clustertesttypes"), + example3v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *example3v1.ClusterTestType { return &example3v1.ClusterTestType{} }, + func() *example3v1.ClusterTestTypeList { return &example3v1.ClusterTestTypeList{} }, + func(dst, src *example3v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *example3v1.ClusterTestTypeList) []*example3v1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *example3v1.ClusterTestTypeList, items []*example3v1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*example3v1.ClusterTestType), err } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/example3_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/example3_client.go index c88f0c78e..8f44329dc 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/example3_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/example3_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" kcpexample3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpexample3v1.Example3V1ClusterInterface = (*Example3V1ClusterClient)(nil) @@ -44,30 +41,30 @@ func (c *Example3V1ClusterClient) Cluster(clusterPath logicalcluster.Path) examp return &Example3V1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *Example3V1ClusterClient) TestTypes() kcpexample3v1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *Example3V1ClusterClient) ClusterTestTypes() kcpexample3v1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ example3v1.Example3V1Interface = (*Example3V1Client)(nil) +func (c *Example3V1ClusterClient) TestTypes() kcpexample3v1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type Example3V1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *Example3V1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *Example3V1Client) ClusterTestTypes() example3v1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *Example3V1Client) TestTypes(namespace string) example3v1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *Example3V1Client) ClusterTestTypes() example3v1.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *Example3V1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/testtype.go index a48cedad0..fa780e148 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,222 +14,121 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" + context "context" examplev1 "acme.corp/pkg/apis/example/v1" example3v1 "acme.corp/pkg/apis/example3/v1" - applyconfigurationsexample3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" - example3v1client "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" - kcpexample3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1" -) + v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" + typedexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + typedkcpexample3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1" -var testTypesResource = schema.GroupVersionResource{Group: "example3.some.corp", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example3.some.corp", Version: "v1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake -} + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexample3v1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" +) - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*example3v1.TestType, *example3v1.TestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. -func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*example3v1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &example3v1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &example3v1.TestTypeList{ListMeta: obj.(*example3v1.TestTypeList).ListMeta} - for _, item := range obj.(*example3v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeTestTypeClusterClient(fake *Example3V1ClusterClient) typedkcpexample3v1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*example3v1.TestType, *example3v1.TestTypeList]( + fake.Fake, + example3v1.SchemeGroupVersion.WithResource("testtypes"), + example3v1.SchemeGroupVersion.WithKind("TestType"), + func() *example3v1.TestType { return &example3v1.TestType{} }, + func() *example3v1.TestTypeList { return &example3v1.TestTypeList{} }, + func(dst, src *example3v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *example3v1.TestTypeList) []*example3v1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *example3v1.TestTypeList, items []*example3v1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested TestTypes across all clusters. -func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexample3v1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -type testTypesNamespacer struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) example3v1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexample3v1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*example3v1.TestType, *example3v1.TestTypeList, *v1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *example3v1.TestType, opts metav1.CreateOptions) (*example3v1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *example3v1.TestType, opts metav1.UpdateOptions) (*example3v1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *example3v1.TestType, opts metav1.UpdateOptions) (*example3v1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &example3v1.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &example3v1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*example3v1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*example3v1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &example3v1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &example3v1.TestTypeList{ListMeta: obj.(*example3v1.TestTypeList).ListMeta} - for _, item := range obj.(*example3v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*example3v1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexample3v1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*example3v1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexample3v1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*example3v1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err } -func (c *testTypesClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (*examplev1.Field, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(testTypesResource, c.ClusterPath, testTypeName, "field", c.Namespace, field), &examplev1.Field{}) +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexample3v1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*example3v1.TestType, *example3v1.TestTypeList, *v1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + example3v1.SchemeGroupVersion.WithResource("testtypes"), + example3v1.SchemeGroupVersion.WithKind("TestType"), + func() *example3v1.TestType { return &example3v1.TestType{} }, + func() *example3v1.TestTypeList { return &example3v1.TestTypeList{} }, + func(dst, src *example3v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *example3v1.TestTypeList) []*example3v1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *example3v1.TestTypeList, items []*example3v1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, + } +} + +// CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypeScopedClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, _ metav1.CreateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(c.Resource(), c.ClusterPath, testTypeName, "field", c.Namespace(), field), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } -func (c *testTypesClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (*examplev1.Field, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, field), &examplev1.Field{}) +// UpdateField takes the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypeScopedClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, _ metav1.UpdateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(c.Resource(), c.ClusterPath, "field", c.Namespace(), field), &examplev1.Field{}) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } -func (c *testTypesClient) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*examplev1.Field, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, testTypeName), &examplev1.Field{}) +// GetField takes name of the testType, and returns the corresponding field object, and an error if there is any. +func (c *testTypeScopedClient) GetField(ctx context.Context, testTypeName string, _ metav1.GetOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(c.Resource(), c.ClusterPath, c.Namespace(), "field", testTypeName), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } diff --git a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype_expansion.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/generated_expansion.go similarity index 68% rename from examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype_expansion.go rename to examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/generated_expansion.go index 835da85d6..21b9d4175 100644 --- a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype_expansion.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/generated_expansion.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,9 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 -// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. -type TestTypeClusterListerExpansion interface{} +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/testtype.go index bee57419e..6a28c0f86 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + example3v1 "acme.corp/pkg/apis/example3/v1" + typedexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - example3v1 "acme.corp/pkg/apis/example3/v1" - example3v1client "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -46,10 +43,11 @@ type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer List(ctx context.Context, opts metav1.ListOptions) (*example3v1.TestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*example3v1client.Example3V1Client] + clientCache kcpclient.Cache[*typedexample3v1.Example3V1Client] } // Cluster scopes the client down to a particular cluster. @@ -71,16 +69,16 @@ func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListO return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) } -// TestTypesNamespacer can scope to objects within a namespace, returning a example3v1client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexample3v1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) example3v1client.TestTypeInterface + Namespace(string) typedexample3v1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*example3v1client.Example3V1Client] + clientCache kcpclient.Cache[*typedexample3v1.Example3V1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) example3v1client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedexample3v1.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..f3c907eba --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go @@ -0,0 +1,70 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + + apisexampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" +) + +// ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. +// A group's cluster client should implement this interface. +type ClusterTestTypesClusterGetter interface { + ClusterTestTypes() ClusterTestTypeClusterInterface +} + +// ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, +// or scope down to one cluster and return a exampledashedv1.ClusterTestTypeInterface. +type ClusterTestTypeClusterInterface interface { + Cluster(logicalcluster.Path) exampledashedv1.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*apisexampledashedv1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion +} + +type clusterTestTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv1.ExampleDashedV1Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ClusterTestTypeInterface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return c.clientCache.ClusterOrDie(clusterPath).ClusterTestTypes() +} + +// List returns the entire collection of all ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*apisexampledashedv1.ClusterTestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) +} + +// Watch begins to watch all ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().Watch(ctx, opts) +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/doc.go new file mode 100644 index 000000000..dc2c8e634 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go new file mode 100644 index 000000000..86b51039a --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go @@ -0,0 +1,109 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +import ( + http "net/http" + + apisexampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + scheme "acme.corp/pkg/kcp/clients/clientset/versioned/scheme" + + rest "k8s.io/client-go/rest" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" +) + +type ExampleDashedV1ClusterInterface interface { + ExampleDashedV1ClusterScoper + ClusterTestTypesClusterGetter + TestTypesClusterGetter +} + +type ExampleDashedV1ClusterScoper interface { + Cluster(logicalcluster.Path) exampledashedv1.ExampleDashedV1Interface +} + +// ExampleDashedV1ClusterClient is used to interact with features provided by the example-dashed.some.corp group. +type ExampleDashedV1ClusterClient struct { + clientCache kcpclient.Cache[*exampledashedv1.ExampleDashedV1Client] +} + +func (c *ExampleDashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ExampleDashedV1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +func (c *ExampleDashedV1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterInterface{clientCache: c.clientCache} +} + +func (c *ExampleDashedV1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + +// NewForConfig creates a new ExampleDashedV1ClusterClient for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExampleDashedV1ClusterClient, error) { + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new ExampleDashedV1ClusterClient for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleDashedV1ClusterClient, error) { + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*exampledashedv1.ExampleDashedV1Client]{ + NewForConfigAndClient: exampledashedv1.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + + return &ExampleDashedV1ClusterClient{clientCache: cache}, nil +} + +// NewForConfigOrDie creates a new ExampleDashedV1ClusterClient for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExampleDashedV1ClusterClient { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +func setConfigDefaults(config *rest.Config) { + gv := apisexampledashedv1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go new file mode 100644 index 000000000..cbc88e0d0 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go @@ -0,0 +1,90 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package fake + +import ( + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + typedexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + typedkcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" + + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" +) + +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList] + Fake *kcptesting.Fake +} + +func newFakeClusterTestTypeClusterClient(fake *ExampleDashedV1ClusterClient) typedkcpexampledashedv1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList]( + fake.Fake, + exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"), + exampledashedv1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *exampledashedv1.ClusterTestType { return &exampledashedv1.ClusterTestType{} }, + func() *exampledashedv1.ClusterTestTypeList { return &exampledashedv1.ClusterTestTypeList{} }, + func(dst, src *exampledashedv1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *exampledashedv1.ClusterTestTypeList) []*exampledashedv1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *exampledashedv1.ClusterTestTypeList, items []*exampledashedv1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, + } +} + +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexampledashedv1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) +} + +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexampledashedv1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"), + exampledashedv1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *exampledashedv1.ClusterTestType { return &exampledashedv1.ClusterTestType{} }, + func() *exampledashedv1.ClusterTestTypeList { return &exampledashedv1.ClusterTestTypeList{} }, + func(dst, src *exampledashedv1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *exampledashedv1.ClusterTestTypeList) []*exampledashedv1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *exampledashedv1.ClusterTestTypeList, items []*exampledashedv1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, + } +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go new file mode 100644 index 000000000..ee952fd9a --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go @@ -0,0 +1,70 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package fake + +import ( + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" +) + +var _ kcpexampledashedv1.ExampleDashedV1ClusterInterface = (*ExampleDashedV1ClusterClient)(nil) + +type ExampleDashedV1ClusterClient struct { + *kcptesting.Fake +} + +func (c *ExampleDashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ExampleDashedV1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &ExampleDashedV1Client{Fake: c.Fake, ClusterPath: clusterPath} +} + +func (c *ExampleDashedV1ClusterClient) ClusterTestTypes() kcpexampledashedv1.ClusterTestTypeClusterInterface { + return newFakeClusterTestTypeClusterClient(c) +} + +func (c *ExampleDashedV1ClusterClient) TestTypes() kcpexampledashedv1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} + +type ExampleDashedV1Client struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *ExampleDashedV1Client) ClusterTestTypes() exampledashedv1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) +} + +func (c *ExampleDashedV1Client) TestTypes(namespace string) exampledashedv1.TestTypeInterface { + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExampleDashedV1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go new file mode 100644 index 000000000..1a1383a0c --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go @@ -0,0 +1,134 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package fake + +import ( + context "context" + + examplev1 "acme.corp/pkg/apis/example/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + typedexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + typedkcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" +) + +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*exampledashedv1.TestType, *exampledashedv1.TestTypeList] + Fake *kcptesting.Fake +} + +func newFakeTestTypeClusterClient(fake *ExampleDashedV1ClusterClient) typedkcpexampledashedv1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*exampledashedv1.TestType, *exampledashedv1.TestTypeList]( + fake.Fake, + exampledashedv1.SchemeGroupVersion.WithResource("testtypes"), + exampledashedv1.SchemeGroupVersion.WithKind("TestType"), + func() *exampledashedv1.TestType { return &exampledashedv1.TestType{} }, + func() *exampledashedv1.TestTypeList { return &exampledashedv1.TestTypeList{} }, + func(dst, src *exampledashedv1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *exampledashedv1.TestTypeList) []*exampledashedv1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *exampledashedv1.TestTypeList, items []*exampledashedv1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, + } +} + +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexampledashedv1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} +} + +type testTypeNamespacer struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (n *testTypeNamespacer) Namespace(namespace string) typedexampledashedv1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) +} + +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*exampledashedv1.TestType, *exampledashedv1.TestTypeList, *v1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexampledashedv1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*exampledashedv1.TestType, *exampledashedv1.TestTypeList, *v1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + exampledashedv1.SchemeGroupVersion.WithResource("testtypes"), + exampledashedv1.SchemeGroupVersion.WithKind("TestType"), + func() *exampledashedv1.TestType { return &exampledashedv1.TestType{} }, + func() *exampledashedv1.TestTypeList { return &exampledashedv1.TestTypeList{} }, + func(dst, src *exampledashedv1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *exampledashedv1.TestTypeList) []*exampledashedv1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *exampledashedv1.TestTypeList, items []*exampledashedv1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, + } +} + +// CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypeScopedClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, _ metav1.CreateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(c.Resource(), c.ClusterPath, testTypeName, "field", c.Namespace(), field), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} + +// UpdateField takes the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypeScopedClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, _ metav1.UpdateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(c.Resource(), c.ClusterPath, "field", c.Namespace(), field), &examplev1.Field{}) + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} + +// GetField takes name of the testType, and returns the corresponding field object, and an error if there is any. +func (c *testTypeScopedClient) GetField(ctx context.Context, testTypeName string, _ metav1.GetOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(c.Resource(), c.ClusterPath, c.Namespace(), "field", testTypeName), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/generated_expansion.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/generated_expansion.go new file mode 100644 index 000000000..21b9d4175 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/testtype.go new file mode 100644 index 000000000..286c87623 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/testtype.go @@ -0,0 +1,84 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + typedexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" +) + +// TestTypesClusterGetter has a method to return a TestTypeClusterInterface. +// A group's cluster client should implement this interface. +type TestTypesClusterGetter interface { + TestTypes() TestTypeClusterInterface +} + +// TestTypeClusterInterface can operate on TestTypes across all clusters, +// or scope down to one cluster and return a TestTypesNamespacer. +type TestTypeClusterInterface interface { + Cluster(logicalcluster.Path) TestTypesNamespacer + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion +} + +type testTypesClusterInterface struct { + clientCache kcpclient.Cache[*typedexampledashedv1.ExampleDashedV1Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) TestTypesNamespacer { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &testTypesNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} +} + +// List returns the entire collection of all TestTypes across all clusters. +func (c *testTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).List(ctx, opts) +} + +// Watch begins to watch all TestTypes across all clusters. +func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) +} + +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexampledashedv1.TestTypeInterface. +type TestTypesNamespacer interface { + Namespace(string) typedexampledashedv1.TestTypeInterface +} + +type testTypesNamespacer struct { + clientCache kcpclient.Cache[*typedexampledashedv1.ExampleDashedV1Client] + clusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) typedexampledashedv1.TestTypeInterface { + return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go index c9f0833ce..d829a5546 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - existinginterfacesv1client "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a existinginterfacesv1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a existinginterfacesv1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) existinginterfacesv1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.ClusterTestTypeList, error) + Cluster(logicalcluster.Path) existinginterfacesv1.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*apisexistinginterfacesv1.ClusterTestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*existinginterfacesv1client.ExistinginterfacesV1Client] + clientCache kcpclient.Cache[*existinginterfacesv1.ExistinginterfacesV1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) existinginterfacesv1client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) existinginterfacesv1.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,7 +60,7 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*apisexistinginterfacesv1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/doc.go new file mode 100644 index 000000000..dc2c8e634 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/existinginterfaces_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/existinginterfaces_client.go index f91869ecb..c2b520e6c 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/existinginterfaces_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/existinginterfaces_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + scheme "acme.corp/pkg/kcp/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type ExistinginterfacesV1ClusterInterface interface { ExistinginterfacesV1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter } type ExistinginterfacesV1ClusterScoper interface { Cluster(logicalcluster.Path) existinginterfacesv1.ExistinginterfacesV1Interface } +// ExistinginterfacesV1ClusterClient is used to interact with features provided by the existinginterfaces.acme.corp group. type ExistinginterfacesV1ClusterClient struct { clientCache kcpclient.Cache[*existinginterfacesv1.ExistinginterfacesV1Client] } @@ -53,23 +53,25 @@ func (c *ExistinginterfacesV1ClusterClient) Cluster(clusterPath logicalcluster.P return c.clientCache.ClusterOrDie(clusterPath) } -func (c *ExistinginterfacesV1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *ExistinginterfacesV1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *ExistinginterfacesV1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new ExistinginterfacesV1ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExistinginterfacesV1ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new ExistinginterfacesV1ClusterClient for the given config and http client. @@ -81,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExistinginterfacesV if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &ExistinginterfacesV1ClusterClient{clientCache: cache}, nil } @@ -93,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *ExistinginterfacesV1ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apisexistinginterfacesv1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go index 3db29e205..ce5ffa993 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" + typedexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + typedkcpexistinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - applyconfigurationsexistinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" - existinginterfacesv1client "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "existinginterfaces.acme.corp", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "existinginterfaces.acme.corp", Version: "v1", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) existinginterfacesv1client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &existinginterfacesv1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &existinginterfacesv1.ClusterTestTypeList{ListMeta: obj.(*existinginterfacesv1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*existinginterfacesv1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *ExistinginterfacesV1ClusterClient) typedkcpexistinginterfacesv1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList]( + fake.Fake, + existinginterfacesv1.SchemeGroupVersion.WithResource("clustertesttypes"), + existinginterfacesv1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *existinginterfacesv1.ClusterTestType { return &existinginterfacesv1.ClusterTestType{} }, + func() *existinginterfacesv1.ClusterTestTypeList { return &existinginterfacesv1.ClusterTestTypeList{} }, + func(dst, src *existinginterfacesv1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *existinginterfacesv1.ClusterTestTypeList) []*existinginterfacesv1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *existinginterfacesv1.ClusterTestTypeList, items []*existinginterfacesv1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexistinginterfacesv1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *existinginterfacesv1.ClusterTestType, opts metav1.CreateOptions) (*existinginterfacesv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *existinginterfacesv1.ClusterTestType, opts metav1.UpdateOptions) (*existinginterfacesv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *existinginterfacesv1.ClusterTestType, opts metav1.UpdateOptions) (*existinginterfacesv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &existinginterfacesv1.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &existinginterfacesv1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*existinginterfacesv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &existinginterfacesv1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &existinginterfacesv1.ClusterTestTypeList{ListMeta: obj.(*existinginterfacesv1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*existinginterfacesv1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*existinginterfacesv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexistinginterfacesv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*existinginterfacesv1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexistinginterfacesv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*existinginterfacesv1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexistinginterfacesv1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + existinginterfacesv1.SchemeGroupVersion.WithResource("clustertesttypes"), + existinginterfacesv1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *existinginterfacesv1.ClusterTestType { return &existinginterfacesv1.ClusterTestType{} }, + func() *existinginterfacesv1.ClusterTestTypeList { return &existinginterfacesv1.ClusterTestTypeList{} }, + func(dst, src *existinginterfacesv1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *existinginterfacesv1.ClusterTestTypeList) []*existinginterfacesv1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *existinginterfacesv1.ClusterTestTypeList, items []*existinginterfacesv1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*existinginterfacesv1.ClusterTestType), err } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/existinginterfaces_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/existinginterfaces_client.go index 57d89259f..878d1e1da 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/existinginterfaces_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/existinginterfaces_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" kcpexistinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpexistinginterfacesv1.ExistinginterfacesV1ClusterInterface = (*ExistinginterfacesV1ClusterClient)(nil) @@ -44,30 +41,30 @@ func (c *ExistinginterfacesV1ClusterClient) Cluster(clusterPath logicalcluster.P return &ExistinginterfacesV1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *ExistinginterfacesV1ClusterClient) TestTypes() kcpexistinginterfacesv1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *ExistinginterfacesV1ClusterClient) ClusterTestTypes() kcpexistinginterfacesv1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ existinginterfacesv1.ExistinginterfacesV1Interface = (*ExistinginterfacesV1Client)(nil) +func (c *ExistinginterfacesV1ClusterClient) TestTypes() kcpexistinginterfacesv1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type ExistinginterfacesV1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *ExistinginterfacesV1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *ExistinginterfacesV1Client) ClusterTestTypes() existinginterfacesv1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *ExistinginterfacesV1Client) TestTypes(namespace string) existinginterfacesv1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExistinginterfacesV1Client) ClusterTestTypes() existinginterfacesv1.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExistinginterfacesV1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go index 8279dd6a9..8d42b4580 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,197 +14,86 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" + typedexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + typedkcpexistinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - applyconfigurationsexistinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" - existinginterfacesv1client "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" - kcpexistinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var testTypesResource = schema.GroupVersionResource{Group: "existinginterfaces.acme.corp", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "existinginterfaces.acme.corp", Version: "v1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexistinginterfacesv1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +func newFakeTestTypeClusterClient(fake *ExistinginterfacesV1ClusterClient) typedkcpexistinginterfacesv1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList]( + fake.Fake, + existinginterfacesv1.SchemeGroupVersion.WithResource("testtypes"), + existinginterfacesv1.SchemeGroupVersion.WithKind("TestType"), + func() *existinginterfacesv1.TestType { return &existinginterfacesv1.TestType{} }, + func() *existinginterfacesv1.TestTypeList { return &existinginterfacesv1.TestTypeList{} }, + func(dst, src *existinginterfacesv1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *existinginterfacesv1.TestTypeList) []*existinginterfacesv1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *existinginterfacesv1.TestTypeList, items []*existinginterfacesv1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. -func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &existinginterfacesv1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &existinginterfacesv1.TestTypeList{ListMeta: obj.(*existinginterfacesv1.TestTypeList).ListMeta} - for _, item := range obj.(*existinginterfacesv1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexistinginterfacesv1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -// Watch returns a watch.Interface that watches the requested TestTypes across all clusters. -func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) -} - -type testTypesNamespacer struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) existinginterfacesv1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexistinginterfacesv1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList, *v1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *existinginterfacesv1.TestType, opts metav1.CreateOptions) (*existinginterfacesv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *existinginterfacesv1.TestType, opts metav1.UpdateOptions) (*existinginterfacesv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *existinginterfacesv1.TestType, opts metav1.UpdateOptions) (*existinginterfacesv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &existinginterfacesv1.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &existinginterfacesv1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*existinginterfacesv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &existinginterfacesv1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &existinginterfacesv1.TestTypeList{ListMeta: obj.(*existinginterfacesv1.TestTypeList).ListMeta} - for _, item := range obj.(*existinginterfacesv1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*existinginterfacesv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexistinginterfacesv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*existinginterfacesv1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexistinginterfacesv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*existinginterfacesv1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexistinginterfacesv1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList, *v1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + existinginterfacesv1.SchemeGroupVersion.WithResource("testtypes"), + existinginterfacesv1.SchemeGroupVersion.WithKind("TestType"), + func() *existinginterfacesv1.TestType { return &existinginterfacesv1.TestType{} }, + func() *existinginterfacesv1.TestTypeList { return &existinginterfacesv1.TestTypeList{} }, + func(dst, src *existinginterfacesv1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *existinginterfacesv1.TestTypeList) []*existinginterfacesv1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *existinginterfacesv1.TestTypeList, items []*existinginterfacesv1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*existinginterfacesv1.TestType), err } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/generated_expansion.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/generated_expansion.go new file mode 100644 index 000000000..21b9d4175 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/testtype.go index 3873c0502..8adce2827 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + typedexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - existinginterfacesv1client "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -46,10 +43,11 @@ type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.TestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*existinginterfacesv1client.ExistinginterfacesV1Client] + clientCache kcpclient.Cache[*typedexistinginterfacesv1.ExistinginterfacesV1Client] } // Cluster scopes the client down to a particular cluster. @@ -71,16 +69,16 @@ func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListO return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) } -// TestTypesNamespacer can scope to objects within a namespace, returning a existinginterfacesv1client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexistinginterfacesv1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) existinginterfacesv1client.TestTypeInterface + Namespace(string) typedexistinginterfacesv1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*existinginterfacesv1client.ExistinginterfacesV1Client] + clientCache kcpclient.Cache[*typedexistinginterfacesv1.ExistinginterfacesV1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) existinginterfacesv1client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedexistinginterfacesv1.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/clustertesttype.go index 28c948133..861ce3c8c 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - secondexamplev1client "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a secondexamplev1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a secondexamplev1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) secondexamplev1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.ClusterTestTypeList, error) + Cluster(logicalcluster.Path) secondexamplev1.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*apissecondexamplev1.ClusterTestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*secondexamplev1client.SecondexampleV1Client] + clientCache kcpclient.Cache[*secondexamplev1.SecondexampleV1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) secondexamplev1client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) secondexamplev1.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,7 +60,7 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*apissecondexamplev1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/doc.go new file mode 100644 index 000000000..dc2c8e634 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/clustertesttype.go index bfa081276..868d6acf5 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" + typedsecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + typedkcpsecondexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - applyconfigurationssecondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" - secondexamplev1client "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "secondexample", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "secondexample", Version: "v1", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) secondexamplev1client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &secondexamplev1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &secondexamplev1.ClusterTestTypeList{ListMeta: obj.(*secondexamplev1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*secondexamplev1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *SecondexampleV1ClusterClient) typedkcpsecondexamplev1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList]( + fake.Fake, + secondexamplev1.SchemeGroupVersion.WithResource("clustertesttypes"), + secondexamplev1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *secondexamplev1.ClusterTestType { return &secondexamplev1.ClusterTestType{} }, + func() *secondexamplev1.ClusterTestTypeList { return &secondexamplev1.ClusterTestTypeList{} }, + func(dst, src *secondexamplev1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *secondexamplev1.ClusterTestTypeList) []*secondexamplev1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *secondexamplev1.ClusterTestTypeList, items []*secondexamplev1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedsecondexamplev1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *secondexamplev1.ClusterTestType, opts metav1.CreateOptions) (*secondexamplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *secondexamplev1.ClusterTestType, opts metav1.UpdateOptions) (*secondexamplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *secondexamplev1.ClusterTestType, opts metav1.UpdateOptions) (*secondexamplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &secondexamplev1.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &secondexamplev1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*secondexamplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &secondexamplev1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &secondexamplev1.ClusterTestTypeList{ListMeta: obj.(*secondexamplev1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*secondexamplev1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*secondexamplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationssecondexamplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*secondexamplev1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationssecondexamplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*secondexamplev1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedsecondexamplev1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + secondexamplev1.SchemeGroupVersion.WithResource("clustertesttypes"), + secondexamplev1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *secondexamplev1.ClusterTestType { return &secondexamplev1.ClusterTestType{} }, + func() *secondexamplev1.ClusterTestTypeList { return &secondexamplev1.ClusterTestTypeList{} }, + func(dst, src *secondexamplev1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *secondexamplev1.ClusterTestTypeList) []*secondexamplev1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *secondexamplev1.ClusterTestTypeList, items []*secondexamplev1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*secondexamplev1.ClusterTestType), err } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/doc.go b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/secondexample_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/secondexample_client.go index 92be820b3..4ab6a9269 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/secondexample_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/secondexample_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" kcpsecondexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpsecondexamplev1.SecondexampleV1ClusterInterface = (*SecondexampleV1ClusterClient)(nil) @@ -44,30 +41,30 @@ func (c *SecondexampleV1ClusterClient) Cluster(clusterPath logicalcluster.Path) return &SecondexampleV1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *SecondexampleV1ClusterClient) TestTypes() kcpsecondexamplev1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *SecondexampleV1ClusterClient) ClusterTestTypes() kcpsecondexamplev1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ secondexamplev1.SecondexampleV1Interface = (*SecondexampleV1Client)(nil) +func (c *SecondexampleV1ClusterClient) TestTypes() kcpsecondexamplev1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type SecondexampleV1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *SecondexampleV1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *SecondexampleV1Client) ClusterTestTypes() secondexamplev1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *SecondexampleV1Client) TestTypes(namespace string) secondexamplev1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *SecondexampleV1Client) ClusterTestTypes() secondexamplev1.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *SecondexampleV1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/testtype.go index f820e4c88..41a76e9e5 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,197 +14,86 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" + typedsecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + typedkcpsecondexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - applyconfigurationssecondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" - secondexamplev1client "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" - kcpsecondexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var testTypesResource = schema.GroupVersionResource{Group: "secondexample", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "secondexample", Version: "v1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*secondexamplev1.TestType, *secondexamplev1.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpsecondexamplev1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +func newFakeTestTypeClusterClient(fake *SecondexampleV1ClusterClient) typedkcpsecondexamplev1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*secondexamplev1.TestType, *secondexamplev1.TestTypeList]( + fake.Fake, + secondexamplev1.SchemeGroupVersion.WithResource("testtypes"), + secondexamplev1.SchemeGroupVersion.WithKind("TestType"), + func() *secondexamplev1.TestType { return &secondexamplev1.TestType{} }, + func() *secondexamplev1.TestTypeList { return &secondexamplev1.TestTypeList{} }, + func(dst, src *secondexamplev1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *secondexamplev1.TestTypeList) []*secondexamplev1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *secondexamplev1.TestTypeList, items []*secondexamplev1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. -func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &secondexamplev1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &secondexamplev1.TestTypeList{ListMeta: obj.(*secondexamplev1.TestTypeList).ListMeta} - for _, item := range obj.(*secondexamplev1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpsecondexamplev1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -// Watch returns a watch.Interface that watches the requested TestTypes across all clusters. -func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) -} - -type testTypesNamespacer struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) secondexamplev1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedsecondexamplev1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*secondexamplev1.TestType, *secondexamplev1.TestTypeList, *v1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *secondexamplev1.TestType, opts metav1.CreateOptions) (*secondexamplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *secondexamplev1.TestType, opts metav1.UpdateOptions) (*secondexamplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *secondexamplev1.TestType, opts metav1.UpdateOptions) (*secondexamplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &secondexamplev1.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &secondexamplev1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*secondexamplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &secondexamplev1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &secondexamplev1.TestTypeList{ListMeta: obj.(*secondexamplev1.TestTypeList).ListMeta} - for _, item := range obj.(*secondexamplev1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*secondexamplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationssecondexamplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*secondexamplev1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationssecondexamplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*secondexamplev1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedsecondexamplev1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*secondexamplev1.TestType, *secondexamplev1.TestTypeList, *v1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + secondexamplev1.SchemeGroupVersion.WithResource("testtypes"), + secondexamplev1.SchemeGroupVersion.WithKind("TestType"), + func() *secondexamplev1.TestType { return &secondexamplev1.TestType{} }, + func() *secondexamplev1.TestTypeList { return &secondexamplev1.TestTypeList{} }, + func(dst, src *secondexamplev1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *secondexamplev1.TestTypeList) []*secondexamplev1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *secondexamplev1.TestTypeList, items []*secondexamplev1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*secondexamplev1.TestType), err } diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/generated_expansion.go b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/generated_expansion.go new file mode 100644 index 000000000..21b9d4175 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/secondexample_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/secondexample_client.go index f0da7668f..0a27f0d9f 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/secondexample_client.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/secondexample_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + scheme "acme.corp/pkg/kcp/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type SecondexampleV1ClusterInterface interface { SecondexampleV1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter } type SecondexampleV1ClusterScoper interface { Cluster(logicalcluster.Path) secondexamplev1.SecondexampleV1Interface } +// SecondexampleV1ClusterClient is used to interact with features provided by the secondexample.dev group. type SecondexampleV1ClusterClient struct { clientCache kcpclient.Cache[*secondexamplev1.SecondexampleV1Client] } @@ -53,23 +53,25 @@ func (c *SecondexampleV1ClusterClient) Cluster(clusterPath logicalcluster.Path) return c.clientCache.ClusterOrDie(clusterPath) } -func (c *SecondexampleV1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *SecondexampleV1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *SecondexampleV1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new SecondexampleV1ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*SecondexampleV1ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new SecondexampleV1ClusterClient for the given config and http client. @@ -81,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*SecondexampleV1Clus if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &SecondexampleV1ClusterClient{clientCache: cache}, nil } @@ -93,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *SecondexampleV1ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apissecondexamplev1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/testtype.go index fe04e5e5b..beb003f72 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + typedsecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - secondexamplev1client "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -46,10 +43,11 @@ type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.TestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*secondexamplev1client.SecondexampleV1Client] + clientCache kcpclient.Cache[*typedsecondexamplev1.SecondexampleV1Client] } // Cluster scopes the client down to a particular cluster. @@ -71,16 +69,16 @@ func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListO return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) } -// TestTypesNamespacer can scope to objects within a namespace, returning a secondexamplev1client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedsecondexamplev1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) secondexamplev1client.TestTypeInterface + Namespace(string) typedsecondexamplev1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*secondexamplev1client.SecondexampleV1Client] + clientCache kcpclient.Cache[*typedsecondexamplev1.SecondexampleV1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) secondexamplev1client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedsecondexamplev1.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/interface.go b/examples/pkg/kcp/clients/informers/externalversions/example/interface.go index 424e1f2b4..4d6b8d142 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,26 +14,27 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package example import ( - "acme.corp/pkg/kcp/clients/informers/externalversions/example/v1" - "acme.corp/pkg/kcp/clients/informers/externalversions/example/v1alpha1" - "acme.corp/pkg/kcp/clients/informers/externalversions/example/v1beta1" - "acme.corp/pkg/kcp/clients/informers/externalversions/example/v2" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + v1 "acme.corp/pkg/kcp/clients/informers/externalversions/example/v1" + v1alpha1 "acme.corp/pkg/kcp/clients/informers/externalversions/example/v1alpha1" + v1beta1 "acme.corp/pkg/kcp/clients/informers/externalversions/example/v1beta1" + v2 "acme.corp/pkg/kcp/clients/informers/externalversions/example/v2" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" ) +// ClusterInterface provides access to each of this group's versions. type ClusterInterface interface { - // V1 provides access to the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.ClusterInterface - // V1alpha1 provides access to the shared informers in V1alpha1. + // V1alpha1 provides access to shared informers for resources in V1alpha1. V1alpha1() v1alpha1.ClusterInterface - // V1beta1 provides access to the shared informers in V1beta1. + // V1beta1 provides access to shared informers for resources in V1beta1. V1beta1() v1beta1.ClusterInterface - // V2 provides access to the shared informers in V2. + // V2 provides access to shared informers for resources in V2. V2() v2.ClusterInterface } @@ -70,14 +68,15 @@ func (g *group) V2() v2.ClusterInterface { return v2.New(g.factory, g.tweakListOptions) } +// Interface provides access to each of this group's versions. type Interface interface { - // V1 provides access to the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.Interface - // V1alpha1 provides access to the shared informers in V1alpha1. + // V1alpha1 provides access to shared informers for resources in V1alpha1. V1alpha1() v1alpha1.Interface - // V1beta1 provides access to the shared informers in V1beta1. + // V1beta1 provides access to shared informers for resources in V1beta1. V1beta1() v1beta1.Interface - // V2 provides access to the shared informers in V2. + // V2 provides access to shared informers for resources in V2. V2() v2.Interface } @@ -92,22 +91,22 @@ func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace strin return &scopedGroup{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// V1 returns a new v1.ClusterInterface. +// V1 returns a new v1.Interface. func (g *scopedGroup) V1() v1.Interface { return v1.NewScoped(g.factory, g.namespace, g.tweakListOptions) } -// V1alpha1 returns a new v1alpha1.ClusterInterface. +// V1alpha1 returns a new v1alpha1.Interface. func (g *scopedGroup) V1alpha1() v1alpha1.Interface { return v1alpha1.NewScoped(g.factory, g.namespace, g.tweakListOptions) } -// V1beta1 returns a new v1beta1.ClusterInterface. +// V1beta1 returns a new v1beta1.Interface. func (g *scopedGroup) V1beta1() v1beta1.Interface { return v1beta1.NewScoped(g.factory, g.namespace, g.tweakListOptions) } -// V2 returns a new v2.ClusterInterface. +// V2 returns a new v2.Interface. func (g *scopedGroup) V2() v2.Interface { return v2.NewScoped(g.factory, g.namespace, g.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1/clustertesttype.go index 226cb1047..77f6ed3f8 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1 "acme.corp/pkg/apis/example/v1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + examplev1 "acme.corp/pkg/kcp/clients/listers/example/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev1 "acme.corp/pkg/apis/example/v1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - examplev1listers "acme.corp/pkg/kcp/clients/listers/example/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1listers.ClusterTestTypeClusterLister + Lister() examplev1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -57,76 +55,82 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &examplev1.ClusterTestType{}, + &apisexamplev1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Lister() examplev1listers.ClusterTestTypeClusterLister { - return examplev1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Lister() examplev1.ClusterTestTypeClusterLister { + return examplev1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -// ClusterTestTypeInformer provides access to a shared informer and lister for -// ClusterTestTypes. -type ClusterTestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() examplev1listers.ClusterTestTypeLister +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister examplev1listers.ClusterTestTypeLister + lister examplev1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() examplev1listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() examplev1.ClusterTestTypeLister { + return i.lister +} + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev1.ClusterTestTypeLister } type clusterTestTypeScopedInformer struct { @@ -134,46 +138,46 @@ type clusterTestTypeScopedInformer struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -func (f *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1.ClusterTestType{}, f.defaultInformer) -} - -func (f *clusterTestTypeScopedInformer) Lister() examplev1listers.ClusterTestTypeLister { - return examplev1listers.NewClusterTestTypeLister(f.Informer().GetIndexer()) -} - // NewClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { +func NewClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &examplev1.ClusterTestType{}, + &apisexamplev1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) +func (i *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1.ClusterTestType{}, i.defaultInformer) +} + +func (i *clusterTestTypeScopedInformer) Lister() examplev1.ClusterTestTypeLister { + return examplev1.NewClusterTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1/interface.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1/interface.go index 3034bb594..e632b7bcb 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // TestTypes returns a TestTypeClusterInformer - TestTypes() TestTypeClusterInformer - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -37,26 +34,26 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// TestTypes returns a TestTypeClusterInformer -func (v *version) TestTypes() TestTypeClusterInformer { - return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + type Interface interface { - // TestTypes returns a TestTypeInformer - TestTypes() TestTypeInformer - // ClusterTestTypes returns a ClusterTestTypeInformer + // ClusterTestTypes returns a ClusterTestTypeInformer. ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer } type scopedVersion struct { @@ -65,17 +62,17 @@ type scopedVersion struct { namespace string } -// New returns a new ClusterInterface. +// New returns a new Interface. func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &scopedVersion{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// TestTypes returns a TestTypeInformer -func (v *scopedVersion) TestTypes() TestTypeInformer { - return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} + return &scopedVersion{factory: f, tweakListOptions: tweakListOptions} } -// ClusterTestTypes returns a ClusterTestTypeInformer +// ClusterTestTypes returns a ClusterTestTypeInformer. func (v *scopedVersion) ClusterTestTypes() ClusterTestTypeInformer { return &clusterTestTypeScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeInformer. +func (v *scopedVersion) TestTypes() TestTypeInformer { + return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1/testtype.go index d4341a5b7..2c672c1b4 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1 "acme.corp/pkg/apis/example/v1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + examplev1 "acme.corp/pkg/kcp/clients/listers/example/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev1 "acme.corp/pkg/apis/example/v1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - examplev1listers "acme.corp/pkg/kcp/clients/listers/example/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1listers.TestTypeClusterLister + Lister() examplev1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -57,76 +55,82 @@ type testTypeClusterInformer struct { // NewTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().TestTypes().List(context.TODO(), options) + return client.ExampleV1().TestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().TestTypes().Watch(context.TODO(), options) + return client.ExampleV1().TestTypes().Watch(context.Background(), options) }, }, - &examplev1.TestType{}, + &apisexamplev1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, - f.tweakListOptions, - ) + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Lister() examplev1listers.TestTypeClusterLister { - return examplev1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Lister() examplev1.TestTypeClusterLister { + return examplev1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -// TestTypeInformer provides access to a shared informer and lister for -// TestTypes. -type TestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() examplev1listers.TestTypeLister +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister examplev1listers.TestTypeLister + lister examplev1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() examplev1listers.TestTypeLister { - return f.lister +func (i *testTypeInformer) Lister() examplev1.TestTypeLister { + return i.lister +} + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev1.TestTypeLister } type testTypeScopedInformer struct { @@ -135,48 +139,48 @@ type testTypeScopedInformer struct { namespace string } -func (f *testTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1.TestType{}, f.defaultInformer) -} - -func (f *testTypeScopedInformer) Lister() examplev1listers.TestTypeLister { - return examplev1listers.NewTestTypeLister(f.Informer().GetIndexer()) -} - // NewTestTypeInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { +func NewTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredTestTypeInformer(client, resyncPeriod, namespace, indexers, nil) } // NewFilteredTestTypeInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().TestTypes(namespace).List(context.TODO(), options) + return client.ExampleV1().TestTypes(namespace).List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().TestTypes(namespace).Watch(context.TODO(), options) + return client.ExampleV1().TestTypes(namespace).Watch(context.Background(), options) }, }, - &examplev1.TestType{}, + &apisexamplev1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredTestTypeInformer(client, resyncPeriod, f.namespace, cache.Indexers{ +func (i *testTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1.TestType{}, i.defaultInformer) +} + +func (i *testTypeScopedInformer) Lister() examplev1.TestTypeLister { + return examplev1.NewTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *testTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, i.namespace, cache.Indexers{ cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, - }, f.tweakListOptions) + }, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/clustertesttype.go index ecabffe7c..0648999a5 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1alpha1 import ( - "context" - "time" + context "context" + time "time" + + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + examplev1alpha1 "acme.corp/pkg/kcp/clients/listers/example/v1alpha1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - examplev1alpha1listers "acme.corp/pkg/kcp/clients/listers/example/v1alpha1" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1alpha1listers.ClusterTestTypeClusterLister + Lister() examplev1alpha1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -57,76 +55,82 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV1alpha1().ClusterTestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV1alpha1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &examplev1alpha1.ClusterTestType{}, + &apisexamplev1alpha1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev1alpha1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1alpha1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Lister() examplev1alpha1listers.ClusterTestTypeClusterLister { - return examplev1alpha1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Lister() examplev1alpha1.ClusterTestTypeClusterLister { + return examplev1alpha1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -// ClusterTestTypeInformer provides access to a shared informer and lister for -// ClusterTestTypes. -type ClusterTestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() examplev1alpha1listers.ClusterTestTypeLister +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister examplev1alpha1listers.ClusterTestTypeLister + lister examplev1alpha1.ClusterTestTypeLister +} + +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Lister() examplev1alpha1.ClusterTestTypeLister { + return i.lister } -func (f *clusterTestTypeInformer) Lister() examplev1alpha1listers.ClusterTestTypeLister { - return f.lister +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev1alpha1.ClusterTestTypeLister } type clusterTestTypeScopedInformer struct { @@ -134,46 +138,46 @@ type clusterTestTypeScopedInformer struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -func (f *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1alpha1.ClusterTestType{}, f.defaultInformer) -} - -func (f *clusterTestTypeScopedInformer) Lister() examplev1alpha1listers.ClusterTestTypeLister { - return examplev1alpha1listers.NewClusterTestTypeLister(f.Informer().GetIndexer()) -} - // NewClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { +func NewClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV1alpha1().ClusterTestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV1alpha1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &examplev1alpha1.ClusterTestType{}, + &apisexamplev1alpha1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) +func (i *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1alpha1.ClusterTestType{}, i.defaultInformer) +} + +func (i *clusterTestTypeScopedInformer) Lister() examplev1alpha1.ClusterTestTypeLister { + return examplev1alpha1.NewClusterTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/interface.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/interface.go index c57b8de35..e63e9ce82 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1alpha1 import ( - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // TestTypes returns a TestTypeClusterInformer - TestTypes() TestTypeClusterInformer - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -37,26 +34,26 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// TestTypes returns a TestTypeClusterInformer -func (v *version) TestTypes() TestTypeClusterInformer { - return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + type Interface interface { - // TestTypes returns a TestTypeInformer - TestTypes() TestTypeInformer - // ClusterTestTypes returns a ClusterTestTypeInformer + // ClusterTestTypes returns a ClusterTestTypeInformer. ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer } type scopedVersion struct { @@ -65,17 +62,17 @@ type scopedVersion struct { namespace string } -// New returns a new ClusterInterface. +// New returns a new Interface. func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &scopedVersion{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// TestTypes returns a TestTypeInformer -func (v *scopedVersion) TestTypes() TestTypeInformer { - return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} + return &scopedVersion{factory: f, tweakListOptions: tweakListOptions} } -// ClusterTestTypes returns a ClusterTestTypeInformer +// ClusterTestTypes returns a ClusterTestTypeInformer. func (v *scopedVersion) ClusterTestTypes() ClusterTestTypeInformer { return &clusterTestTypeScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeInformer. +func (v *scopedVersion) TestTypes() TestTypeInformer { + return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/testtype.go index 4fd69274f..e90c65225 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1alpha1 import ( - "context" - "time" + context "context" + time "time" + + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + examplev1alpha1 "acme.corp/pkg/kcp/clients/listers/example/v1alpha1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - examplev1alpha1listers "acme.corp/pkg/kcp/clients/listers/example/v1alpha1" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1alpha1listers.TestTypeClusterLister + Lister() examplev1alpha1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -57,76 +55,82 @@ type testTypeClusterInformer struct { // NewTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().TestTypes().List(context.TODO(), options) + return client.ExampleV1alpha1().TestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().TestTypes().Watch(context.TODO(), options) + return client.ExampleV1alpha1().TestTypes().Watch(context.Background(), options) }, }, - &examplev1alpha1.TestType{}, + &apisexamplev1alpha1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, - f.tweakListOptions, - ) + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev1alpha1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1alpha1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Lister() examplev1alpha1listers.TestTypeClusterLister { - return examplev1alpha1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Lister() examplev1alpha1.TestTypeClusterLister { + return examplev1alpha1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -// TestTypeInformer provides access to a shared informer and lister for -// TestTypes. -type TestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() examplev1alpha1listers.TestTypeLister +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister examplev1alpha1listers.TestTypeLister + lister examplev1alpha1.TestTypeLister +} + +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Lister() examplev1alpha1.TestTypeLister { + return i.lister } -func (f *testTypeInformer) Lister() examplev1alpha1listers.TestTypeLister { - return f.lister +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev1alpha1.TestTypeLister } type testTypeScopedInformer struct { @@ -135,48 +139,48 @@ type testTypeScopedInformer struct { namespace string } -func (f *testTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1alpha1.TestType{}, f.defaultInformer) -} - -func (f *testTypeScopedInformer) Lister() examplev1alpha1listers.TestTypeLister { - return examplev1alpha1listers.NewTestTypeLister(f.Informer().GetIndexer()) -} - // NewTestTypeInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { +func NewTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredTestTypeInformer(client, resyncPeriod, namespace, indexers, nil) } // NewFilteredTestTypeInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().TestTypes(namespace).List(context.TODO(), options) + return client.ExampleV1alpha1().TestTypes(namespace).List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().TestTypes(namespace).Watch(context.TODO(), options) + return client.ExampleV1alpha1().TestTypes(namespace).Watch(context.Background(), options) }, }, - &examplev1alpha1.TestType{}, + &apisexamplev1alpha1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredTestTypeInformer(client, resyncPeriod, f.namespace, cache.Indexers{ +func (i *testTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1alpha1.TestType{}, i.defaultInformer) +} + +func (i *testTypeScopedInformer) Lister() examplev1alpha1.TestTypeLister { + return examplev1alpha1.NewTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *testTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, i.namespace, cache.Indexers{ cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, - }, f.tweakListOptions) + }, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/clustertesttype.go index c3034154a..302c3833c 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1beta1 import ( - "context" - "time" + context "context" + time "time" + + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + examplev1beta1 "acme.corp/pkg/kcp/clients/listers/example/v1beta1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - examplev1beta1listers "acme.corp/pkg/kcp/clients/listers/example/v1beta1" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1beta1listers.ClusterTestTypeClusterLister + Lister() examplev1beta1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -57,76 +55,82 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1beta1().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV1beta1().ClusterTestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1beta1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV1beta1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &examplev1beta1.ClusterTestType{}, + &apisexamplev1beta1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev1beta1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1beta1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Lister() examplev1beta1listers.ClusterTestTypeClusterLister { - return examplev1beta1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Lister() examplev1beta1.ClusterTestTypeClusterLister { + return examplev1beta1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -// ClusterTestTypeInformer provides access to a shared informer and lister for -// ClusterTestTypes. -type ClusterTestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() examplev1beta1listers.ClusterTestTypeLister +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister examplev1beta1listers.ClusterTestTypeLister + lister examplev1beta1.ClusterTestTypeLister +} + +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Lister() examplev1beta1.ClusterTestTypeLister { + return i.lister } -func (f *clusterTestTypeInformer) Lister() examplev1beta1listers.ClusterTestTypeLister { - return f.lister +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev1beta1.ClusterTestTypeLister } type clusterTestTypeScopedInformer struct { @@ -134,46 +138,46 @@ type clusterTestTypeScopedInformer struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -func (f *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1beta1.ClusterTestType{}, f.defaultInformer) -} - -func (f *clusterTestTypeScopedInformer) Lister() examplev1beta1listers.ClusterTestTypeLister { - return examplev1beta1listers.NewClusterTestTypeLister(f.Informer().GetIndexer()) -} - // NewClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { +func NewClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1beta1().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV1beta1().ClusterTestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1beta1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV1beta1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &examplev1beta1.ClusterTestType{}, + &apisexamplev1beta1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) +func (i *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1beta1.ClusterTestType{}, i.defaultInformer) +} + +func (i *clusterTestTypeScopedInformer) Lister() examplev1beta1.ClusterTestTypeLister { + return examplev1beta1.NewClusterTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/interface.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/interface.go index 758358ee6..12cc5c282 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,17 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1beta1 import ( - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -35,19 +34,26 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + type Interface interface { - // ClusterTestTypes returns a ClusterTestTypeInformer + // ClusterTestTypes returns a ClusterTestTypeInformer. ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer } type scopedVersion struct { @@ -56,12 +62,17 @@ type scopedVersion struct { namespace string } -// New returns a new ClusterInterface. +// New returns a new Interface. func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &scopedVersion{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} + return &scopedVersion{factory: f, tweakListOptions: tweakListOptions} } -// ClusterTestTypes returns a ClusterTestTypeInformer +// ClusterTestTypes returns a ClusterTestTypeInformer. func (v *scopedVersion) ClusterTestTypes() ClusterTestTypeInformer { return &clusterTestTypeScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeInformer. +func (v *scopedVersion) TestTypes() TestTypeInformer { + return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/testtype.go new file mode 100644 index 000000000..b94b41a2b --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/testtype.go @@ -0,0 +1,186 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + context "context" + time "time" + + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + examplev1beta1 "acme.corp/pkg/kcp/clients/listers/example/v1beta1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" +) + +// TestTypeClusterInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeClusterInformer interface { + Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() examplev1beta1.TestTypeClusterLister +} + +type testTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewTestTypeClusterInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { + return kcpinformers.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1beta1().TestTypes().List(context.Background(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1beta1().TestTypes().Watch(context.Background(), options) + }, + }, + &apisexamplev1beta1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1beta1.TestType{}, i.defaultInformer) +} + +func (i *testTypeClusterInformer) Lister() examplev1beta1.TestTypeClusterLister { + return examplev1beta1.NewTestTypeClusterLister(i.Informer().GetIndexer()) +} + +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +type testTypeInformer struct { + informer cache.SharedIndexInformer + lister examplev1beta1.TestTypeLister +} + +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer +} + +func (i *testTypeInformer) Lister() examplev1beta1.TestTypeLister { + return i.lister +} + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev1beta1.TestTypeLister +} + +type testTypeScopedInformer struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, namespace, indexers, nil) +} + +// NewFilteredTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1beta1().TestTypes(namespace).List(context.Background(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1beta1().TestTypes(namespace).Watch(context.Background(), options) + }, + }, + &apisexamplev1beta1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (i *testTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1beta1.TestType{}, i.defaultInformer) +} + +func (i *testTypeScopedInformer) Lister() examplev1beta1.TestTypeLister { + return examplev1beta1.NewTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *testTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, i.namespace, cache.Indexers{ + cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, + }, i.tweakListOptions) +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v2/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v2/clustertesttype.go index 90754cc30..0eb235368 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v2/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v2/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v2 import ( - "context" - "time" + context "context" + time "time" + + apisexamplev2 "acme.corp/pkg/apis/example/v2" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + examplev2 "acme.corp/pkg/kcp/clients/listers/example/v2" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev2 "acme.corp/pkg/apis/example/v2" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - examplev2listers "acme.corp/pkg/kcp/clients/listers/example/v2" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev2listers.ClusterTestTypeClusterLister + Lister() examplev2.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -57,76 +55,82 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV2().ClusterTestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV2().ClusterTestTypes().Watch(context.Background(), options) }, }, - &examplev2.ClusterTestType{}, + &apisexamplev2.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev2.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev2.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Lister() examplev2listers.ClusterTestTypeClusterLister { - return examplev2listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Lister() examplev2.ClusterTestTypeClusterLister { + return examplev2.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -// ClusterTestTypeInformer provides access to a shared informer and lister for -// ClusterTestTypes. -type ClusterTestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() examplev2listers.ClusterTestTypeLister +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister examplev2listers.ClusterTestTypeLister + lister examplev2.ClusterTestTypeLister +} + +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Lister() examplev2.ClusterTestTypeLister { + return i.lister } -func (f *clusterTestTypeInformer) Lister() examplev2listers.ClusterTestTypeLister { - return f.lister +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev2.ClusterTestTypeLister } type clusterTestTypeScopedInformer struct { @@ -134,46 +138,46 @@ type clusterTestTypeScopedInformer struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -func (f *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev2.ClusterTestType{}, f.defaultInformer) -} - -func (f *clusterTestTypeScopedInformer) Lister() examplev2listers.ClusterTestTypeLister { - return examplev2listers.NewClusterTestTypeLister(f.Informer().GetIndexer()) -} - // NewClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { +func NewClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV2().ClusterTestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV2().ClusterTestTypes().Watch(context.Background(), options) }, }, - &examplev2.ClusterTestType{}, + &apisexamplev2.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) +func (i *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexamplev2.ClusterTestType{}, i.defaultInformer) +} + +func (i *clusterTestTypeScopedInformer) Lister() examplev2.ClusterTestTypeLister { + return examplev2.NewClusterTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v2/interface.go b/examples/pkg/kcp/clients/informers/externalversions/example/v2/interface.go index 6a7bbd3da..b5089ba33 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v2/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v2/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v2 import ( - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // TestTypes returns a TestTypeClusterInformer - TestTypes() TestTypeClusterInformer - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -37,26 +34,26 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// TestTypes returns a TestTypeClusterInformer -func (v *version) TestTypes() TestTypeClusterInformer { - return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + type Interface interface { - // TestTypes returns a TestTypeInformer - TestTypes() TestTypeInformer - // ClusterTestTypes returns a ClusterTestTypeInformer + // ClusterTestTypes returns a ClusterTestTypeInformer. ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer } type scopedVersion struct { @@ -65,17 +62,17 @@ type scopedVersion struct { namespace string } -// New returns a new ClusterInterface. +// New returns a new Interface. func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &scopedVersion{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// TestTypes returns a TestTypeInformer -func (v *scopedVersion) TestTypes() TestTypeInformer { - return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} + return &scopedVersion{factory: f, tweakListOptions: tweakListOptions} } -// ClusterTestTypes returns a ClusterTestTypeInformer +// ClusterTestTypes returns a ClusterTestTypeInformer. func (v *scopedVersion) ClusterTestTypes() ClusterTestTypeInformer { return &clusterTestTypeScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeInformer. +func (v *scopedVersion) TestTypes() TestTypeInformer { + return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v2/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v2/testtype.go index 1502cee98..02c17d0fb 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v2/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v2/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v2 import ( - "context" - "time" + context "context" + time "time" + + apisexamplev2 "acme.corp/pkg/apis/example/v2" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + examplev2 "acme.corp/pkg/kcp/clients/listers/example/v2" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev2 "acme.corp/pkg/apis/example/v2" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - examplev2listers "acme.corp/pkg/kcp/clients/listers/example/v2" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev2listers.TestTypeClusterLister + Lister() examplev2.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -57,76 +55,82 @@ type testTypeClusterInformer struct { // NewTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().TestTypes().List(context.TODO(), options) + return client.ExampleV2().TestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().TestTypes().Watch(context.TODO(), options) + return client.ExampleV2().TestTypes().Watch(context.Background(), options) }, }, - &examplev2.TestType{}, + &apisexamplev2.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, - f.tweakListOptions, - ) + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev2.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev2.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Lister() examplev2listers.TestTypeClusterLister { - return examplev2listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Lister() examplev2.TestTypeClusterLister { + return examplev2.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -// TestTypeInformer provides access to a shared informer and lister for -// TestTypes. -type TestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() examplev2listers.TestTypeLister +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister examplev2listers.TestTypeLister + lister examplev2.TestTypeLister +} + +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Lister() examplev2.TestTypeLister { + return i.lister } -func (f *testTypeInformer) Lister() examplev2listers.TestTypeLister { - return f.lister +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev2.TestTypeLister } type testTypeScopedInformer struct { @@ -135,48 +139,48 @@ type testTypeScopedInformer struct { namespace string } -func (f *testTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev2.TestType{}, f.defaultInformer) -} - -func (f *testTypeScopedInformer) Lister() examplev2listers.TestTypeLister { - return examplev2listers.NewTestTypeLister(f.Informer().GetIndexer()) -} - // NewTestTypeInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { +func NewTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredTestTypeInformer(client, resyncPeriod, namespace, indexers, nil) } // NewFilteredTestTypeInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().TestTypes(namespace).List(context.TODO(), options) + return client.ExampleV2().TestTypes(namespace).List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().TestTypes(namespace).Watch(context.TODO(), options) + return client.ExampleV2().TestTypes(namespace).Watch(context.Background(), options) }, }, - &examplev2.TestType{}, + &apisexamplev2.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredTestTypeInformer(client, resyncPeriod, f.namespace, cache.Indexers{ +func (i *testTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexamplev2.TestType{}, i.defaultInformer) +} + +func (i *testTypeScopedInformer) Lister() examplev2.TestTypeLister { + return examplev2.NewTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *testTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, i.namespace, cache.Indexers{ cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, - }, f.tweakListOptions) + }, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/example3/interface.go b/examples/pkg/kcp/clients/informers/externalversions/example3/interface.go index b15357f83..2cade5d19 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example3/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example3/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,17 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package example3 import ( - "acme.corp/pkg/kcp/clients/informers/externalversions/example3/v1" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + v1 "acme.corp/pkg/kcp/clients/informers/externalversions/example3/v1" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" ) +// ClusterInterface provides access to each of this group's versions. type ClusterInterface interface { - // V1 provides access to the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.ClusterInterface } @@ -46,8 +44,9 @@ func (g *group) V1() v1.ClusterInterface { return v1.New(g.factory, g.tweakListOptions) } +// Interface provides access to each of this group's versions. type Interface interface { - // V1 provides access to the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.Interface } @@ -62,7 +61,7 @@ func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace strin return &scopedGroup{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// V1 returns a new v1.ClusterInterface. +// V1 returns a new v1.Interface. func (g *scopedGroup) V1() v1.Interface { return v1.NewScoped(g.factory, g.namespace, g.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/clustertesttype.go index 1e7fa3065..b99a0822f 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + example3v1 "acme.corp/pkg/kcp/clients/listers/example3/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - example3v1 "acme.corp/pkg/apis/example3/v1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - example3v1listers "acme.corp/pkg/kcp/clients/listers/example3/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() example3v1listers.ClusterTestTypeClusterLister + Lister() example3v1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -57,76 +55,82 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().ClusterTestTypes().List(context.TODO(), options) + return client.Example3V1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().ClusterTestTypes().Watch(context.TODO(), options) + return client.Example3V1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &example3v1.ClusterTestType{}, + &apisexample3v1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&example3v1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexample3v1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Lister() example3v1listers.ClusterTestTypeClusterLister { - return example3v1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Lister() example3v1.ClusterTestTypeClusterLister { + return example3v1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -// ClusterTestTypeInformer provides access to a shared informer and lister for -// ClusterTestTypes. -type ClusterTestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() example3v1listers.ClusterTestTypeLister +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister example3v1listers.ClusterTestTypeLister + lister example3v1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() example3v1listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() example3v1.ClusterTestTypeLister { + return i.lister +} + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() example3v1.ClusterTestTypeLister } type clusterTestTypeScopedInformer struct { @@ -134,46 +138,46 @@ type clusterTestTypeScopedInformer struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -func (f *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&example3v1.ClusterTestType{}, f.defaultInformer) -} - -func (f *clusterTestTypeScopedInformer) Lister() example3v1listers.ClusterTestTypeLister { - return example3v1listers.NewClusterTestTypeLister(f.Informer().GetIndexer()) -} - // NewClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { +func NewClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().ClusterTestTypes().List(context.TODO(), options) + return client.Example3V1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().ClusterTestTypes().Watch(context.TODO(), options) + return client.Example3V1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &example3v1.ClusterTestType{}, + &apisexample3v1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) +func (i *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexample3v1.ClusterTestType{}, i.defaultInformer) +} + +func (i *clusterTestTypeScopedInformer) Lister() example3v1.ClusterTestTypeLister { + return example3v1.NewClusterTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/interface.go b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/interface.go index 3034bb594..e632b7bcb 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // TestTypes returns a TestTypeClusterInformer - TestTypes() TestTypeClusterInformer - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -37,26 +34,26 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// TestTypes returns a TestTypeClusterInformer -func (v *version) TestTypes() TestTypeClusterInformer { - return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + type Interface interface { - // TestTypes returns a TestTypeInformer - TestTypes() TestTypeInformer - // ClusterTestTypes returns a ClusterTestTypeInformer + // ClusterTestTypes returns a ClusterTestTypeInformer. ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer } type scopedVersion struct { @@ -65,17 +62,17 @@ type scopedVersion struct { namespace string } -// New returns a new ClusterInterface. +// New returns a new Interface. func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &scopedVersion{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// TestTypes returns a TestTypeInformer -func (v *scopedVersion) TestTypes() TestTypeInformer { - return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} + return &scopedVersion{factory: f, tweakListOptions: tweakListOptions} } -// ClusterTestTypes returns a ClusterTestTypeInformer +// ClusterTestTypes returns a ClusterTestTypeInformer. func (v *scopedVersion) ClusterTestTypes() ClusterTestTypeInformer { return &clusterTestTypeScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeInformer. +func (v *scopedVersion) TestTypes() TestTypeInformer { + return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/testtype.go index 4abedd49b..78a4b59c8 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + example3v1 "acme.corp/pkg/kcp/clients/listers/example3/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - example3v1 "acme.corp/pkg/apis/example3/v1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - example3v1listers "acme.corp/pkg/kcp/clients/listers/example3/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() example3v1listers.TestTypeClusterLister + Lister() example3v1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -57,76 +55,82 @@ type testTypeClusterInformer struct { // NewTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().TestTypes().List(context.TODO(), options) + return client.Example3V1().TestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().TestTypes().Watch(context.TODO(), options) + return client.Example3V1().TestTypes().Watch(context.Background(), options) }, }, - &example3v1.TestType{}, + &apisexample3v1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, - f.tweakListOptions, - ) + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&example3v1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexample3v1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Lister() example3v1listers.TestTypeClusterLister { - return example3v1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Lister() example3v1.TestTypeClusterLister { + return example3v1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -// TestTypeInformer provides access to a shared informer and lister for -// TestTypes. -type TestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() example3v1listers.TestTypeLister +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister example3v1listers.TestTypeLister + lister example3v1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() example3v1listers.TestTypeLister { - return f.lister +func (i *testTypeInformer) Lister() example3v1.TestTypeLister { + return i.lister +} + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() example3v1.TestTypeLister } type testTypeScopedInformer struct { @@ -135,48 +139,48 @@ type testTypeScopedInformer struct { namespace string } -func (f *testTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&example3v1.TestType{}, f.defaultInformer) -} - -func (f *testTypeScopedInformer) Lister() example3v1listers.TestTypeLister { - return example3v1listers.NewTestTypeLister(f.Informer().GetIndexer()) -} - // NewTestTypeInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { +func NewTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredTestTypeInformer(client, resyncPeriod, namespace, indexers, nil) } // NewFilteredTestTypeInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().TestTypes(namespace).List(context.TODO(), options) + return client.Example3V1().TestTypes(namespace).List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().TestTypes(namespace).Watch(context.TODO(), options) + return client.Example3V1().TestTypes(namespace).Watch(context.Background(), options) }, }, - &example3v1.TestType{}, + &apisexample3v1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredTestTypeInformer(client, resyncPeriod, f.namespace, cache.Indexers{ +func (i *testTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexample3v1.TestType{}, i.defaultInformer) +} + +func (i *testTypeScopedInformer) Lister() example3v1.TestTypeLister { + return example3v1.NewTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *testTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, i.namespace, cache.Indexers{ cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, - }, f.tweakListOptions) + }, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/interface.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/interface.go new file mode 100644 index 000000000..024d025d8 --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/interface.go @@ -0,0 +1,67 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-informer-gen. DO NOT EDIT. + +package exampledashed + +import ( + v1 "acme.corp/pkg/kcp/clients/informers/externalversions/exampledashed/v1" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" +) + +// ClusterInterface provides access to each of this group's versions. +type ClusterInterface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.ClusterInterface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new ClusterInterface. +func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { + return &group{factory: f, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.ClusterInterface. +func (g *group) V1() v1.ClusterInterface { + return v1.New(g.factory, g.tweakListOptions) +} + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface +} + +type scopedGroup struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// New returns a new Interface. +func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &scopedGroup{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.Interface. +func (g *scopedGroup) V1() v1.Interface { + return v1.NewScoped(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..fb30b30ca --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go @@ -0,0 +1,183 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-informer-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + time "time" + + apisexampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + exampledashedv1 "acme.corp/pkg/kcp/clients/listers/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" +) + +// ClusterTestTypeClusterInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeClusterInformer interface { + Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv1.ClusterTestTypeClusterLister +} + +type clusterTestTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { + return kcpinformers.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().List(context.Background(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().Watch(context.Background(), options) + }, + }, + &apisexampledashedv1.ClusterTestType{}, + resyncPeriod, + indexers, + ) +} + +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexampledashedv1.ClusterTestType{}, i.defaultInformer) +} + +func (i *clusterTestTypeClusterInformer) Lister() exampledashedv1.ClusterTestTypeClusterLister { + return exampledashedv1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +type clusterTestTypeInformer struct { + informer cache.SharedIndexInformer + lister exampledashedv1.ClusterTestTypeLister +} + +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer +} + +func (i *clusterTestTypeInformer) Lister() exampledashedv1.ClusterTestTypeLister { + return i.lister +} + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() exampledashedv1.ClusterTestTypeLister +} + +type clusterTestTypeScopedInformer struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewClusterTestTypeInformer constructs a new informer for ClusterTestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().List(context.Background(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().Watch(context.Background(), options) + }, + }, + &apisexampledashedv1.ClusterTestType{}, + resyncPeriod, + indexers, + ) +} + +func (i *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexampledashedv1.ClusterTestType{}, i.defaultInformer) +} + +func (i *clusterTestTypeScopedInformer) Lister() exampledashedv1.ClusterTestTypeLister { + return exampledashedv1.NewClusterTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, i.tweakListOptions) +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/interface.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/interface.go new file mode 100644 index 000000000..e632b7bcb --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/interface.go @@ -0,0 +1,78 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-informer-gen. DO NOT EDIT. + +package v1 + +import ( + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. + ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { + return &version{factory: f, tweakListOptions: tweakListOptions} +} + +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. +func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { + return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +type Interface interface { + // ClusterTestTypes returns a ClusterTestTypeInformer. + ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer +} + +type scopedVersion struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// New returns a new Interface. +func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &scopedVersion{factory: f, tweakListOptions: tweakListOptions} +} + +// ClusterTestTypes returns a ClusterTestTypeInformer. +func (v *scopedVersion) ClusterTestTypes() ClusterTestTypeInformer { + return &clusterTestTypeScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// TestTypes returns a TestTypeInformer. +func (v *scopedVersion) TestTypes() TestTypeInformer { + return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go new file mode 100644 index 000000000..eba52923c --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go @@ -0,0 +1,186 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-informer-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + time "time" + + apisexampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + exampledashedv1 "acme.corp/pkg/kcp/clients/listers/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" +) + +// TestTypeClusterInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeClusterInformer interface { + Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv1.TestTypeClusterLister +} + +type testTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewTestTypeClusterInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { + return kcpinformers.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes().List(context.Background(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes().Watch(context.Background(), options) + }, + }, + &apisexampledashedv1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexampledashedv1.TestType{}, i.defaultInformer) +} + +func (i *testTypeClusterInformer) Lister() exampledashedv1.TestTypeClusterLister { + return exampledashedv1.NewTestTypeClusterLister(i.Informer().GetIndexer()) +} + +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +type testTypeInformer struct { + informer cache.SharedIndexInformer + lister exampledashedv1.TestTypeLister +} + +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer +} + +func (i *testTypeInformer) Lister() exampledashedv1.TestTypeLister { + return i.lister +} + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() exampledashedv1.TestTypeLister +} + +type testTypeScopedInformer struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, namespace, indexers, nil) +} + +// NewFilteredTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes(namespace).List(context.Background(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes(namespace).Watch(context.Background(), options) + }, + }, + &apisexampledashedv1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (i *testTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexampledashedv1.TestType{}, i.defaultInformer) +} + +func (i *testTypeScopedInformer) Lister() exampledashedv1.TestTypeLister { + return exampledashedv1.NewTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *testTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, i.namespace, cache.Indexers{ + cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, + }, i.tweakListOptions) +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/interface.go b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/interface.go index c9604e96e..f08874be4 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,17 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package existinginterfaces import ( - "acme.corp/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + v1 "acme.corp/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" ) +// ClusterInterface provides access to each of this group's versions. type ClusterInterface interface { - // V1 provides access to the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.ClusterInterface } @@ -46,8 +44,9 @@ func (g *group) V1() v1.ClusterInterface { return v1.New(g.factory, g.tweakListOptions) } +// Interface provides access to each of this group's versions. type Interface interface { - // V1 provides access to the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.Interface } @@ -62,7 +61,7 @@ func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace strin return &scopedGroup{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// V1 returns a new v1.ClusterInterface. +// V1 returns a new v1.Interface. func (g *scopedGroup) V1() v1.Interface { return v1.NewScoped(g.factory, g.namespace, g.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go index 546b9b6a9..9eb4b1659 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + existinginterfacesv1 "acme.corp/pkg/kcp/clients/listers/existinginterfaces/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - existinginterfacesv1listers "acme.corp/pkg/kcp/clients/listers/existinginterfaces/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() existinginterfacesv1listers.ClusterTestTypeClusterLister + Lister() existinginterfacesv1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -57,76 +55,82 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().ClusterTestTypes().List(context.TODO(), options) + return client.ExistinginterfacesV1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExistinginterfacesV1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &existinginterfacesv1.ClusterTestType{}, + &apisexistinginterfacesv1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&existinginterfacesv1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexistinginterfacesv1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Lister() existinginterfacesv1listers.ClusterTestTypeClusterLister { - return existinginterfacesv1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Lister() existinginterfacesv1.ClusterTestTypeClusterLister { + return existinginterfacesv1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -// ClusterTestTypeInformer provides access to a shared informer and lister for -// ClusterTestTypes. -type ClusterTestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() existinginterfacesv1listers.ClusterTestTypeLister +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister existinginterfacesv1listers.ClusterTestTypeLister + lister existinginterfacesv1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() existinginterfacesv1listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() existinginterfacesv1.ClusterTestTypeLister { + return i.lister +} + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() existinginterfacesv1.ClusterTestTypeLister } type clusterTestTypeScopedInformer struct { @@ -134,46 +138,46 @@ type clusterTestTypeScopedInformer struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -func (f *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&existinginterfacesv1.ClusterTestType{}, f.defaultInformer) -} - -func (f *clusterTestTypeScopedInformer) Lister() existinginterfacesv1listers.ClusterTestTypeLister { - return existinginterfacesv1listers.NewClusterTestTypeLister(f.Informer().GetIndexer()) -} - // NewClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { +func NewClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().ClusterTestTypes().List(context.TODO(), options) + return client.ExistinginterfacesV1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExistinginterfacesV1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &existinginterfacesv1.ClusterTestType{}, + &apisexistinginterfacesv1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) +func (i *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexistinginterfacesv1.ClusterTestType{}, i.defaultInformer) +} + +func (i *clusterTestTypeScopedInformer) Lister() existinginterfacesv1.ClusterTestTypeLister { + return existinginterfacesv1.NewClusterTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/interface.go b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/interface.go index 3034bb594..e632b7bcb 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // TestTypes returns a TestTypeClusterInformer - TestTypes() TestTypeClusterInformer - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -37,26 +34,26 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// TestTypes returns a TestTypeClusterInformer -func (v *version) TestTypes() TestTypeClusterInformer { - return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + type Interface interface { - // TestTypes returns a TestTypeInformer - TestTypes() TestTypeInformer - // ClusterTestTypes returns a ClusterTestTypeInformer + // ClusterTestTypes returns a ClusterTestTypeInformer. ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer } type scopedVersion struct { @@ -65,17 +62,17 @@ type scopedVersion struct { namespace string } -// New returns a new ClusterInterface. +// New returns a new Interface. func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &scopedVersion{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// TestTypes returns a TestTypeInformer -func (v *scopedVersion) TestTypes() TestTypeInformer { - return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} + return &scopedVersion{factory: f, tweakListOptions: tweakListOptions} } -// ClusterTestTypes returns a ClusterTestTypeInformer +// ClusterTestTypes returns a ClusterTestTypeInformer. func (v *scopedVersion) ClusterTestTypes() ClusterTestTypeInformer { return &clusterTestTypeScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeInformer. +func (v *scopedVersion) TestTypes() TestTypeInformer { + return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/testtype.go index 1375195f5..75807a57a 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + existinginterfacesv1 "acme.corp/pkg/kcp/clients/listers/existinginterfaces/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - existinginterfacesv1listers "acme.corp/pkg/kcp/clients/listers/existinginterfaces/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() existinginterfacesv1listers.TestTypeClusterLister + Lister() existinginterfacesv1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -57,76 +55,82 @@ type testTypeClusterInformer struct { // NewTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().TestTypes().List(context.TODO(), options) + return client.ExistinginterfacesV1().TestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().TestTypes().Watch(context.TODO(), options) + return client.ExistinginterfacesV1().TestTypes().Watch(context.Background(), options) }, }, - &existinginterfacesv1.TestType{}, + &apisexistinginterfacesv1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, - f.tweakListOptions, - ) + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&existinginterfacesv1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexistinginterfacesv1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Lister() existinginterfacesv1listers.TestTypeClusterLister { - return existinginterfacesv1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Lister() existinginterfacesv1.TestTypeClusterLister { + return existinginterfacesv1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -// TestTypeInformer provides access to a shared informer and lister for -// TestTypes. -type TestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() existinginterfacesv1listers.TestTypeLister +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister existinginterfacesv1listers.TestTypeLister + lister existinginterfacesv1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() existinginterfacesv1listers.TestTypeLister { - return f.lister +func (i *testTypeInformer) Lister() existinginterfacesv1.TestTypeLister { + return i.lister +} + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() existinginterfacesv1.TestTypeLister } type testTypeScopedInformer struct { @@ -135,48 +139,48 @@ type testTypeScopedInformer struct { namespace string } -func (f *testTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&existinginterfacesv1.TestType{}, f.defaultInformer) -} - -func (f *testTypeScopedInformer) Lister() existinginterfacesv1listers.TestTypeLister { - return existinginterfacesv1listers.NewTestTypeLister(f.Informer().GetIndexer()) -} - // NewTestTypeInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { +func NewTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredTestTypeInformer(client, resyncPeriod, namespace, indexers, nil) } // NewFilteredTestTypeInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().TestTypes(namespace).List(context.TODO(), options) + return client.ExistinginterfacesV1().TestTypes(namespace).List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().TestTypes(namespace).Watch(context.TODO(), options) + return client.ExistinginterfacesV1().TestTypes(namespace).Watch(context.Background(), options) }, }, - &existinginterfacesv1.TestType{}, + &apisexistinginterfacesv1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredTestTypeInformer(client, resyncPeriod, f.namespace, cache.Indexers{ +func (i *testTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apisexistinginterfacesv1.TestType{}, i.defaultInformer) +} + +func (i *testTypeScopedInformer) Lister() existinginterfacesv1.TestTypeLister { + return existinginterfacesv1.NewTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *testTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, i.namespace, cache.Indexers{ cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, - }, f.tweakListOptions) + }, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/factory.go b/examples/pkg/kcp/clients/informers/externalversions/factory.go index 36763ad41..1b46a70c7 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/factory.go +++ b/examples/pkg/kcp/clients/informers/externalversions/factory.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,30 +14,31 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. -package informers +package externalversions import ( - "reflect" - "sync" - "time" + reflect "reflect" + sync "sync" + time "time" + + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + example "acme.corp/pkg/kcp/clients/informers/externalversions/example" + example3 "acme.corp/pkg/kcp/clients/informers/externalversions/example3" + exampledashed "acme.corp/pkg/kcp/clients/informers/externalversions/exampledashed" + existinginterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/existinginterfaces" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + secondexample "acme.corp/pkg/kcp/clients/informers/externalversions/secondexample" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/tools/cache" - - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - exampleinformers "acme.corp/pkg/kcp/clients/informers/externalversions/example" - example3informers "acme.corp/pkg/kcp/clients/informers/externalversions/example3" - existinginterfacesinformers "acme.corp/pkg/kcp/clients/informers/externalversions/existinginterfaces" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - secondexampleinformers "acme.corp/pkg/kcp/clients/informers/externalversions/secondexample" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // SharedInformerOption defines the functional option type for SharedInformerFactory. @@ -49,15 +47,17 @@ type SharedInformerOption func(*SharedInformerOptions) *SharedInformerOptions type SharedInformerOptions struct { customResync map[reflect.Type]time.Duration tweakListOptions internalinterfaces.TweakListOptionsFunc + transform cache.TransformFunc namespace string } type sharedInformerFactory struct { - client clientset.ClusterInterface + client versioned.ClusterInterface tweakListOptions internalinterfaces.TweakListOptionsFunc lock sync.Mutex defaultResync time.Duration customResync map[reflect.Type]time.Duration + transform cache.TransformFunc informers map[reflect.Type]kcpcache.ScopeableSharedIndexInformer // startedInformers is used for tracking which informers have been started. @@ -71,7 +71,7 @@ type sharedInformerFactory struct { } // WithCustomResyncConfig sets a custom resync period for the specified informer types. -func WithCustomResyncConfig(resyncConfig map[metav1.Object]time.Duration) SharedInformerOption { +func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { return func(opts *SharedInformerOptions) *SharedInformerOptions { for k, v := range resyncConfig { opts.customResync[reflect.TypeOf(k)] = v @@ -88,13 +88,29 @@ func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFu } } -// NewSharedInformerFactory constructs a new instance of SharedInformerFactory for all namespaces. -func NewSharedInformerFactory(client clientset.ClusterInterface, defaultResync time.Duration) SharedInformerFactory { +// WithTransform sets a transform on all informers. +func WithTransform(transform cache.TransformFunc) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + opts.transform = transform + return opts + } +} + +// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client versioned.ClusterInterface, defaultResync time.Duration) SharedInformerFactory { return NewSharedInformerFactoryWithOptions(client, defaultResync) } +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +// Deprecated: Please use NewSharedInformerFactoryWithOptions instead +func NewFilteredSharedInformerFactory(client versioned.ClusterInterface, defaultResync time.Duration, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync, WithTweakListOptions(tweakListOptions)) +} + // NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. -func NewSharedInformerFactoryWithOptions(client clientset.ClusterInterface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { +func NewSharedInformerFactoryWithOptions(client versioned.ClusterInterface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { factory := &sharedInformerFactory{ client: client, defaultResync: defaultResync, @@ -115,11 +131,11 @@ func NewSharedInformerFactoryWithOptions(client clientset.ClusterInterface, defa // Forward options to the factory factory.customResync = opts.customResync factory.tweakListOptions = opts.tweakListOptions + factory.transform = opts.transform return factory } -// Start initializes all requested informers. func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { f.lock.Lock() defer f.lock.Unlock() @@ -153,7 +169,6 @@ func (f *sharedInformerFactory) Shutdown() { f.wg.Wait() } -// WaitForCacheSync waits for all started informers' cache were synced. func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { informers := func() map[reflect.Type]kcpcache.ScopeableSharedIndexInformer { f.lock.Lock() @@ -172,10 +187,11 @@ func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[ref for informType, informer := range informers { res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) } + return res } -// InformerFor returns the SharedIndexInformer for obj. +// InformerFor returns the ScopeableSharedIndexInformer for obj using an internal client. func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer { f.lock.Lock() defer f.lock.Unlock() @@ -192,6 +208,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal } informer = newFunc(f.client, resyncPeriod) + informer.SetTransform(f.transform) f.informers[informerType] = informer return informer @@ -213,11 +230,11 @@ type ScopedDynamicSharedInformerFactory interface { // // ctx, cancel := context.Background() // defer cancel() -// factory := NewSharedInformerFactoryWithOptions(client, resyncPeriod) -// defer factory.Shutdown() // Returns immediately if nothing was started. +// factory := NewSharedInformerFactory(client, resyncPeriod) +// defer factory.WaitForStop() // Returns immediately if nothing was started. // genericInformer := factory.ForResource(resource) // typedInformer := factory.SomeAPIGroup().V1().SomeType() -// factory.Start(ctx.Done()) // Start processing these informers. +// factory.Start(ctx.Done()) // Start processing these informers. // synced := factory.WaitForCacheSync(ctx.Done()) // for v, ok := range synced { // if !ok { @@ -237,6 +254,7 @@ type SharedInformerFactory interface { // Start initializes all requested informers. They are handled in goroutines // which run until the stop channel gets closed. + // Warning: Start does not block. When run in a go-routine, it will race with a later WaitForCacheSync. Start(stopCh <-chan struct{}) // Shutdown marks a factory as shutting down. At that point no new @@ -251,36 +269,42 @@ type SharedInformerFactory interface { // block until all goroutines have terminated. Shutdown() - // ForResource gives generic access to a shared informer of the matching type. - ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) - // WaitForCacheSync blocks until all started informers' caches were synced // or the stop channel gets closed. WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool - // InformerFor returns the SharedIndexInformer for obj. + // ForResource gives generic access to a shared informer of the matching type. + ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) + + // InformerFor returns the SharedIndexInformer for obj using an internal + // client. InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer - Example() exampleinformers.ClusterInterface - Example3() example3informers.ClusterInterface - Existinginterfaces() existinginterfacesinformers.ClusterInterface - Secondexample() secondexampleinformers.ClusterInterface + Example() example.ClusterInterface + Example3() example3.ClusterInterface + ExampleDashed() exampledashed.ClusterInterface + Existinginterfaces() existinginterfaces.ClusterInterface + Secondexample() secondexample.ClusterInterface } -func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { - return exampleinformers.New(f, f.tweakListOptions) +func (f *sharedInformerFactory) Example() example.ClusterInterface { + return example.New(f, f.tweakListOptions) } -func (f *sharedInformerFactory) Example3() example3informers.ClusterInterface { - return example3informers.New(f, f.tweakListOptions) +func (f *sharedInformerFactory) Example3() example3.ClusterInterface { + return example3.New(f, f.tweakListOptions) } -func (f *sharedInformerFactory) Existinginterfaces() existinginterfacesinformers.ClusterInterface { - return existinginterfacesinformers.New(f, f.tweakListOptions) +func (f *sharedInformerFactory) ExampleDashed() exampledashed.ClusterInterface { + return exampledashed.New(f, f.tweakListOptions) } -func (f *sharedInformerFactory) Secondexample() secondexampleinformers.ClusterInterface { - return secondexampleinformers.New(f, f.tweakListOptions) +func (f *sharedInformerFactory) Existinginterfaces() existinginterfaces.ClusterInterface { + return existinginterfaces.New(f, f.tweakListOptions) +} + +func (f *sharedInformerFactory) Secondexample() secondexample.ClusterInterface { + return secondexample.New(f, f.tweakListOptions) } func (f *sharedInformerFactory) Cluster(clusterName logicalcluster.Name) ScopedDynamicSharedInformerFactory { @@ -316,12 +340,13 @@ func WithNamespace(namespace string) SharedInformerOption { } type sharedScopedInformerFactory struct { - client scopedclientset.Interface - namespace string + client clientsetversioned.Interface tweakListOptions internalinterfaces.TweakListOptionsFunc lock sync.Mutex defaultResync time.Duration customResync map[reflect.Type]time.Duration + transform cache.TransformFunc + namespace string informers map[reflect.Type]cache.SharedIndexInformer // startedInformers is used for tracking which informers have been started. @@ -330,12 +355,12 @@ type sharedScopedInformerFactory struct { } // NewSharedScopedInformerFactory constructs a new instance of SharedInformerFactory for some or all namespaces. -func NewSharedScopedInformerFactory(client scopedclientset.Interface, defaultResync time.Duration, namespace string) SharedScopedInformerFactory { +func NewSharedScopedInformerFactory(client clientsetversioned.Interface, defaultResync time.Duration, namespace string) SharedScopedInformerFactory { return NewSharedScopedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace)) } // NewSharedScopedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. -func NewSharedScopedInformerFactoryWithOptions(client scopedclientset.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedScopedInformerFactory { +func NewSharedScopedInformerFactoryWithOptions(client clientsetversioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedScopedInformerFactory { factory := &sharedScopedInformerFactory{ client: client, defaultResync: defaultResync, @@ -413,6 +438,7 @@ func (f *sharedScopedInformerFactory) InformerFor(obj runtime.Object, newFunc in } informer = newFunc(f.client, resyncPeriod) + informer.SetTransform(f.transform) f.informers[informerType] = informer return informer @@ -425,24 +451,29 @@ type SharedScopedInformerFactory interface { ForResource(resource schema.GroupVersionResource) (GenericInformer, error) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool - Example() exampleinformers.Interface - Example3() example3informers.Interface - Existinginterfaces() existinginterfacesinformers.Interface - Secondexample() secondexampleinformers.Interface + Example() example.Interface + Example3() example3.Interface + ExampleDashed() exampledashed.Interface + Existinginterfaces() existinginterfaces.Interface + Secondexample() secondexample.Interface +} + +func (f *sharedScopedInformerFactory) Example() example.Interface { + return example.NewScoped(f, f.namespace, f.tweakListOptions) } -func (f *sharedScopedInformerFactory) Example() exampleinformers.Interface { - return exampleinformers.NewScoped(f, f.namespace, f.tweakListOptions) +func (f *sharedScopedInformerFactory) Example3() example3.Interface { + return example3.NewScoped(f, f.namespace, f.tweakListOptions) } -func (f *sharedScopedInformerFactory) Example3() example3informers.Interface { - return example3informers.NewScoped(f, f.namespace, f.tweakListOptions) +func (f *sharedScopedInformerFactory) ExampleDashed() exampledashed.Interface { + return exampledashed.NewScoped(f, f.namespace, f.tweakListOptions) } -func (f *sharedScopedInformerFactory) Existinginterfaces() existinginterfacesinformers.Interface { - return existinginterfacesinformers.NewScoped(f, f.namespace, f.tweakListOptions) +func (f *sharedScopedInformerFactory) Existinginterfaces() existinginterfaces.Interface { + return existinginterfaces.NewScoped(f, f.namespace, f.tweakListOptions) } -func (f *sharedScopedInformerFactory) Secondexample() secondexampleinformers.Interface { - return secondexampleinformers.NewScoped(f, f.namespace, f.tweakListOptions) +func (f *sharedScopedInformerFactory) Secondexample() secondexample.Interface { + return secondexample.NewScoped(f, f.namespace, f.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/generic.go b/examples/pkg/kcp/clients/informers/externalversions/generic.go index 02cbb364d..312946367 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcp/clients/informers/externalversions/generic.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,30 +14,33 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. -package informers +package externalversions import ( - "fmt" - - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" - - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/tools/cache" + context "context" + fmt "fmt" examplev1 "acme.corp/pkg/apis/example/v1" - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - examplev2 "acme.corp/pkg/apis/example/v2" + v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + v1beta1 "acme.corp/pkg/apis/example/v1beta1" + v2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + v1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) type GenericClusterInformer interface { Cluster(logicalcluster.Name) GenericInformer + ClusterWithContext(context.Context, logicalcluster.Name) GenericInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() kcpcache.GenericClusterLister } @@ -56,20 +56,29 @@ type genericClusterInformer struct { } // Informer returns the SharedIndexInformer. -func (f *genericClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.informer +func (i *genericClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.informer } -// Lister returns the GenericClusterLister. -func (f *genericClusterInformer) Lister() kcpcache.GenericClusterLister { - return kcpcache.NewGenericClusterLister(f.Informer().GetIndexer(), f.resource) +// Lister returns the GenericLister. +func (i *genericClusterInformer) Lister() kcpcache.GenericClusterLister { + return kcpcache.NewGenericClusterLister(i.Informer().GetIndexer(), i.resource) } // Cluster scopes to a GenericInformer. -func (f *genericClusterInformer) Cluster(clusterName logicalcluster.Name) GenericInformer { +func (i *genericClusterInformer) Cluster(clusterName logicalcluster.Name) GenericInformer { return &genericInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().ByCluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().ByCluster(clusterName), + } +} + +// ClusterWithContext scopes to a GenericInformer and unregisters all +// handles registered through it once the provided context is canceled. +func (i *genericClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) GenericInformer { + return &genericInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().ByCluster(clusterName), } } @@ -79,52 +88,67 @@ type genericInformer struct { } // Informer returns the SharedIndexInformer. -func (f *genericInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *genericInformer) Informer() cache.SharedIndexInformer { + return i.informer } // Lister returns the GenericLister. -func (f *genericInformer) Lister() cache.GenericLister { - return f.lister +func (i *genericInformer) Lister() cache.GenericLister { + return i.lister } // ForResource gives generic access to a shared informer of the matching type // TODO extend this to unknown resources with a client pool func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) { switch resource { - // Group=example3.some.corp, Version=V1 - case example3v1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().TestTypes().Informer()}, nil - case example3v1.SchemeGroupVersion.WithResource("clustertesttypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().ClusterTestTypes().Informer()}, nil - // Group=example, Version=V1 - case examplev1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1().TestTypes().Informer()}, nil + // Group=example-dashed.some.corp, Version=v1 + case v1.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().ClusterTestTypes().Informer()}, nil + case v1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().TestTypes().Informer()}, nil + + // Group=example.dev, Version=v1 case examplev1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1().ClusterTestTypes().Informer()}, nil - // Group=example, Version=V1alpha1 - case examplev1alpha1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1alpha1().TestTypes().Informer()}, nil - case examplev1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"): + case examplev1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1().TestTypes().Informer()}, nil + + // Group=example.dev, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1alpha1().ClusterTestTypes().Informer()}, nil - // Group=example, Version=V1beta1 - case examplev1beta1.SchemeGroupVersion.WithResource("clustertesttypes"): + case v1alpha1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1alpha1().TestTypes().Informer()}, nil + + // Group=example.dev, Version=v1beta1 + case v1beta1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().ClusterTestTypes().Informer()}, nil - // Group=example, Version=V2 - case examplev2.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V2().TestTypes().Informer()}, nil - case examplev2.SchemeGroupVersion.WithResource("clustertesttypes"): + case v1beta1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().TestTypes().Informer()}, nil + + // Group=example.dev, Version=v2 + case v2.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V2().ClusterTestTypes().Informer()}, nil - // Group=existinginterfaces.acme.corp, Version=V1 - case existinginterfacesv1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Existinginterfaces().V1().TestTypes().Informer()}, nil + case v2.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V2().TestTypes().Informer()}, nil + + // Group=example3.some.corp, Version=v1 + case example3v1.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().ClusterTestTypes().Informer()}, nil + case example3v1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().TestTypes().Informer()}, nil + + // Group=existinginterfaces.acme.corp, Version=v1 case existinginterfacesv1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Existinginterfaces().V1().ClusterTestTypes().Informer()}, nil - // Group=secondexample, Version=V1 - case secondexamplev1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Secondexample().V1().TestTypes().Informer()}, nil + case existinginterfacesv1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Existinginterfaces().V1().TestTypes().Informer()}, nil + + // Group=secondexample.dev, Version=v1 case secondexamplev1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Secondexample().V1().ClusterTestTypes().Informer()}, nil + case secondexamplev1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Secondexample().V1().TestTypes().Informer()}, nil + } return nil, fmt.Errorf("no informer found for %v", resource) @@ -134,52 +158,70 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource // TODO extend this to unknown resources with a client pool func (f *sharedScopedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { - // Group=example3.some.corp, Version=V1 - case example3v1.SchemeGroupVersion.WithResource("testtypes"): - informer := f.Example3().V1().TestTypes().Informer() + // Group=example-dashed.some.corp, Version=v1 + case v1.SchemeGroupVersion.WithResource("clustertesttypes"): + informer := f.ExampleDashed().V1().ClusterTestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - case example3v1.SchemeGroupVersion.WithResource("clustertesttypes"): - informer := f.Example3().V1().ClusterTestTypes().Informer() - return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - // Group=example, Version=V1 - case examplev1.SchemeGroupVersion.WithResource("testtypes"): - informer := f.Example().V1().TestTypes().Informer() + case v1.SchemeGroupVersion.WithResource("testtypes"): + informer := f.ExampleDashed().V1().TestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + + // Group=example.dev, Version=v1 case examplev1.SchemeGroupVersion.WithResource("clustertesttypes"): informer := f.Example().V1().ClusterTestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - // Group=example, Version=V1alpha1 - case examplev1alpha1.SchemeGroupVersion.WithResource("testtypes"): - informer := f.Example().V1alpha1().TestTypes().Informer() + case examplev1.SchemeGroupVersion.WithResource("testtypes"): + informer := f.Example().V1().TestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - case examplev1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"): + + // Group=example.dev, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"): informer := f.Example().V1alpha1().ClusterTestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - // Group=example, Version=V1beta1 - case examplev1beta1.SchemeGroupVersion.WithResource("clustertesttypes"): + case v1alpha1.SchemeGroupVersion.WithResource("testtypes"): + informer := f.Example().V1alpha1().TestTypes().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + + // Group=example.dev, Version=v1beta1 + case v1beta1.SchemeGroupVersion.WithResource("clustertesttypes"): informer := f.Example().V1beta1().ClusterTestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - // Group=example, Version=V2 - case examplev2.SchemeGroupVersion.WithResource("testtypes"): - informer := f.Example().V2().TestTypes().Informer() + case v1beta1.SchemeGroupVersion.WithResource("testtypes"): + informer := f.Example().V1beta1().TestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - case examplev2.SchemeGroupVersion.WithResource("clustertesttypes"): + + // Group=example.dev, Version=v2 + case v2.SchemeGroupVersion.WithResource("clustertesttypes"): informer := f.Example().V2().ClusterTestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - // Group=existinginterfaces.acme.corp, Version=V1 - case existinginterfacesv1.SchemeGroupVersion.WithResource("testtypes"): - informer := f.Existinginterfaces().V1().TestTypes().Informer() + case v2.SchemeGroupVersion.WithResource("testtypes"): + informer := f.Example().V2().TestTypes().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + + // Group=example3.some.corp, Version=v1 + case example3v1.SchemeGroupVersion.WithResource("clustertesttypes"): + informer := f.Example3().V1().ClusterTestTypes().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + case example3v1.SchemeGroupVersion.WithResource("testtypes"): + informer := f.Example3().V1().TestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + + // Group=existinginterfaces.acme.corp, Version=v1 case existinginterfacesv1.SchemeGroupVersion.WithResource("clustertesttypes"): informer := f.Existinginterfaces().V1().ClusterTestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - // Group=secondexample, Version=V1 - case secondexamplev1.SchemeGroupVersion.WithResource("testtypes"): - informer := f.Secondexample().V1().TestTypes().Informer() + case existinginterfacesv1.SchemeGroupVersion.WithResource("testtypes"): + informer := f.Existinginterfaces().V1().TestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + + // Group=secondexample.dev, Version=v1 case secondexamplev1.SchemeGroupVersion.WithResource("clustertesttypes"): informer := f.Secondexample().V1().ClusterTestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + case secondexamplev1.SchemeGroupVersion.WithResource("testtypes"): + informer := f.Secondexample().V1().TestTypes().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + } return nil, fmt.Errorf("no informer found for %v", resource) diff --git a/examples/pkg/kcp/clients/informers/externalversions/internalinterfaces/factory_interfaces.go b/examples/pkg/kcp/clients/informers/externalversions/internalinterfaces/factory_interfaces.go index 692040b2d..4c872a55e 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/examples/pkg/kcp/clients/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,40 +14,40 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package internalinterfaces import ( time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" - "k8s.io/client-go/tools/cache" + cache "k8s.io/client-go/tools/cache" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" ) -// NewInformerFunc takes clientset.ClusterInterface and time.Duration to return a ScopeableSharedIndexInformer. -type NewInformerFunc func(clientset.ClusterInterface, time.Duration) kcpcache.ScopeableSharedIndexInformer +// TweakListOptionsFunc is a function that transforms a v1.ListOptions. +type TweakListOptionsFunc func(*v1.ListOptions) -// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +// NewInformerFunc takes versioned.ClusterInterface and time.Duration to return a kcpcache.ScopeableSharedIndexInformer. +type NewInformerFunc func(versioned.ClusterInterface, time.Duration) kcpcache.ScopeableSharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle. type SharedInformerFactory interface { Start(stopCh <-chan struct{}) InformerFor(obj runtime.Object, newFunc NewInformerFunc) kcpcache.ScopeableSharedIndexInformer } -// NewScopedInformerFunc takes scopedclientset.Interface and time.Duration to return a SharedIndexInformer. -type NewScopedInformerFunc func(scopedclientset.Interface, time.Duration) cache.SharedIndexInformer +// NewScopedInformerFunc takes clientsetversioned.Interface and time.Duration to return a SharedIndexInformer. +type NewScopedInformerFunc func(clientsetversioned.Interface, time.Duration) cache.SharedIndexInformer -// SharedScopedInformerFactory a small interface to allow for adding an informer without an import cycle +// SharedScopedInformerFactory a small interface to allow for adding an informer without an import cycle. type SharedScopedInformerFactory interface { Start(stopCh <-chan struct{}) InformerFor(obj runtime.Object, newFunc NewScopedInformerFunc) cache.SharedIndexInformer } - -// TweakListOptionsFunc is a function that transforms a metav1.ListOptions. -type TweakListOptionsFunc func(*metav1.ListOptions) diff --git a/examples/pkg/kcp/clients/informers/externalversions/secondexample/interface.go b/examples/pkg/kcp/clients/informers/externalversions/secondexample/interface.go index e6094563f..51e38e1b6 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/secondexample/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/secondexample/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,17 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package secondexample import ( - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - "acme.corp/pkg/kcp/clients/informers/externalversions/secondexample/v1" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + v1 "acme.corp/pkg/kcp/clients/informers/externalversions/secondexample/v1" ) +// ClusterInterface provides access to each of this group's versions. type ClusterInterface interface { - // V1 provides access to the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.ClusterInterface } @@ -46,8 +44,9 @@ func (g *group) V1() v1.ClusterInterface { return v1.New(g.factory, g.tweakListOptions) } +// Interface provides access to each of this group's versions. type Interface interface { - // V1 provides access to the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.Interface } @@ -62,7 +61,7 @@ func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace strin return &scopedGroup{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// V1 returns a new v1.ClusterInterface. +// V1 returns a new v1.Interface. func (g *scopedGroup) V1() v1.Interface { return v1.NewScoped(g.factory, g.namespace, g.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/clustertesttype.go index 1ee784424..8ebabdd58 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + secondexamplev1 "acme.corp/pkg/kcp/clients/listers/secondexample/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - secondexamplev1listers "acme.corp/pkg/kcp/clients/listers/secondexample/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() secondexamplev1listers.ClusterTestTypeClusterLister + Lister() secondexamplev1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -57,76 +55,82 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().ClusterTestTypes().List(context.TODO(), options) + return client.SecondexampleV1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().ClusterTestTypes().Watch(context.TODO(), options) + return client.SecondexampleV1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &secondexamplev1.ClusterTestType{}, + &apissecondexamplev1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&secondexamplev1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apissecondexamplev1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Lister() secondexamplev1listers.ClusterTestTypeClusterLister { - return secondexamplev1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Lister() secondexamplev1.ClusterTestTypeClusterLister { + return secondexamplev1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -// ClusterTestTypeInformer provides access to a shared informer and lister for -// ClusterTestTypes. -type ClusterTestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() secondexamplev1listers.ClusterTestTypeLister +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister secondexamplev1listers.ClusterTestTypeLister + lister secondexamplev1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() secondexamplev1listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() secondexamplev1.ClusterTestTypeLister { + return i.lister +} + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() secondexamplev1.ClusterTestTypeLister } type clusterTestTypeScopedInformer struct { @@ -134,46 +138,46 @@ type clusterTestTypeScopedInformer struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -func (f *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&secondexamplev1.ClusterTestType{}, f.defaultInformer) -} - -func (f *clusterTestTypeScopedInformer) Lister() secondexamplev1listers.ClusterTestTypeLister { - return secondexamplev1listers.NewClusterTestTypeLister(f.Informer().GetIndexer()) -} - // NewClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { +func NewClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredClusterTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().ClusterTestTypes().List(context.TODO(), options) + return client.SecondexampleV1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().ClusterTestTypes().Watch(context.TODO(), options) + return client.SecondexampleV1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &secondexamplev1.ClusterTestType{}, + &apissecondexamplev1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) +func (i *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apissecondexamplev1.ClusterTestType{}, i.defaultInformer) +} + +func (i *clusterTestTypeScopedInformer) Lister() secondexamplev1.ClusterTestTypeLister { + return secondexamplev1.NewClusterTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/interface.go b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/interface.go index 3034bb594..e632b7bcb 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // TestTypes returns a TestTypeClusterInformer - TestTypes() TestTypeClusterInformer - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -37,26 +34,26 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// TestTypes returns a TestTypeClusterInformer -func (v *version) TestTypes() TestTypeClusterInformer { - return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + type Interface interface { - // TestTypes returns a TestTypeInformer - TestTypes() TestTypeInformer - // ClusterTestTypes returns a ClusterTestTypeInformer + // ClusterTestTypes returns a ClusterTestTypeInformer. ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer } type scopedVersion struct { @@ -65,17 +62,17 @@ type scopedVersion struct { namespace string } -// New returns a new ClusterInterface. +// New returns a new Interface. func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &scopedVersion{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// TestTypes returns a TestTypeInformer -func (v *scopedVersion) TestTypes() TestTypeInformer { - return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} + return &scopedVersion{factory: f, tweakListOptions: tweakListOptions} } -// ClusterTestTypes returns a ClusterTestTypeInformer +// ClusterTestTypes returns a ClusterTestTypeInformer. func (v *scopedVersion) ClusterTestTypes() ClusterTestTypeInformer { return &clusterTestTypeScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeInformer. +func (v *scopedVersion) TestTypes() TestTypeInformer { + return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/testtype.go index 5d2ae2aa0..503309e51 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,36 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + secondexamplev1 "acme.corp/pkg/kcp/clients/listers/secondexample/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - secondexamplev1listers "acme.corp/pkg/kcp/clients/listers/secondexample/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() secondexamplev1listers.TestTypeClusterLister + Lister() secondexamplev1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -57,76 +55,82 @@ type testTypeClusterInformer struct { // NewTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().TestTypes().List(context.TODO(), options) + return client.SecondexampleV1().TestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().TestTypes().Watch(context.TODO(), options) + return client.SecondexampleV1().TestTypes().Watch(context.Background(), options) }, }, - &secondexamplev1.TestType{}, + &apissecondexamplev1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, - f.tweakListOptions, - ) + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&secondexamplev1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apissecondexamplev1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Lister() secondexamplev1listers.TestTypeClusterLister { - return secondexamplev1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Lister() secondexamplev1.TestTypeClusterLister { + return secondexamplev1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -// TestTypeInformer provides access to a shared informer and lister for -// TestTypes. -type TestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() secondexamplev1listers.TestTypeLister +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister secondexamplev1listers.TestTypeLister + lister secondexamplev1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() secondexamplev1listers.TestTypeLister { - return f.lister +func (i *testTypeInformer) Lister() secondexamplev1.TestTypeLister { + return i.lister +} + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() secondexamplev1.TestTypeLister } type testTypeScopedInformer struct { @@ -135,48 +139,48 @@ type testTypeScopedInformer struct { namespace string } -func (f *testTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&secondexamplev1.TestType{}, f.defaultInformer) -} - -func (f *testTypeScopedInformer) Lister() secondexamplev1listers.TestTypeLister { - return secondexamplev1listers.NewTestTypeLister(f.Informer().GetIndexer()) -} - // NewTestTypeInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { +func NewTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredTestTypeInformer(client, resyncPeriod, namespace, indexers, nil) } // NewFilteredTestTypeInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredTestTypeInformer(client clientsetversioned.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().TestTypes(namespace).List(context.TODO(), options) + return client.SecondexampleV1().TestTypes(namespace).List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().TestTypes(namespace).Watch(context.TODO(), options) + return client.SecondexampleV1().TestTypes(namespace).Watch(context.Background(), options) }, }, - &secondexamplev1.TestType{}, + &apissecondexamplev1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredTestTypeInformer(client, resyncPeriod, f.namespace, cache.Indexers{ +func (i *testTypeScopedInformer) Informer() cache.SharedIndexInformer { + return i.factory.InformerFor(&apissecondexamplev1.TestType{}, i.defaultInformer) +} + +func (i *testTypeScopedInformer) Lister() secondexamplev1.TestTypeLister { + return secondexamplev1.NewTestTypeLister(i.Informer().GetIndexer()) +} + +func (i *testTypeScopedInformer) defaultInformer(client clientsetversioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, i.namespace, cache.Indexers{ cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, - }, f.tweakListOptions) + }, i.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/listers/example/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/example/v1/clustertesttype.go index 9a8e7c172..1f62e4093 100644 --- a/examples/pkg/kcp/clients/listers/example/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev1 "acme.corp/pkg/apis/example/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev1 "acme.corp/pkg/apis/example/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. @@ -43,36 +40,43 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev1.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), + } } -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*examplev1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev1.ClusterTestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister for one namespace. +type clusterTestTypeLister struct { + kcplisters.ResourceIndexer[*examplev1.ClusterTestType] } +var _ ClusterTestTypeLister = new(clusterTestTypeLister) + // ClusterTestTypeLister can list all ClusterTestTypes, or get one in particular. // All objects returned here must be treated as read-only. type ClusterTestTypeLister interface { - // List lists all ClusterTestTypes in the workspace. + // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the indexer for a given workspace and name. @@ -81,63 +85,19 @@ type ClusterTestTypeLister interface { ClusterTestTypeListerExpansion } -// clusterTestTypeLister can list all ClusterTestTypes inside a workspace. -type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*examplev1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*examplev1.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1.Resource("clustertesttypes"), name) - } - return obj.(*examplev1.ClusterTestType), nil -} - // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -func NewClusterTestTypeLister(indexer cache.Indexer) *clusterTestTypeScopedLister { - return &clusterTestTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), + } } -// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace. +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeScopedLister) List(selector labels.Selector) (ret []*examplev1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeScopedLister) Get(name string) (*examplev1.ClusterTestType, error) { - key := name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1.Resource("clustertesttypes"), name) - } - return obj.(*examplev1.ClusterTestType), nil + kcplisters.ResourceIndexer[*examplev1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/example/v1/expansion_generated.go b/examples/pkg/kcp/clients/listers/example/v1/expansion_generated.go new file mode 100644 index 000000000..5c9986676 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/example/v1/expansion_generated.go @@ -0,0 +1,51 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-lister-gen. DO NOT EDIT. + +package v1 + +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} + +// ClusterTestTypeListerExpansion allows custom methods to be added to +// ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} + +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. +type TestTypeListerExpansion interface{} + +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. +type TestTypeNamespaceListerExpansion interface{} + +// WithoutVerbTypeClusterListerExpansion allows custom methods to be added to +// WithoutVerbTypeClusterLister. +type WithoutVerbTypeClusterListerExpansion interface{} + +// WithoutVerbTypeListerExpansion allows custom methods to be added to +// WithoutVerbTypeLister. +type WithoutVerbTypeListerExpansion interface{} + +// WithoutVerbTypeNamespaceListerExpansion allows custom methods to be added to +// WithoutVerbTypeNamespaceLister. +type WithoutVerbTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/example/v1/testtype.go b/examples/pkg/kcp/clients/listers/example/v1/testtype.go index 54df3a921..de7aaa728 100644 --- a/examples/pkg/kcp/clients/listers/example/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/example/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev1 "acme.corp/pkg/apis/example/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev1 "acme.corp/pkg/apis/example/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. // All objects returned here must be treated as read-only. type TestTypeClusterLister interface { // List lists all TestTypes in the indexer. @@ -43,37 +40,44 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev1.TestType] } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev1.TestType](indexer, examplev1.Resource("testtype")), + } } -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*examplev1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev1.TestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. +type testTypeLister struct { + kcplisters.ResourceIndexer[*examplev1.TestType] } +var _ TestTypeLister = new(testTypeLister) + // TestTypeLister can list TestTypes across all namespaces, or scope down to a TestTypeNamespaceLister for one namespace. // All objects returned here must be treated as read-only. type TestTypeLister interface { - // List lists all TestTypes in the workspace. + // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev1.TestType, err error) // TestTypes returns a lister that can list and get TestTypes in one workspace and namespace. @@ -81,29 +85,25 @@ type TestTypeLister interface { TestTypeListerExpansion } -// testTypeLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. -type testTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*examplev1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1.TestType)) - }) - return ret, err +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*examplev1.TestType] } -// TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} -} +var _ TestTypeNamespaceLister = new(testTypeNamespaceLister) -// testTypeNamespaceLister helps list and get TestTypes. +// TestTypeNamespaceLister can list all TestTypes, or get one in particular. // All objects returned here must be treated as read-only. type TestTypeNamespaceLister interface { - // List lists all TestTypes in the workspace and namespace. + // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev1.TestType, err error) // Get retrieves the TestType from the indexer for a given workspace, namespace and name. @@ -112,85 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// testTypeNamespaceLister helps list and get TestTypes. -// All objects returned here must be treated as read-only. -type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string -} - -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*examplev1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*examplev1.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1.Resource("testtypes"), name) - } - return obj.(*examplev1.TestType), nil -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index -func NewTestTypeLister(indexer cache.Indexer) *testTypeScopedLister { - return &testTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*examplev1.TestType](indexer, examplev1.Resource("testtype")), + } } -// testTypeScopedLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeScopedLister) List(selector labels.Selector) (ret []*examplev1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1.TestType)) - }) - return ret, err + kcplisters.ResourceIndexer[*examplev1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return &testTypeScopedNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// testTypeScopedNamespaceLister helps list and get TestTypes. -type testTypeScopedNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeScopedNamespaceLister) List(selector labels.Selector) (ret []*examplev1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeScopedNamespaceLister) Get(name string) (*examplev1.TestType, error) { - key := s.namespace + "/" + name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1.Resource("testtypes"), name) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), } - return obj.(*examplev1.TestType), nil } diff --git a/examples/pkg/kcp/clients/listers/example/v1/withoutverbtype.go b/examples/pkg/kcp/clients/listers/example/v1/withoutverbtype.go new file mode 100644 index 000000000..f5cced56a --- /dev/null +++ b/examples/pkg/kcp/clients/listers/example/v1/withoutverbtype.go @@ -0,0 +1,138 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-lister-gen. DO NOT EDIT. + +package v1 + +import ( + examplev1 "acme.corp/pkg/apis/example/v1" + + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" +) + +// WithoutVerbTypeClusterLister helps list WithoutVerbTypes across all workspaces, +// or scope down to a WithoutVerbTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type WithoutVerbTypeClusterLister interface { + // List lists all WithoutVerbTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*examplev1.WithoutVerbType, err error) + // Cluster returns a lister that can list and get WithoutVerbTypes in one workspace. + Cluster(clusterName logicalcluster.Name) WithoutVerbTypeLister + WithoutVerbTypeClusterListerExpansion +} + +// withoutVerbTypeClusterLister implements the WithoutVerbTypeClusterLister interface. +type withoutVerbTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev1.WithoutVerbType] +} + +var _ WithoutVerbTypeClusterLister = new(withoutVerbTypeClusterLister) + +// NewWithoutVerbTypeClusterLister returns a new WithoutVerbTypeClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewWithoutVerbTypeClusterLister(indexer cache.Indexer) WithoutVerbTypeClusterLister { + return &withoutVerbTypeClusterLister{ + kcplisters.NewCluster[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype")), + } +} + +// Cluster scopes the lister to one workspace, allowing users to list and get WithoutVerbTypes. +func (l *withoutVerbTypeClusterLister) Cluster(clusterName logicalcluster.Name) WithoutVerbTypeLister { + return &withoutVerbTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } +} + +// withoutVerbTypeLister can list all WithoutVerbTypes inside a workspace +// or scope down to a WithoutVerbTypeNamespaceLister for one namespace. +type withoutVerbTypeLister struct { + kcplisters.ResourceIndexer[*examplev1.WithoutVerbType] +} + +var _ WithoutVerbTypeLister = new(withoutVerbTypeLister) + +// WithoutVerbTypeLister can list WithoutVerbTypes across all namespaces, or scope down to a WithoutVerbTypeNamespaceLister for one namespace. +// All objects returned here must be treated as read-only. +type WithoutVerbTypeLister interface { + // List lists all WithoutVerbTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*examplev1.WithoutVerbType, err error) + // WithoutVerbTypes returns a lister that can list and get WithoutVerbTypes in one workspace and namespace. + WithoutVerbTypes(namespace string) WithoutVerbTypeNamespaceLister + WithoutVerbTypeListerExpansion +} + +// WithoutVerbTypes returns an object that can list and get WithoutVerbTypes in one namespace. +func (l *withoutVerbTypeLister) WithoutVerbTypes(namespace string) WithoutVerbTypeNamespaceLister { + return &withoutVerbTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} + +// withoutVerbTypeNamespaceLister implements the WithoutVerbTypeNamespaceLister +// interface. +type withoutVerbTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*examplev1.WithoutVerbType] +} + +var _ WithoutVerbTypeNamespaceLister = new(withoutVerbTypeNamespaceLister) + +// WithoutVerbTypeNamespaceLister can list all WithoutVerbTypes, or get one in particular. +// All objects returned here must be treated as read-only. +type WithoutVerbTypeNamespaceLister interface { + // List lists all WithoutVerbTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*examplev1.WithoutVerbType, err error) + // Get retrieves the WithoutVerbType from the indexer for a given workspace, namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*examplev1.WithoutVerbType, error) + WithoutVerbTypeNamespaceListerExpansion +} + +// NewWithoutVerbTypeLister returns a new WithoutVerbTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewWithoutVerbTypeLister(indexer cache.Indexer) WithoutVerbTypeLister { + return &withoutVerbTypeLister{ + kcplisters.New[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype")), + } +} + +// withoutVerbTypeScopedLister can list all WithoutVerbTypes inside a workspace +// or scope down to a WithoutVerbTypeNamespaceLister for one namespace. +type withoutVerbTypeScopedLister struct { + kcplisters.ResourceIndexer[*examplev1.WithoutVerbType] +} + +// WithoutVerbTypes returns an object that can list and get WithoutVerbTypes in one namespace. +func (l *withoutVerbTypeScopedLister) WithoutVerbTypes(namespace string) WithoutVerbTypeLister { + return &withoutVerbTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} diff --git a/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype.go b/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype.go index 96dd19f54..7b17851dc 100644 --- a/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1alpha1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. @@ -43,36 +40,43 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev1alpha1.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), + } } -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*examplev1alpha1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev1alpha1.ClusterTestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister for one namespace. +type clusterTestTypeLister struct { + kcplisters.ResourceIndexer[*examplev1alpha1.ClusterTestType] } +var _ ClusterTestTypeLister = new(clusterTestTypeLister) + // ClusterTestTypeLister can list all ClusterTestTypes, or get one in particular. // All objects returned here must be treated as read-only. type ClusterTestTypeLister interface { - // List lists all ClusterTestTypes in the workspace. + // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev1alpha1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the indexer for a given workspace and name. @@ -81,63 +85,19 @@ type ClusterTestTypeLister interface { ClusterTestTypeListerExpansion } -// clusterTestTypeLister can list all ClusterTestTypes inside a workspace. -type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*examplev1alpha1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1alpha1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*examplev1alpha1.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1alpha1.Resource("clustertesttypes"), name) - } - return obj.(*examplev1alpha1.ClusterTestType), nil -} - // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -func NewClusterTestTypeLister(indexer cache.Indexer) *clusterTestTypeScopedLister { - return &clusterTestTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), + } } -// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace. +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeScopedLister) List(selector labels.Selector) (ret []*examplev1alpha1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1alpha1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeScopedLister) Get(name string) (*examplev1alpha1.ClusterTestType, error) { - key := name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1alpha1.Resource("clustertesttypes"), name) - } - return obj.(*examplev1alpha1.ClusterTestType), nil + kcplisters.ResourceIndexer[*examplev1alpha1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype_expansion.go b/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype_expansion.go deleted file mode 100644 index 3bc267025..000000000 --- a/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype_expansion.go +++ /dev/null @@ -1,28 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by kcp code-generator. DO NOT EDIT. - -package v1alpha1 - -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. -type ClusterTestTypeClusterListerExpansion interface{} - -// ClusterTestTypeListerExpansion allows custom methods to be added to ClusterTestTypeLister. -type ClusterTestTypeListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/example/v1alpha1/testtype_expansion.go b/examples/pkg/kcp/clients/listers/example/v1alpha1/expansion_generated.go similarity index 62% rename from examples/pkg/kcp/clients/listers/example/v1alpha1/testtype_expansion.go rename to examples/pkg/kcp/clients/listers/example/v1alpha1/expansion_generated.go index e0f60610c..24f288c6e 100644 --- a/examples/pkg/kcp/clients/listers/example/v1alpha1/testtype_expansion.go +++ b/examples/pkg/kcp/clients/listers/example/v1alpha1/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,15 +14,26 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1alpha1 -// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} + +// ClusterTestTypeListerExpansion allows custom methods to be added to +// ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. type TestTypeClusterListerExpansion interface{} -// TestTypeListerExpansion allows custom methods to be added to TestTypeLister. +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. type TestTypeListerExpansion interface{} -// TestTypeNamespaceListerExpansion allows custom methods to be added to TestTypeNamespaceLister. +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/example/v1alpha1/testtype.go b/examples/pkg/kcp/clients/listers/example/v1alpha1/testtype.go index 092a8d581..e6b7b5bb5 100644 --- a/examples/pkg/kcp/clients/listers/example/v1alpha1/testtype.go +++ b/examples/pkg/kcp/clients/listers/example/v1alpha1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1alpha1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. // All objects returned here must be treated as read-only. type TestTypeClusterLister interface { // List lists all TestTypes in the indexer. @@ -43,37 +40,44 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev1alpha1.TestType] } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), + } } -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev1alpha1.TestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. +type testTypeLister struct { + kcplisters.ResourceIndexer[*examplev1alpha1.TestType] } +var _ TestTypeLister = new(testTypeLister) + // TestTypeLister can list TestTypes across all namespaces, or scope down to a TestTypeNamespaceLister for one namespace. // All objects returned here must be treated as read-only. type TestTypeLister interface { - // List lists all TestTypes in the workspace. + // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) // TestTypes returns a lister that can list and get TestTypes in one workspace and namespace. @@ -81,29 +85,25 @@ type TestTypeLister interface { TestTypeListerExpansion } -// testTypeLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. -type testTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1alpha1.TestType)) - }) - return ret, err +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*examplev1alpha1.TestType] } -// TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} -} +var _ TestTypeNamespaceLister = new(testTypeNamespaceLister) -// testTypeNamespaceLister helps list and get TestTypes. +// TestTypeNamespaceLister can list all TestTypes, or get one in particular. // All objects returned here must be treated as read-only. type TestTypeNamespaceLister interface { - // List lists all TestTypes in the workspace and namespace. + // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) // Get retrieves the TestType from the indexer for a given workspace, namespace and name. @@ -112,85 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// testTypeNamespaceLister helps list and get TestTypes. -// All objects returned here must be treated as read-only. -type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string -} - -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1alpha1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*examplev1alpha1.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1alpha1.Resource("testtypes"), name) - } - return obj.(*examplev1alpha1.TestType), nil -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index -func NewTestTypeLister(indexer cache.Indexer) *testTypeScopedLister { - return &testTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), + } } -// testTypeScopedLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeScopedLister) List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1alpha1.TestType)) - }) - return ret, err + kcplisters.ResourceIndexer[*examplev1alpha1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return &testTypeScopedNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// testTypeScopedNamespaceLister helps list and get TestTypes. -type testTypeScopedNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeScopedNamespaceLister) List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1alpha1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeScopedNamespaceLister) Get(name string) (*examplev1alpha1.TestType, error) { - key := s.namespace + "/" + name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1alpha1.Resource("testtypes"), name) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), } - return obj.(*examplev1alpha1.TestType), nil } diff --git a/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype.go b/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype.go index b67b7f9ee..65f3068ae 100644 --- a/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1beta1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. @@ -43,36 +40,43 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev1beta1.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), + } } -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*examplev1beta1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev1beta1.ClusterTestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister for one namespace. +type clusterTestTypeLister struct { + kcplisters.ResourceIndexer[*examplev1beta1.ClusterTestType] } +var _ ClusterTestTypeLister = new(clusterTestTypeLister) + // ClusterTestTypeLister can list all ClusterTestTypes, or get one in particular. // All objects returned here must be treated as read-only. type ClusterTestTypeLister interface { - // List lists all ClusterTestTypes in the workspace. + // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev1beta1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the indexer for a given workspace and name. @@ -81,63 +85,19 @@ type ClusterTestTypeLister interface { ClusterTestTypeListerExpansion } -// clusterTestTypeLister can list all ClusterTestTypes inside a workspace. -type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*examplev1beta1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1beta1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*examplev1beta1.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1beta1.Resource("clustertesttypes"), name) - } - return obj.(*examplev1beta1.ClusterTestType), nil -} - // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -func NewClusterTestTypeLister(indexer cache.Indexer) *clusterTestTypeScopedLister { - return &clusterTestTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), + } } -// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace. +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeScopedLister) List(selector labels.Selector) (ret []*examplev1beta1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1beta1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeScopedLister) Get(name string) (*examplev1beta1.ClusterTestType, error) { - key := name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1beta1.Resource("clustertesttypes"), name) - } - return obj.(*examplev1beta1.ClusterTestType), nil + kcplisters.ResourceIndexer[*examplev1beta1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/example/v1beta1/expansion_generated.go b/examples/pkg/kcp/clients/listers/example/v1beta1/expansion_generated.go new file mode 100644 index 000000000..0b54ba7d4 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/example/v1beta1/expansion_generated.go @@ -0,0 +1,39 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-lister-gen. DO NOT EDIT. + +package v1beta1 + +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} + +// ClusterTestTypeListerExpansion allows custom methods to be added to +// ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} + +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. +type TestTypeListerExpansion interface{} + +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. +type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/example/v1beta1/testtype.go b/examples/pkg/kcp/clients/listers/example/v1beta1/testtype.go new file mode 100644 index 000000000..c32e5547e --- /dev/null +++ b/examples/pkg/kcp/clients/listers/example/v1beta1/testtype.go @@ -0,0 +1,138 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-lister-gen. DO NOT EDIT. + +package v1beta1 + +import ( + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" +) + +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type TestTypeClusterLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*examplev1beta1.TestType, err error) + // Cluster returns a lister that can list and get TestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) TestTypeLister + TestTypeClusterListerExpansion +} + +// testTypeClusterLister implements the TestTypeClusterLister interface. +type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev1beta1.TestType] +} + +var _ TestTypeClusterLister = new(testTypeClusterLister) + +// NewTestTypeClusterLister returns a new TestTypeClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), + } +} + +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } +} + +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. +type testTypeLister struct { + kcplisters.ResourceIndexer[*examplev1beta1.TestType] +} + +var _ TestTypeLister = new(testTypeLister) + +// TestTypeLister can list TestTypes across all namespaces, or scope down to a TestTypeNamespaceLister for one namespace. +// All objects returned here must be treated as read-only. +type TestTypeLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*examplev1beta1.TestType, err error) + // TestTypes returns a lister that can list and get TestTypes in one workspace and namespace. + TestTypes(namespace string) TestTypeNamespaceLister + TestTypeListerExpansion +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} + +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*examplev1beta1.TestType] +} + +var _ TestTypeNamespaceLister = new(testTypeNamespaceLister) + +// TestTypeNamespaceLister can list all TestTypes, or get one in particular. +// All objects returned here must be treated as read-only. +type TestTypeNamespaceLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*examplev1beta1.TestType, err error) + // Get retrieves the TestType from the indexer for a given workspace, namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*examplev1beta1.TestType, error) + TestTypeNamespaceListerExpansion +} + +// NewTestTypeLister returns a new TestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), + } +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + kcplisters.ResourceIndexer[*examplev1beta1.TestType] +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} diff --git a/examples/pkg/kcp/clients/listers/example/v2/clustertesttype.go b/examples/pkg/kcp/clients/listers/example/v2/clustertesttype.go index 157fbe856..09c3d18df 100644 --- a/examples/pkg/kcp/clients/listers/example/v2/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example/v2/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v2 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev2 "acme.corp/pkg/apis/example/v2" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev2 "acme.corp/pkg/apis/example/v2" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. @@ -43,36 +40,43 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev2.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), + } } -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*examplev2.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev2.ClusterTestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister for one namespace. +type clusterTestTypeLister struct { + kcplisters.ResourceIndexer[*examplev2.ClusterTestType] } +var _ ClusterTestTypeLister = new(clusterTestTypeLister) + // ClusterTestTypeLister can list all ClusterTestTypes, or get one in particular. // All objects returned here must be treated as read-only. type ClusterTestTypeLister interface { - // List lists all ClusterTestTypes in the workspace. + // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev2.ClusterTestType, err error) // Get retrieves the ClusterTestType from the indexer for a given workspace and name. @@ -81,63 +85,19 @@ type ClusterTestTypeLister interface { ClusterTestTypeListerExpansion } -// clusterTestTypeLister can list all ClusterTestTypes inside a workspace. -type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*examplev2.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev2.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*examplev2.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev2.Resource("clustertesttypes"), name) - } - return obj.(*examplev2.ClusterTestType), nil -} - // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -func NewClusterTestTypeLister(indexer cache.Indexer) *clusterTestTypeScopedLister { - return &clusterTestTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), + } } -// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace. +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeScopedLister) List(selector labels.Selector) (ret []*examplev2.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*examplev2.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeScopedLister) Get(name string) (*examplev2.ClusterTestType, error) { - key := name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev2.Resource("clustertesttypes"), name) - } - return obj.(*examplev2.ClusterTestType), nil + kcplisters.ResourceIndexer[*examplev2.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/example/v2/clustertesttype_expansion.go b/examples/pkg/kcp/clients/listers/example/v2/clustertesttype_expansion.go deleted file mode 100644 index 2ce875217..000000000 --- a/examples/pkg/kcp/clients/listers/example/v2/clustertesttype_expansion.go +++ /dev/null @@ -1,28 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by kcp code-generator. DO NOT EDIT. - -package v2 - -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. -type ClusterTestTypeClusterListerExpansion interface{} - -// ClusterTestTypeListerExpansion allows custom methods to be added to ClusterTestTypeLister. -type ClusterTestTypeListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/example/v2/testtype_expansion.go b/examples/pkg/kcp/clients/listers/example/v2/expansion_generated.go similarity index 61% rename from examples/pkg/kcp/clients/listers/example/v2/testtype_expansion.go rename to examples/pkg/kcp/clients/listers/example/v2/expansion_generated.go index 3c8c5b8e7..904cf3a8f 100644 --- a/examples/pkg/kcp/clients/listers/example/v2/testtype_expansion.go +++ b/examples/pkg/kcp/clients/listers/example/v2/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,15 +14,26 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v2 -// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} + +// ClusterTestTypeListerExpansion allows custom methods to be added to +// ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. type TestTypeClusterListerExpansion interface{} -// TestTypeListerExpansion allows custom methods to be added to TestTypeLister. +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. type TestTypeListerExpansion interface{} -// TestTypeNamespaceListerExpansion allows custom methods to be added to TestTypeNamespaceLister. +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/example/v2/testtype.go b/examples/pkg/kcp/clients/listers/example/v2/testtype.go index 069ad8082..069c2c140 100644 --- a/examples/pkg/kcp/clients/listers/example/v2/testtype.go +++ b/examples/pkg/kcp/clients/listers/example/v2/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v2 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev2 "acme.corp/pkg/apis/example/v2" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev2 "acme.corp/pkg/apis/example/v2" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. // All objects returned here must be treated as read-only. type TestTypeClusterLister interface { // List lists all TestTypes in the indexer. @@ -43,37 +40,44 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev2.TestType] } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev2.TestType](indexer, examplev2.Resource("testtype")), + } } -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*examplev2.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev2.TestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. +type testTypeLister struct { + kcplisters.ResourceIndexer[*examplev2.TestType] } +var _ TestTypeLister = new(testTypeLister) + // TestTypeLister can list TestTypes across all namespaces, or scope down to a TestTypeNamespaceLister for one namespace. // All objects returned here must be treated as read-only. type TestTypeLister interface { - // List lists all TestTypes in the workspace. + // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev2.TestType, err error) // TestTypes returns a lister that can list and get TestTypes in one workspace and namespace. @@ -81,29 +85,25 @@ type TestTypeLister interface { TestTypeListerExpansion } -// testTypeLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. -type testTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*examplev2.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev2.TestType)) - }) - return ret, err +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*examplev2.TestType] } -// TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} -} +var _ TestTypeNamespaceLister = new(testTypeNamespaceLister) -// testTypeNamespaceLister helps list and get TestTypes. +// TestTypeNamespaceLister can list all TestTypes, or get one in particular. // All objects returned here must be treated as read-only. type TestTypeNamespaceLister interface { - // List lists all TestTypes in the workspace and namespace. + // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev2.TestType, err error) // Get retrieves the TestType from the indexer for a given workspace, namespace and name. @@ -112,85 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// testTypeNamespaceLister helps list and get TestTypes. -// All objects returned here must be treated as read-only. -type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string -} - -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*examplev2.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*examplev2.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*examplev2.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev2.Resource("testtypes"), name) - } - return obj.(*examplev2.TestType), nil -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index -func NewTestTypeLister(indexer cache.Indexer) *testTypeScopedLister { - return &testTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*examplev2.TestType](indexer, examplev2.Resource("testtype")), + } } -// testTypeScopedLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeScopedLister) List(selector labels.Selector) (ret []*examplev2.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*examplev2.TestType)) - }) - return ret, err + kcplisters.ResourceIndexer[*examplev2.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return &testTypeScopedNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// testTypeScopedNamespaceLister helps list and get TestTypes. -type testTypeScopedNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeScopedNamespaceLister) List(selector labels.Selector) (ret []*examplev2.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*examplev2.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeScopedNamespaceLister) Get(name string) (*examplev2.TestType, error) { - key := s.namespace + "/" + name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev2.Resource("testtypes"), name) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), } - return obj.(*examplev2.TestType), nil } diff --git a/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype.go index dd32331b4..c36421fce 100644 --- a/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + example3v1 "acme.corp/pkg/apis/example3/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - example3v1 "acme.corp/pkg/apis/example3/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. @@ -43,36 +40,43 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*example3v1.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), + } } -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*example3v1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*example3v1.ClusterTestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister for one namespace. +type clusterTestTypeLister struct { + kcplisters.ResourceIndexer[*example3v1.ClusterTestType] } +var _ ClusterTestTypeLister = new(clusterTestTypeLister) + // ClusterTestTypeLister can list all ClusterTestTypes, or get one in particular. // All objects returned here must be treated as read-only. type ClusterTestTypeLister interface { - // List lists all ClusterTestTypes in the workspace. + // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*example3v1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the indexer for a given workspace and name. @@ -81,63 +85,19 @@ type ClusterTestTypeLister interface { ClusterTestTypeListerExpansion } -// clusterTestTypeLister can list all ClusterTestTypes inside a workspace. -type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*example3v1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*example3v1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*example3v1.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(example3v1.Resource("clustertesttypes"), name) - } - return obj.(*example3v1.ClusterTestType), nil -} - // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -func NewClusterTestTypeLister(indexer cache.Indexer) *clusterTestTypeScopedLister { - return &clusterTestTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), + } } -// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace. +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeScopedLister) List(selector labels.Selector) (ret []*example3v1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*example3v1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeScopedLister) Get(name string) (*example3v1.ClusterTestType, error) { - key := name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(example3v1.Resource("clustertesttypes"), name) - } - return obj.(*example3v1.ClusterTestType), nil + kcplisters.ResourceIndexer[*example3v1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype_expansion.go b/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype_expansion.go deleted file mode 100644 index a85e878f1..000000000 --- a/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype_expansion.go +++ /dev/null @@ -1,28 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by kcp code-generator. DO NOT EDIT. - -package v1 - -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. -type ClusterTestTypeClusterListerExpansion interface{} - -// ClusterTestTypeListerExpansion allows custom methods to be added to ClusterTestTypeLister. -type ClusterTestTypeListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/example3/v1/testtype_expansion.go b/examples/pkg/kcp/clients/listers/example3/v1/expansion_generated.go similarity index 61% rename from examples/pkg/kcp/clients/listers/example3/v1/testtype_expansion.go rename to examples/pkg/kcp/clients/listers/example3/v1/expansion_generated.go index 3f50c325f..1ef10b740 100644 --- a/examples/pkg/kcp/clients/listers/example3/v1/testtype_expansion.go +++ b/examples/pkg/kcp/clients/listers/example3/v1/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,15 +14,26 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 -// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} + +// ClusterTestTypeListerExpansion allows custom methods to be added to +// ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. type TestTypeClusterListerExpansion interface{} -// TestTypeListerExpansion allows custom methods to be added to TestTypeLister. +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. type TestTypeListerExpansion interface{} -// TestTypeNamespaceListerExpansion allows custom methods to be added to TestTypeNamespaceLister. +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/example3/v1/testtype.go b/examples/pkg/kcp/clients/listers/example3/v1/testtype.go index c21ef2849..45c5945ef 100644 --- a/examples/pkg/kcp/clients/listers/example3/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/example3/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + example3v1 "acme.corp/pkg/apis/example3/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - example3v1 "acme.corp/pkg/apis/example3/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. // All objects returned here must be treated as read-only. type TestTypeClusterLister interface { // List lists all TestTypes in the indexer. @@ -43,37 +40,44 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*example3v1.TestType] } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*example3v1.TestType](indexer, example3v1.Resource("testtype")), + } } -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*example3v1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*example3v1.TestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. +type testTypeLister struct { + kcplisters.ResourceIndexer[*example3v1.TestType] } +var _ TestTypeLister = new(testTypeLister) + // TestTypeLister can list TestTypes across all namespaces, or scope down to a TestTypeNamespaceLister for one namespace. // All objects returned here must be treated as read-only. type TestTypeLister interface { - // List lists all TestTypes in the workspace. + // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*example3v1.TestType, err error) // TestTypes returns a lister that can list and get TestTypes in one workspace and namespace. @@ -81,29 +85,25 @@ type TestTypeLister interface { TestTypeListerExpansion } -// testTypeLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. -type testTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*example3v1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*example3v1.TestType)) - }) - return ret, err +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*example3v1.TestType] } -// TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} -} +var _ TestTypeNamespaceLister = new(testTypeNamespaceLister) -// testTypeNamespaceLister helps list and get TestTypes. +// TestTypeNamespaceLister can list all TestTypes, or get one in particular. // All objects returned here must be treated as read-only. type TestTypeNamespaceLister interface { - // List lists all TestTypes in the workspace and namespace. + // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*example3v1.TestType, err error) // Get retrieves the TestType from the indexer for a given workspace, namespace and name. @@ -112,85 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// testTypeNamespaceLister helps list and get TestTypes. -// All objects returned here must be treated as read-only. -type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string -} - -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*example3v1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*example3v1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*example3v1.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(example3v1.Resource("testtypes"), name) - } - return obj.(*example3v1.TestType), nil -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index -func NewTestTypeLister(indexer cache.Indexer) *testTypeScopedLister { - return &testTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*example3v1.TestType](indexer, example3v1.Resource("testtype")), + } } -// testTypeScopedLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeScopedLister) List(selector labels.Selector) (ret []*example3v1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*example3v1.TestType)) - }) - return ret, err + kcplisters.ResourceIndexer[*example3v1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return &testTypeScopedNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// testTypeScopedNamespaceLister helps list and get TestTypes. -type testTypeScopedNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeScopedNamespaceLister) List(selector labels.Selector) (ret []*example3v1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*example3v1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeScopedNamespaceLister) Get(name string) (*example3v1.TestType, error) { - key := s.namespace + "/" + name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(example3v1.Resource("testtypes"), name) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), } - return obj.(*example3v1.TestType), nil } diff --git a/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..10ca8dfd8 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go @@ -0,0 +1,103 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-lister-gen. DO NOT EDIT. + +package v1 + +import ( + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" +) + +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type ClusterTestTypeClusterLister interface { + // List lists all ClusterTestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) + // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister + ClusterTestTypeClusterListerExpansion +} + +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. +type clusterTestTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*exampledashedv1.ClusterTestType] +} + +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + +// NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), + } +} + +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } +} + +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister for one namespace. +type clusterTestTypeLister struct { + kcplisters.ResourceIndexer[*exampledashedv1.ClusterTestType] +} + +var _ ClusterTestTypeLister = new(clusterTestTypeLister) + +// ClusterTestTypeLister can list all ClusterTestTypes, or get one in particular. +// All objects returned here must be treated as read-only. +type ClusterTestTypeLister interface { + // List lists all ClusterTestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) + // Get retrieves the ClusterTestType from the indexer for a given workspace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*exampledashedv1.ClusterTestType, error) + ClusterTestTypeListerExpansion +} + +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), + } +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + kcplisters.ResourceIndexer[*exampledashedv1.ClusterTestType] +} diff --git a/examples/pkg/kcp/clients/listers/example/v1/testtype_expansion.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/expansion_generated.go similarity index 61% rename from examples/pkg/kcp/clients/listers/example/v1/testtype_expansion.go rename to examples/pkg/kcp/clients/listers/exampledashed/v1/expansion_generated.go index 3f50c325f..1ef10b740 100644 --- a/examples/pkg/kcp/clients/listers/example/v1/testtype_expansion.go +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,15 +14,26 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 -// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} + +// ClusterTestTypeListerExpansion allows custom methods to be added to +// ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. type TestTypeClusterListerExpansion interface{} -// TestTypeListerExpansion allows custom methods to be added to TestTypeLister. +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. type TestTypeListerExpansion interface{} -// TestTypeNamespaceListerExpansion allows custom methods to be added to TestTypeNamespaceLister. +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go new file mode 100644 index 000000000..da17fabc3 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go @@ -0,0 +1,138 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-lister-gen. DO NOT EDIT. + +package v1 + +import ( + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" +) + +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type TestTypeClusterLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) + // Cluster returns a lister that can list and get TestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) TestTypeLister + TestTypeClusterListerExpansion +} + +// testTypeClusterLister implements the TestTypeClusterLister interface. +type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*exampledashedv1.TestType] +} + +var _ TestTypeClusterLister = new(testTypeClusterLister) + +// NewTestTypeClusterLister returns a new TestTypeClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), + } +} + +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } +} + +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. +type testTypeLister struct { + kcplisters.ResourceIndexer[*exampledashedv1.TestType] +} + +var _ TestTypeLister = new(testTypeLister) + +// TestTypeLister can list TestTypes across all namespaces, or scope down to a TestTypeNamespaceLister for one namespace. +// All objects returned here must be treated as read-only. +type TestTypeLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) + // TestTypes returns a lister that can list and get TestTypes in one workspace and namespace. + TestTypes(namespace string) TestTypeNamespaceLister + TestTypeListerExpansion +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} + +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*exampledashedv1.TestType] +} + +var _ TestTypeNamespaceLister = new(testTypeNamespaceLister) + +// TestTypeNamespaceLister can list all TestTypes, or get one in particular. +// All objects returned here must be treated as read-only. +type TestTypeNamespaceLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) + // Get retrieves the TestType from the indexer for a given workspace, namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*exampledashedv1.TestType, error) + TestTypeNamespaceListerExpansion +} + +// NewTestTypeLister returns a new TestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), + } +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + kcplisters.ResourceIndexer[*exampledashedv1.TestType] +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} diff --git a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype.go index 86084abc8..4d96f1630 100644 --- a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. @@ -43,36 +40,43 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*existinginterfacesv1.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), + } } -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*existinginterfacesv1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*existinginterfacesv1.ClusterTestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister for one namespace. +type clusterTestTypeLister struct { + kcplisters.ResourceIndexer[*existinginterfacesv1.ClusterTestType] } +var _ ClusterTestTypeLister = new(clusterTestTypeLister) + // ClusterTestTypeLister can list all ClusterTestTypes, or get one in particular. // All objects returned here must be treated as read-only. type ClusterTestTypeLister interface { - // List lists all ClusterTestTypes in the workspace. + // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*existinginterfacesv1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the indexer for a given workspace and name. @@ -81,63 +85,19 @@ type ClusterTestTypeLister interface { ClusterTestTypeListerExpansion } -// clusterTestTypeLister can list all ClusterTestTypes inside a workspace. -type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*existinginterfacesv1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*existinginterfacesv1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*existinginterfacesv1.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(existinginterfacesv1.Resource("clustertesttypes"), name) - } - return obj.(*existinginterfacesv1.ClusterTestType), nil -} - // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -func NewClusterTestTypeLister(indexer cache.Indexer) *clusterTestTypeScopedLister { - return &clusterTestTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), + } } -// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace. +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeScopedLister) List(selector labels.Selector) (ret []*existinginterfacesv1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*existinginterfacesv1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeScopedLister) Get(name string) (*existinginterfacesv1.ClusterTestType, error) { - key := name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(existinginterfacesv1.Resource("clustertesttypes"), name) - } - return obj.(*existinginterfacesv1.ClusterTestType), nil + kcplisters.ResourceIndexer[*existinginterfacesv1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype_expansion.go b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype_expansion.go deleted file mode 100644 index a85e878f1..000000000 --- a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype_expansion.go +++ /dev/null @@ -1,28 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by kcp code-generator. DO NOT EDIT. - -package v1 - -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. -type ClusterTestTypeClusterListerExpansion interface{} - -// ClusterTestTypeListerExpansion allows custom methods to be added to ClusterTestTypeLister. -type ClusterTestTypeListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/secondexample/v1/testtype_expansion.go b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/expansion_generated.go similarity index 61% rename from examples/pkg/kcp/clients/listers/secondexample/v1/testtype_expansion.go rename to examples/pkg/kcp/clients/listers/existinginterfaces/v1/expansion_generated.go index 3f50c325f..1ef10b740 100644 --- a/examples/pkg/kcp/clients/listers/secondexample/v1/testtype_expansion.go +++ b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,15 +14,26 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 -// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} + +// ClusterTestTypeListerExpansion allows custom methods to be added to +// ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. type TestTypeClusterListerExpansion interface{} -// TestTypeListerExpansion allows custom methods to be added to TestTypeLister. +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. type TestTypeListerExpansion interface{} -// TestTypeNamespaceListerExpansion allows custom methods to be added to TestTypeNamespaceLister. +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype.go b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype.go index 06787be9e..30c95e27c 100644 --- a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. // All objects returned here must be treated as read-only. type TestTypeClusterLister interface { // List lists all TestTypes in the indexer. @@ -43,37 +40,44 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*existinginterfacesv1.TestType] } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), + } } -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*existinginterfacesv1.TestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. +type testTypeLister struct { + kcplisters.ResourceIndexer[*existinginterfacesv1.TestType] } +var _ TestTypeLister = new(testTypeLister) + // TestTypeLister can list TestTypes across all namespaces, or scope down to a TestTypeNamespaceLister for one namespace. // All objects returned here must be treated as read-only. type TestTypeLister interface { - // List lists all TestTypes in the workspace. + // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) // TestTypes returns a lister that can list and get TestTypes in one workspace and namespace. @@ -81,29 +85,25 @@ type TestTypeLister interface { TestTypeListerExpansion } -// testTypeLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. -type testTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*existinginterfacesv1.TestType)) - }) - return ret, err +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*existinginterfacesv1.TestType] } -// TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} -} +var _ TestTypeNamespaceLister = new(testTypeNamespaceLister) -// testTypeNamespaceLister helps list and get TestTypes. +// TestTypeNamespaceLister can list all TestTypes, or get one in particular. // All objects returned here must be treated as read-only. type TestTypeNamespaceLister interface { - // List lists all TestTypes in the workspace and namespace. + // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) // Get retrieves the TestType from the indexer for a given workspace, namespace and name. @@ -112,85 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// testTypeNamespaceLister helps list and get TestTypes. -// All objects returned here must be treated as read-only. -type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string -} - -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*existinginterfacesv1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*existinginterfacesv1.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(existinginterfacesv1.Resource("testtypes"), name) - } - return obj.(*existinginterfacesv1.TestType), nil -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index -func NewTestTypeLister(indexer cache.Indexer) *testTypeScopedLister { - return &testTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), + } } -// testTypeScopedLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeScopedLister) List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*existinginterfacesv1.TestType)) - }) - return ret, err + kcplisters.ResourceIndexer[*existinginterfacesv1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return &testTypeScopedNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// testTypeScopedNamespaceLister helps list and get TestTypes. -type testTypeScopedNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeScopedNamespaceLister) List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*existinginterfacesv1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeScopedNamespaceLister) Get(name string) (*existinginterfacesv1.TestType, error) { - key := s.namespace + "/" + name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(existinginterfacesv1.Resource("testtypes"), name) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), } - return obj.(*existinginterfacesv1.TestType), nil } diff --git a/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype.go index 98552b722..d28191bc9 100644 --- a/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. @@ -43,36 +40,43 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*secondexamplev1.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), + } } -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*secondexamplev1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*secondexamplev1.ClusterTestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister for one namespace. +type clusterTestTypeLister struct { + kcplisters.ResourceIndexer[*secondexamplev1.ClusterTestType] } +var _ ClusterTestTypeLister = new(clusterTestTypeLister) + // ClusterTestTypeLister can list all ClusterTestTypes, or get one in particular. // All objects returned here must be treated as read-only. type ClusterTestTypeLister interface { - // List lists all ClusterTestTypes in the workspace. + // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*secondexamplev1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the indexer for a given workspace and name. @@ -81,63 +85,19 @@ type ClusterTestTypeLister interface { ClusterTestTypeListerExpansion } -// clusterTestTypeLister can list all ClusterTestTypes inside a workspace. -type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*secondexamplev1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*secondexamplev1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*secondexamplev1.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(secondexamplev1.Resource("clustertesttypes"), name) - } - return obj.(*secondexamplev1.ClusterTestType), nil -} - // NewClusterTestTypeLister returns a new ClusterTestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -func NewClusterTestTypeLister(indexer cache.Indexer) *clusterTestTypeScopedLister { - return &clusterTestTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), + } } -// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace. +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a ClusterTestTypeNamespaceLister. type clusterTestTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeScopedLister) List(selector labels.Selector) (ret []*secondexamplev1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*secondexamplev1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeScopedLister) Get(name string) (*secondexamplev1.ClusterTestType, error) { - key := name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(secondexamplev1.Resource("clustertesttypes"), name) - } - return obj.(*secondexamplev1.ClusterTestType), nil + kcplisters.ResourceIndexer[*secondexamplev1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype_expansion.go b/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype_expansion.go deleted file mode 100644 index a85e878f1..000000000 --- a/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype_expansion.go +++ /dev/null @@ -1,28 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by kcp code-generator. DO NOT EDIT. - -package v1 - -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. -type ClusterTestTypeClusterListerExpansion interface{} - -// ClusterTestTypeListerExpansion allows custom methods to be added to ClusterTestTypeLister. -type ClusterTestTypeListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/secondexample/v1/expansion_generated.go b/examples/pkg/kcp/clients/listers/secondexample/v1/expansion_generated.go new file mode 100644 index 000000000..1ef10b740 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/secondexample/v1/expansion_generated.go @@ -0,0 +1,39 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-lister-gen. DO NOT EDIT. + +package v1 + +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} + +// ClusterTestTypeListerExpansion allows custom methods to be added to +// ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} + +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. +type TestTypeListerExpansion interface{} + +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. +type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/secondexample/v1/testtype.go b/examples/pkg/kcp/clients/listers/secondexample/v1/testtype.go index 96f29577d..697b34d19 100644 --- a/examples/pkg/kcp/clients/listers/secondexample/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/secondexample/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,22 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. // All objects returned here must be treated as read-only. type TestTypeClusterLister interface { // List lists all TestTypes in the indexer. @@ -43,37 +40,44 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*secondexamplev1.TestType] } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), + } } -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*secondexamplev1.TestType)) - }) - return ret, err +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. +type testTypeLister struct { + kcplisters.ResourceIndexer[*secondexamplev1.TestType] } +var _ TestTypeLister = new(testTypeLister) + // TestTypeLister can list TestTypes across all namespaces, or scope down to a TestTypeNamespaceLister for one namespace. // All objects returned here must be treated as read-only. type TestTypeLister interface { - // List lists all TestTypes in the workspace. + // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) // TestTypes returns a lister that can list and get TestTypes in one workspace and namespace. @@ -81,29 +85,25 @@ type TestTypeLister interface { TestTypeListerExpansion } -// testTypeLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. -type testTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*secondexamplev1.TestType)) - }) - return ret, err +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*secondexamplev1.TestType] } -// TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} -} +var _ TestTypeNamespaceLister = new(testTypeNamespaceLister) -// testTypeNamespaceLister helps list and get TestTypes. +// TestTypeNamespaceLister can list all TestTypes, or get one in particular. // All objects returned here must be treated as read-only. type TestTypeNamespaceLister interface { - // List lists all TestTypes in the workspace and namespace. + // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) // Get retrieves the TestType from the indexer for a given workspace, namespace and name. @@ -112,85 +112,27 @@ type TestTypeNamespaceLister interface { TestTypeNamespaceListerExpansion } -// testTypeNamespaceLister helps list and get TestTypes. -// All objects returned here must be treated as read-only. -type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string -} - -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*secondexamplev1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*secondexamplev1.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(secondexamplev1.Resource("testtypes"), name) - } - return obj.(*secondexamplev1.TestType), nil -} - // NewTestTypeLister returns a new TestTypeLister. // We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index -func NewTestTypeLister(indexer cache.Indexer) *testTypeScopedLister { - return &testTypeScopedLister{indexer: indexer} +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), + } } -// testTypeScopedLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a TestTypeNamespaceLister for one namespace. type testTypeScopedLister struct { - indexer cache.Indexer -} - -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeScopedLister) List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*secondexamplev1.TestType)) - }) - return ret, err + kcplisters.ResourceIndexer[*secondexamplev1.TestType] } // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { - return &testTypeScopedNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// testTypeScopedNamespaceLister helps list and get TestTypes. -type testTypeScopedNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeScopedNamespaceLister) List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*secondexamplev1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeScopedNamespaceLister) Get(name string) (*secondexamplev1.TestType, error) { - key := s.namespace + "/" + name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(secondexamplev1.Resource("testtypes"), name) +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), } - return obj.(*secondexamplev1.TestType), nil } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go b/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go index 5db861f6a..99943d9d1 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,20 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. -package clientset +package versioned import ( - "fmt" - "net/http" - - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" - - "k8s.io/client-go/discovery" - "k8s.io/client-go/rest" - "k8s.io/client-go/util/flowcontrol" + fmt "fmt" + http "net/http" client "acme.corp/pkg/generated/clientset/versioned" examplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1" @@ -38,36 +28,46 @@ import ( examplev1beta1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1" + + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type ClusterInterface interface { Cluster(logicalcluster.Path) client.Interface Discovery() discovery.DiscoveryInterface - Example3V1() example3v1.Example3V1ClusterInterface ExampleV1() examplev1.ExampleV1ClusterInterface ExampleV1alpha1() examplev1alpha1.ExampleV1alpha1ClusterInterface ExampleV1beta1() examplev1beta1.ExampleV1beta1ClusterInterface ExampleV2() examplev2.ExampleV2ClusterInterface + Example3V1() example3v1.Example3V1ClusterInterface + ExampleDashedV1() exampledashedv1.ExampleDashedV1ClusterInterface ExistinginterfacesV1() existinginterfacesv1.ExistinginterfacesV1ClusterInterface SecondexampleV1() secondexamplev1.SecondexampleV1ClusterInterface } -// ClusterClientset contains the clients for groups. +// ClusterClientset contains the cluster clients for groups. type ClusterClientset struct { *discovery.DiscoveryClient clientCache kcpclient.Cache[*client.Clientset] - example3V1 *example3v1.Example3V1ClusterClient exampleV1 *examplev1.ExampleV1ClusterClient exampleV1alpha1 *examplev1alpha1.ExampleV1alpha1ClusterClient exampleV1beta1 *examplev1beta1.ExampleV1beta1ClusterClient exampleV2 *examplev2.ExampleV2ClusterClient + example3V1 *example3v1.Example3V1ClusterClient + exampleDashedV1 *exampledashedv1.ExampleDashedV1ClusterClient existinginterfacesV1 *existinginterfacesv1.ExistinginterfacesV1ClusterClient secondexampleV1 *secondexamplev1.SecondexampleV1ClusterClient } -// Discovery retrieves the DiscoveryClient +// Discovery retrieves the DiscoveryClient. func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { if c == nil { return nil @@ -75,11 +75,6 @@ func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { return c.DiscoveryClient } -// Example3V1 retrieves the Example3V1ClusterClient. -func (c *ClusterClientset) Example3V1() example3v1.Example3V1ClusterInterface { - return c.example3V1 -} - // ExampleV1 retrieves the ExampleV1ClusterClient. func (c *ClusterClientset) ExampleV1() examplev1.ExampleV1ClusterInterface { return c.exampleV1 @@ -100,6 +95,16 @@ func (c *ClusterClientset) ExampleV2() examplev2.ExampleV2ClusterInterface { return c.exampleV2 } +// Example3V1 retrieves the Example3V1ClusterClient. +func (c *ClusterClientset) Example3V1() example3v1.Example3V1ClusterInterface { + return c.example3V1 +} + +// ExampleDashedV1 retrieves the ExampleDashedV1ClusterClient. +func (c *ClusterClientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1ClusterInterface { + return c.exampleDashedV1 +} + // ExistinginterfacesV1 retrieves the ExistinginterfacesV1ClusterClient. func (c *ClusterClientset) ExistinginterfacesV1() existinginterfacesv1.ExistinginterfacesV1ClusterInterface { return c.existinginterfacesV1 @@ -162,10 +167,6 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli var cs ClusterClientset cs.clientCache = cache var err error - cs.example3V1, err = example3v1.NewForConfigAndClient(&configShallowCopy, httpClient) - if err != nil { - return nil, err - } cs.exampleV1, err = examplev1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err @@ -182,6 +183,14 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli if err != nil { return nil, err } + cs.example3V1, err = example3v1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } + cs.exampleDashedV1, err = exampledashedv1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } cs.existinginterfacesV1, err = existinginterfacesv1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err @@ -207,3 +216,19 @@ func NewForConfigOrDie(c *rest.Config) *ClusterClientset { } return cs } + +// New creates a new ClusterClientset for the given RESTClient. +func New(c *rest.Config) *ClusterClientset { + var cs ClusterClientset + cs.exampleV1 = examplev1.NewForConfigOrDie(c) + cs.exampleV1alpha1 = examplev1alpha1.NewForConfigOrDie(c) + cs.exampleV1beta1 = examplev1beta1.NewForConfigOrDie(c) + cs.exampleV2 = examplev2.NewForConfigOrDie(c) + cs.example3V1 = example3v1.NewForConfigOrDie(c) + cs.exampleDashedV1 = exampledashedv1.NewForConfigOrDie(c) + cs.existinginterfacesV1 = existinginterfacesv1.NewForConfigOrDie(c) + cs.secondexampleV1 = secondexamplev1.NewForConfigOrDie(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) + return &cs +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go b/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go index ec95d4394..531cdcc36 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,69 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcpfakediscovery "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/discovery/fake" - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/client-go/discovery" - - client "acme.corp/pkg/generated/clientset/versioned" - clientscheme "acme.corp/pkg/generated/clientset/versioned/scheme" + applyconfigurations "acme.corp/pkg/generated/applyconfigurations" + clientset "acme.corp/pkg/generated/clientset/versioned" examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" - kcpclient "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + kcpclientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + kcpclientscheme "acme.corp/pkg/kcpexisting/clients/clientset/versioned/scheme" kcpexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1" - fakeexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake" + kcpfakeexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake" kcpexamplev1alpha1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1" - fakeexamplev1alpha1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake" + kcpfakeexamplev1alpha1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake" kcpexamplev1beta1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1" - fakeexamplev1beta1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake" + kcpfakeexamplev1beta1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake" kcpexamplev2 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2" - fakeexamplev2 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake" + kcpfakeexamplev2 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake" kcpexample3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1" - fakeexample3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake" + kcpfakeexample3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake" + kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" + kcpfakeexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake" kcpexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1" - fakeexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake" + kcpfakeexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake" kcpsecondexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1" - fakesecondexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake" + kcpfakesecondexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake" + + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/discovery" + + kcpfakediscovery "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/discovery/fake" + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) // NewSimpleClientset returns a clientset that will respond with the provided objects. // It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement +// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement // for a real clientset and is mostly useful in simple unit tests. +// +// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves +// server side apply testing. NewClientset is only available when apply configurations are generated (e.g. +// via --with-applyconfig). func NewSimpleClientset(objects ...runtime.Object) *ClusterClientset { - o := kcptesting.NewObjectTracker(clientscheme.Scheme, clientscheme.Codecs.UniversalDecoder()) + o := kcptesting.NewObjectTracker(kcpclientscheme.Scheme, kcpclientscheme.Codecs.UniversalDecoder()) o.AddAll(objects...) - cs := &ClusterClientset{Fake: &kcptesting.Fake{}, tracker: o} - cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: cs.Fake, ClusterPath: logicalcluster.Wildcard} + cs := &ClusterClientset{Fake: kcptesting.Fake{}, tracker: o} + cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: &cs.Fake, ClusterPath: logicalcluster.Wildcard} cs.AddReactor("*", "*", kcptesting.ObjectReaction(o)) cs.AddWatchReactor("*", kcptesting.WatchReaction(o)) return cs } -var _ kcpclient.ClusterInterface = (*ClusterClientset)(nil) - // ClusterClientset contains the clients for groups. type ClusterClientset struct { - *kcptesting.Fake + kcptesting.Fake discovery *kcpfakediscovery.FakeDiscovery tracker kcptesting.ObjectTracker } +var _ kcpclientset.ClusterInterface = (*ClusterClientset)(nil) + // Discovery retrieves the DiscoveryClient func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { return c.discovery @@ -89,57 +94,62 @@ func (c *ClusterClientset) Tracker() kcptesting.ObjectTracker { return c.tracker } -// Example3V1 retrieves the Example3V1ClusterClient. -func (c *ClusterClientset) Example3V1() kcpexample3v1.Example3V1ClusterInterface { - return &fakeexample3v1.Example3V1ClusterClient{Fake: c.Fake} +// Cluster scopes this clientset to one cluster. +func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) clientset.Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &Clientset{ + Fake: &c.Fake, + discovery: &kcpfakediscovery.FakeDiscovery{Fake: &c.Fake, ClusterPath: clusterPath}, + tracker: c.tracker.Cluster(clusterPath), + clusterPath: clusterPath, + } } -// ExampleV1 retrieves the ExampleV1ClusterClient. +// ExampleV1 retrieves the ExampleV1ClusterClient func (c *ClusterClientset) ExampleV1() kcpexamplev1.ExampleV1ClusterInterface { - return &fakeexamplev1.ExampleV1ClusterClient{Fake: c.Fake} + return &kcpfakeexamplev1.ExampleV1ClusterClient{Fake: &c.Fake} } -// ExampleV1alpha1 retrieves the ExampleV1alpha1ClusterClient. +// ExampleV1alpha1 retrieves the ExampleV1alpha1ClusterClient func (c *ClusterClientset) ExampleV1alpha1() kcpexamplev1alpha1.ExampleV1alpha1ClusterInterface { - return &fakeexamplev1alpha1.ExampleV1alpha1ClusterClient{Fake: c.Fake} + return &kcpfakeexamplev1alpha1.ExampleV1alpha1ClusterClient{Fake: &c.Fake} } -// ExampleV1beta1 retrieves the ExampleV1beta1ClusterClient. +// ExampleV1beta1 retrieves the ExampleV1beta1ClusterClient func (c *ClusterClientset) ExampleV1beta1() kcpexamplev1beta1.ExampleV1beta1ClusterInterface { - return &fakeexamplev1beta1.ExampleV1beta1ClusterClient{Fake: c.Fake} + return &kcpfakeexamplev1beta1.ExampleV1beta1ClusterClient{Fake: &c.Fake} } -// ExampleV2 retrieves the ExampleV2ClusterClient. +// ExampleV2 retrieves the ExampleV2ClusterClient func (c *ClusterClientset) ExampleV2() kcpexamplev2.ExampleV2ClusterInterface { - return &fakeexamplev2.ExampleV2ClusterClient{Fake: c.Fake} + return &kcpfakeexamplev2.ExampleV2ClusterClient{Fake: &c.Fake} } -// ExistinginterfacesV1 retrieves the ExistinginterfacesV1ClusterClient. -func (c *ClusterClientset) ExistinginterfacesV1() kcpexistinginterfacesv1.ExistinginterfacesV1ClusterInterface { - return &fakeexistinginterfacesv1.ExistinginterfacesV1ClusterClient{Fake: c.Fake} +// Example3V1 retrieves the Example3V1ClusterClient +func (c *ClusterClientset) Example3V1() kcpexample3v1.Example3V1ClusterInterface { + return &kcpfakeexample3v1.Example3V1ClusterClient{Fake: &c.Fake} } -// SecondexampleV1 retrieves the SecondexampleV1ClusterClient. -func (c *ClusterClientset) SecondexampleV1() kcpsecondexamplev1.SecondexampleV1ClusterInterface { - return &fakesecondexamplev1.SecondexampleV1ClusterClient{Fake: c.Fake} +// ExampleDashedV1 retrieves the ExampleDashedV1ClusterClient +func (c *ClusterClientset) ExampleDashedV1() kcpexampledashedv1.ExampleDashedV1ClusterInterface { + return &kcpfakeexampledashedv1.ExampleDashedV1ClusterClient{Fake: &c.Fake} } -// Cluster scopes this clientset to one cluster. -func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - return &Clientset{ - Fake: c.Fake, - discovery: &kcpfakediscovery.FakeDiscovery{Fake: c.Fake, ClusterPath: clusterPath}, - tracker: c.tracker.Cluster(clusterPath), - clusterPath: clusterPath, - } +// ExistinginterfacesV1 retrieves the ExistinginterfacesV1ClusterClient +func (c *ClusterClientset) ExistinginterfacesV1() kcpexistinginterfacesv1.ExistinginterfacesV1ClusterInterface { + return &kcpfakeexistinginterfacesv1.ExistinginterfacesV1ClusterClient{Fake: &c.Fake} } -var _ client.Interface = (*Clientset)(nil) +// SecondexampleV1 retrieves the SecondexampleV1ClusterClient +func (c *ClusterClientset) SecondexampleV1() kcpsecondexamplev1.SecondexampleV1ClusterInterface { + return &kcpfakesecondexamplev1.SecondexampleV1ClusterClient{Fake: &c.Fake} +} -// Clientset contains the clients for groups. +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. type Clientset struct { *kcptesting.Fake discovery *kcpfakediscovery.FakeDiscovery @@ -147,7 +157,11 @@ type Clientset struct { clusterPath logicalcluster.Path } -// Discovery retrieves the DiscoveryClient +var ( + _ clientset.Interface = &Clientset{} + _ kcptesting.FakeScopedClient = &Clientset{} +) + func (c *Clientset) Discovery() discovery.DiscoveryInterface { return c.discovery } @@ -156,37 +170,62 @@ func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { return c.tracker } -// Example3V1 retrieves the Example3V1Client. -func (c *Clientset) Example3V1() example3v1.Example3V1Interface { - return &fakeexample3v1.Example3V1Client{Fake: c.Fake, ClusterPath: c.clusterPath} +// NewClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewClientset(objects ...runtime.Object) *ClusterClientset { + o := kcptesting.NewFieldManagedObjectTracker( + kcpclientscheme.Scheme, + kcpclientscheme.Codecs.UniversalDecoder(), + applyconfigurations.NewTypeConverter(kcpclientscheme.Scheme), + ) + o.AddAll(objects...) + + cs := &ClusterClientset{Fake: kcptesting.Fake{}, tracker: o} + cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: &cs.Fake, ClusterPath: logicalcluster.Wildcard} + cs.AddReactor("*", "*", kcptesting.ObjectReaction(o)) + cs.AddWatchReactor("*", kcptesting.WatchReaction(o)) + + return cs } -// ExampleV1 retrieves the ExampleV1Client. +// ExampleV1 retrieves the ExampleV1Client func (c *Clientset) ExampleV1() examplev1.ExampleV1Interface { - return &fakeexamplev1.ExampleV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} + return &kcpfakeexamplev1.ExampleV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } -// ExampleV1alpha1 retrieves the ExampleV1alpha1Client. +// ExampleV1alpha1 retrieves the ExampleV1alpha1Client func (c *Clientset) ExampleV1alpha1() examplev1alpha1.ExampleV1alpha1Interface { - return &fakeexamplev1alpha1.ExampleV1alpha1Client{Fake: c.Fake, ClusterPath: c.clusterPath} + return &kcpfakeexamplev1alpha1.ExampleV1alpha1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } -// ExampleV1beta1 retrieves the ExampleV1beta1Client. +// ExampleV1beta1 retrieves the ExampleV1beta1Client func (c *Clientset) ExampleV1beta1() examplev1beta1.ExampleV1beta1Interface { - return &fakeexamplev1beta1.ExampleV1beta1Client{Fake: c.Fake, ClusterPath: c.clusterPath} + return &kcpfakeexamplev1beta1.ExampleV1beta1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } -// ExampleV2 retrieves the ExampleV2Client. +// ExampleV2 retrieves the ExampleV2Client func (c *Clientset) ExampleV2() examplev2.ExampleV2Interface { - return &fakeexamplev2.ExampleV2Client{Fake: c.Fake, ClusterPath: c.clusterPath} + return &kcpfakeexamplev2.ExampleV2Client{Fake: c.Fake, ClusterPath: c.clusterPath} +} + +// Example3V1 retrieves the Example3V1Client +func (c *Clientset) Example3V1() example3v1.Example3V1Interface { + return &kcpfakeexample3v1.Example3V1Client{Fake: c.Fake, ClusterPath: c.clusterPath} +} + +// ExampleDashedV1 retrieves the ExampleDashedV1Client +func (c *Clientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1Interface { + return &kcpfakeexampledashedv1.ExampleDashedV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } -// ExistinginterfacesV1 retrieves the ExistinginterfacesV1Client. +// ExistinginterfacesV1 retrieves the ExistinginterfacesV1Client func (c *Clientset) ExistinginterfacesV1() existinginterfacesv1.ExistinginterfacesV1Interface { - return &fakeexistinginterfacesv1.ExistinginterfacesV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} + return &kcpfakeexistinginterfacesv1.ExistinginterfacesV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } -// SecondexampleV1 retrieves the SecondexampleV1Client. +// SecondexampleV1 retrieves the SecondexampleV1Client func (c *Clientset) SecondexampleV1() secondexamplev1.SecondexampleV1Interface { - return &fakesecondexamplev1.SecondexampleV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} + return &kcpfakesecondexamplev1.SecondexampleV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/fake/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/fake/doc.go new file mode 100644 index 000000000..95b1bc650 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated fake clientset. +package fake diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/fake/register.go b/examples/pkg/kcpexisting/clients/clientset/versioned/fake/register.go new file mode 100644 index 000000000..7d674fea4 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/fake/register.go @@ -0,0 +1,71 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package fake + +import ( + examplev1 "acme.corp/pkg/apis/example/v1" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + examplev2 "acme.corp/pkg/apis/example/v2" + example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) + +var localSchemeBuilder = runtime.SchemeBuilder{ + examplev1.AddToScheme, + examplev1alpha1.AddToScheme, + examplev1beta1.AddToScheme, + examplev2.AddToScheme, + example3v1.AddToScheme, + exampledashedv1.AddToScheme, + existinginterfacesv1.AddToScheme, + secondexamplev1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(scheme)) +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/doc.go new file mode 100644 index 000000000..928f59990 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go b/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go index 2a57d2e75..203e3b2d6 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,35 +14,37 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package scheme import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/runtime/serializer" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - examplev1 "acme.corp/pkg/apis/example/v1" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" ) var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - example3v1.AddToScheme, examplev1.AddToScheme, examplev1alpha1.AddToScheme, examplev1beta1.AddToScheme, examplev2.AddToScheme, + example3v1.AddToScheme, + exampledashedv1.AddToScheme, existinginterfacesv1.AddToScheme, secondexamplev1.AddToScheme, } @@ -67,6 +66,6 @@ var localSchemeBuilder = runtime.SchemeBuilder{ var AddToScheme = localSchemeBuilder.AddToScheme func init() { - metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) utilruntime.Must(AddToScheme(Scheme)) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/clustertesttype.go index e11f623f4..47ed6e3e6 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - examplev1 "acme.corp/pkg/apis/example/v1" - examplev1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a examplev1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a examplev1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) examplev1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*examplev1.ClusterTestTypeList, error) + Cluster(logicalcluster.Path) examplev1.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*apisexamplev1.ClusterTestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1client.ExampleV1Client] + clientCache kcpclient.Cache[*examplev1.ExampleV1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev1client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev1.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,7 +60,7 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*examplev1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*apisexamplev1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/doc.go new file mode 100644 index 000000000..dc2c8e634 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/example_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/example_client.go index e1ef8111c..7fed4fa05 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/example_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,25 +14,27 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + scheme "acme.corp/pkg/kcpexisting/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type ExampleV1ClusterInterface interface { ExampleV1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter WithoutVerbTypesClusterGetter } @@ -43,6 +42,7 @@ type ExampleV1ClusterScoper interface { Cluster(logicalcluster.Path) examplev1.ExampleV1Interface } +// ExampleV1ClusterClient is used to interact with features provided by the example.dev group. type ExampleV1ClusterClient struct { clientCache kcpclient.Cache[*examplev1.ExampleV1Client] } @@ -54,14 +54,14 @@ func (c *ExampleV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampl return c.clientCache.ClusterOrDie(clusterPath) } -func (c *ExampleV1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *ExampleV1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *ExampleV1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + func (c *ExampleV1ClusterClient) WithoutVerbTypes() WithoutVerbTypeClusterInterface { return &withoutVerbTypesClusterInterface{clientCache: c.clientCache} } @@ -70,11 +70,13 @@ func (c *ExampleV1ClusterClient) WithoutVerbTypes() WithoutVerbTypeClusterInterf // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExampleV1ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new ExampleV1ClusterClient for the given config and http client. @@ -86,6 +88,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV1ClusterCli if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &ExampleV1ClusterClient{clientCache: cache}, nil } @@ -98,3 +101,14 @@ func NewForConfigOrDie(c *rest.Config) *ExampleV1ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apisexamplev1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/clustertesttype.go index 225988045..78ae615a8 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev1 "acme.corp/pkg/apis/example/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/example/v1" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + typedkcpexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - examplev1 "acme.corp/pkg/apis/example/v1" - applyconfigurationsexamplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" - examplev1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) examplev1client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &examplev1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1.ClusterTestTypeList{ListMeta: obj.(*examplev1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *ExampleV1ClusterClient) typedkcpexamplev1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList]( + fake.Fake, + examplev1.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev1.ClusterTestType { return &examplev1.ClusterTestType{} }, + func() *examplev1.ClusterTestTypeList { return &examplev1.ClusterTestTypeList{} }, + func(dst, src *examplev1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1.ClusterTestTypeList) []*examplev1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1.ClusterTestTypeList, items []*examplev1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexamplev1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *examplev1.ClusterTestType, opts metav1.CreateOptions) (*examplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *examplev1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *examplev1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &examplev1.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &examplev1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1.ClusterTestTypeList{ListMeta: obj.(*examplev1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &examplev1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexamplev1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + examplev1.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev1.ClusterTestType { return &examplev1.ClusterTestType{} }, + func() *examplev1.ClusterTestTypeList { return &examplev1.ClusterTestTypeList{} }, + func(dst, src *examplev1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1.ClusterTestTypeList) []*examplev1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1.ClusterTestTypeList, items []*examplev1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev1.ClusterTestType), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/example_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/example_client.go index 8df712207..2ebcb2a8b 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/example_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" kcpexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpexamplev1.ExampleV1ClusterInterface = (*ExampleV1ClusterClient)(nil) @@ -44,38 +41,38 @@ func (c *ExampleV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampl return &ExampleV1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *ExampleV1ClusterClient) TestTypes() kcpexamplev1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} +func (c *ExampleV1ClusterClient) ClusterTestTypes() kcpexamplev1.ClusterTestTypeClusterInterface { + return newFakeClusterTestTypeClusterClient(c) } -func (c *ExampleV1ClusterClient) ClusterTestTypes() kcpexamplev1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} +func (c *ExampleV1ClusterClient) TestTypes() kcpexamplev1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) } func (c *ExampleV1ClusterClient) WithoutVerbTypes() kcpexamplev1.WithoutVerbTypeClusterInterface { - return &withoutVerbTypesClusterClient{Fake: c.Fake} + return newFakeWithoutVerbTypeClusterClient(c) } -var _ examplev1.ExampleV1Interface = (*ExampleV1Client)(nil) - type ExampleV1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *ExampleV1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *ExampleV1Client) ClusterTestTypes() examplev1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *ExampleV1Client) TestTypes(namespace string) examplev1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExampleV1Client) ClusterTestTypes() examplev1.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +func (c *ExampleV1Client) WithoutVerbTypes(namespace string) examplev1.WithoutVerbTypeInterface { + return newFakeWithoutVerbTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExampleV1Client) WithoutVerbTypes(namespace string) examplev1.WithoutVerbTypeInterface { - return &withoutVerbTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExampleV1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/testtype.go index 3d59c5df3..6e61e46ec 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,221 +14,116 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" + context "context" - "github.com/kcp-dev/logicalcluster/v3" + examplev1 "acme.corp/pkg/apis/example/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/example/v1" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + typedkcpexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1" - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - examplev1 "acme.corp/pkg/apis/example/v1" - applyconfigurationsexamplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" - examplev1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" - kcpexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) -var testTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1.TestType, *examplev1.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexamplev1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. -func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &examplev1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1.TestTypeList{ListMeta: obj.(*examplev1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeTestTypeClusterClient(fake *ExampleV1ClusterClient) typedkcpexamplev1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev1.TestType, *examplev1.TestTypeList]( + fake.Fake, + examplev1.SchemeGroupVersion.WithResource("testtypes"), + examplev1.SchemeGroupVersion.WithKind("TestType"), + func() *examplev1.TestType { return &examplev1.TestType{} }, + func() *examplev1.TestTypeList { return &examplev1.TestTypeList{} }, + func(dst, src *examplev1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1.TestTypeList) []*examplev1.TestType { return kcpgentype.ToPointerSlice(list.Items) }, + func(list *examplev1.TestTypeList, items []*examplev1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested TestTypes across all clusters. -func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexamplev1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -type testTypesNamespacer struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexamplev1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1.TestType, *examplev1.TestTypeList, *v1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *examplev1.TestType, opts metav1.CreateOptions) (*examplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *examplev1.TestType, opts metav1.UpdateOptions) (*examplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *examplev1.TestType, opts metav1.UpdateOptions) (*examplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &examplev1.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &examplev1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1.TestTypeList{ListMeta: obj.(*examplev1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &examplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1.TestType), err } -func (c *testTypesClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (*examplev1.Field, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(testTypesResource, c.ClusterPath, testTypeName, "field", c.Namespace, field), &examplev1.Field{}) +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexamplev1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev1.TestType, *examplev1.TestTypeList, *v1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + examplev1.SchemeGroupVersion.WithResource("testtypes"), + examplev1.SchemeGroupVersion.WithKind("TestType"), + func() *examplev1.TestType { return &examplev1.TestType{} }, + func() *examplev1.TestTypeList { return &examplev1.TestTypeList{} }, + func(dst, src *examplev1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1.TestTypeList) []*examplev1.TestType { return kcpgentype.ToPointerSlice(list.Items) }, + func(list *examplev1.TestTypeList, items []*examplev1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, + } +} + +// CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypeScopedClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, _ metav1.CreateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(c.Resource(), c.ClusterPath, testTypeName, "field", c.Namespace(), field), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } -func (c *testTypesClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (*examplev1.Field, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, field), &examplev1.Field{}) +// UpdateField takes the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypeScopedClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, _ metav1.UpdateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(c.Resource(), c.ClusterPath, "field", c.Namespace(), field), &examplev1.Field{}) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } -func (c *testTypesClient) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*examplev1.Field, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, testTypeName), &examplev1.Field{}) +// GetField takes name of the testType, and returns the corresponding field object, and an error if there is any. +func (c *testTypeScopedClient) GetField(ctx context.Context, testTypeName string, _ metav1.GetOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(c.Resource(), c.ClusterPath, c.Namespace(), "field", testTypeName), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/withoutverbtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/withoutverbtype.go index 831e4f564..dbba160af 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/withoutverbtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake/withoutverbtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,47 +14,69 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" + examplev1 "acme.corp/pkg/apis/example/v1" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + typedkcpexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/apimachinery/pkg/runtime/schema" - - examplev1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" - kcpexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var withoutVerbTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1", Resource: "withoutverbtypes"} -var withoutVerbTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1", Kind: "WithoutVerbType"} - -type withoutVerbTypesClusterClient struct { - *kcptesting.Fake +// withoutVerbTypeClusterClient implements WithoutVerbTypeClusterInterface +type withoutVerbTypeClusterClient struct { + *kcpgentype.FakeClusterClient[*examplev1.WithoutVerbType] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *withoutVerbTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexamplev1.WithoutVerbTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +func newFakeWithoutVerbTypeClusterClient(fake *ExampleV1ClusterClient) typedkcpexamplev1.WithoutVerbTypeClusterInterface { + return &withoutVerbTypeClusterClient{ + kcpgentype.NewFakeClusterClient[*examplev1.WithoutVerbType]( + fake.Fake, + examplev1.SchemeGroupVersion.WithResource("withoutverbtypes"), + examplev1.SchemeGroupVersion.WithKind("WithoutVerbType"), + func() *examplev1.WithoutVerbType { return &examplev1.WithoutVerbType{} }, + ), + fake.Fake, } +} - return &withoutVerbTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +func (c *withoutVerbTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexamplev1.WithoutVerbTypesNamespacer { + return &withoutVerbTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -type withoutVerbTypesNamespacer struct { +type withoutVerbTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *withoutVerbTypesNamespacer) Namespace(namespace string) examplev1client.WithoutVerbTypeInterface { - return &withoutVerbTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *withoutVerbTypeNamespacer) Namespace(namespace string) typedexamplev1.WithoutVerbTypeInterface { + return newFakeWithoutVerbTypeClient(n.Fake, namespace, n.ClusterPath) } -type withoutVerbTypesClient struct { - *kcptesting.Fake +// withoutVerbTypeScopedClient implements WithoutVerbTypeInterface +type withoutVerbTypeScopedClient struct { + *kcpgentype.FakeClient[*examplev1.WithoutVerbType] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string +} + +func newFakeWithoutVerbTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexamplev1.WithoutVerbTypeInterface { + return &withoutVerbTypeScopedClient{ + kcpgentype.NewFakeClient[*examplev1.WithoutVerbType]( + fake, + clusterPath, + namespace, + examplev1.SchemeGroupVersion.WithResource("withoutverbtypes"), + examplev1.SchemeGroupVersion.WithKind("WithoutVerbType"), + func() *examplev1.WithoutVerbType { return &examplev1.WithoutVerbType{} }, + ), + fake, + clusterPath, + } } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/generated_expansion.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/generated_expansion.go new file mode 100644 index 000000000..1a36817ad --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/generated_expansion.go @@ -0,0 +1,25 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} + +type WithoutVerbTypeClusterExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/testtype.go index c8776540b..42521942e 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + examplev1 "acme.corp/pkg/apis/example/v1" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - examplev1 "acme.corp/pkg/apis/example/v1" - examplev1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -46,10 +43,11 @@ type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer List(ctx context.Context, opts metav1.ListOptions) (*examplev1.TestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1client.ExampleV1Client] + clientCache kcpclient.Cache[*typedexamplev1.ExampleV1Client] } // Cluster scopes the client down to a particular cluster. @@ -71,16 +69,16 @@ func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListO return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) } -// TestTypesNamespacer can scope to objects within a namespace, returning a examplev1client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexamplev1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) examplev1client.TestTypeInterface + Namespace(string) typedexamplev1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*examplev1client.ExampleV1Client] + clientCache kcpclient.Cache[*typedexamplev1.ExampleV1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev1client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedexamplev1.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/withoutverbtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/withoutverbtype.go index b4d4329bd..e17b7629c 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/withoutverbtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/withoutverbtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( + examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" "github.com/kcp-dev/logicalcluster/v3" - - examplev1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" ) // WithoutVerbTypesClusterGetter has a method to return a WithoutVerbTypeClusterInterface. @@ -37,10 +34,12 @@ type WithoutVerbTypesClusterGetter interface { // WithoutVerbTypeClusterInterface can scope down to one cluster and return a WithoutVerbTypesNamespacer. type WithoutVerbTypeClusterInterface interface { Cluster(logicalcluster.Path) WithoutVerbTypesNamespacer + + WithoutVerbTypeClusterExpansion } type withoutVerbTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1client.ExampleV1Client] + clientCache kcpclient.Cache[*examplev1.ExampleV1Client] } // Cluster scopes the client down to a particular cluster. @@ -52,16 +51,16 @@ func (c *withoutVerbTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa return &withoutVerbTypesNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} } -// WithoutVerbTypesNamespacer can scope to objects within a namespace, returning a examplev1client.WithoutVerbTypeInterface. +// WithoutVerbTypesNamespacer can scope to objects within a namespace, returning a examplev1.WithoutVerbTypeInterface. type WithoutVerbTypesNamespacer interface { - Namespace(string) examplev1client.WithoutVerbTypeInterface + Namespace(string) examplev1.WithoutVerbTypeInterface } type withoutVerbTypesNamespacer struct { - clientCache kcpclient.Cache[*examplev1client.ExampleV1Client] + clientCache kcpclient.Cache[*examplev1.ExampleV1Client] clusterPath logicalcluster.Path } -func (n *withoutVerbTypesNamespacer) Namespace(namespace string) examplev1client.WithoutVerbTypeInterface { +func (n *withoutVerbTypesNamespacer) Namespace(namespace string) examplev1.WithoutVerbTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).WithoutVerbTypes(namespace) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/clustertesttype.go index c0f2bba07..b426fa385 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1alpha1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - examplev1alpha1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a examplev1alpha1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a examplev1alpha1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) examplev1alpha1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.ClusterTestTypeList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Cluster(logicalcluster.Path) examplev1alpha1.ClusterTestTypeInterface + List(ctx context.Context, opts v1.ListOptions) (*apisexamplev1alpha1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1alpha1client.ExampleV1alpha1Client] + clientCache kcpclient.Cache[*examplev1alpha1.ExampleV1alpha1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev1alpha1client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev1alpha1.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,11 +60,11 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts v1.ListOptions) (*apisexamplev1alpha1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } // Watch begins to watch all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { +func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().Watch(ctx, opts) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/doc.go new file mode 100644 index 000000000..ca5a1c141 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1alpha1 diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/example_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/example_client.go index e45f76c49..d903e1e46 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/example_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1alpha1 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + scheme "acme.corp/pkg/kcpexisting/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type ExampleV1alpha1ClusterInterface interface { ExampleV1alpha1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter } type ExampleV1alpha1ClusterScoper interface { Cluster(logicalcluster.Path) examplev1alpha1.ExampleV1alpha1Interface } +// ExampleV1alpha1ClusterClient is used to interact with features provided by the example.dev group. type ExampleV1alpha1ClusterClient struct { clientCache kcpclient.Cache[*examplev1alpha1.ExampleV1alpha1Client] } @@ -53,23 +53,25 @@ func (c *ExampleV1alpha1ClusterClient) Cluster(clusterPath logicalcluster.Path) return c.clientCache.ClusterOrDie(clusterPath) } -func (c *ExampleV1alpha1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *ExampleV1alpha1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *ExampleV1alpha1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new ExampleV1alpha1ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExampleV1alpha1ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new ExampleV1alpha1ClusterClient for the given config and http client. @@ -81,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV1alpha1Clus if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &ExampleV1alpha1ClusterClient{clientCache: cache}, nil } @@ -93,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *ExampleV1alpha1ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apisexamplev1alpha1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/clustertesttype.go index e28612369..7f5e7a1f2 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + v1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" + typedexamplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + typedkcpexamplev1alpha1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - applyconfigurationsexamplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" - examplev1alpha1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1alpha1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1alpha1", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) examplev1alpha1client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &examplev1alpha1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1alpha1.ClusterTestTypeList{ListMeta: obj.(*examplev1alpha1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1alpha1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *ExampleV1alpha1ClusterClient) typedkcpexamplev1alpha1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList]( + fake.Fake, + examplev1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev1alpha1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev1alpha1.ClusterTestType { return &examplev1alpha1.ClusterTestType{} }, + func() *examplev1alpha1.ClusterTestTypeList { return &examplev1alpha1.ClusterTestTypeList{} }, + func(dst, src *examplev1alpha1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1alpha1.ClusterTestTypeList) []*examplev1alpha1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1alpha1.ClusterTestTypeList, items []*examplev1alpha1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexamplev1alpha1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList, *v1alpha1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *examplev1alpha1.ClusterTestType, opts metav1.CreateOptions) (*examplev1alpha1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *examplev1alpha1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1alpha1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *examplev1alpha1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1alpha1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &examplev1alpha1.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1alpha1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev1alpha1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &examplev1alpha1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1alpha1.ClusterTestTypeList{ListMeta: obj.(*examplev1alpha1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1alpha1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev1alpha1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1alpha1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1alpha1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1alpha1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1alpha1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &examplev1alpha1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexamplev1alpha1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList, *v1alpha1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + examplev1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev1alpha1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev1alpha1.ClusterTestType { return &examplev1alpha1.ClusterTestType{} }, + func() *examplev1alpha1.ClusterTestTypeList { return &examplev1alpha1.ClusterTestTypeList{} }, + func(dst, src *examplev1alpha1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1alpha1.ClusterTestTypeList) []*examplev1alpha1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1alpha1.ClusterTestTypeList, items []*examplev1alpha1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev1alpha1.ClusterTestType), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/example_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/example_client.go index 7f11d0bab..816d31263 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/example_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" kcpexamplev1alpha1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpexamplev1alpha1.ExampleV1alpha1ClusterInterface = (*ExampleV1alpha1ClusterClient)(nil) @@ -44,30 +41,30 @@ func (c *ExampleV1alpha1ClusterClient) Cluster(clusterPath logicalcluster.Path) return &ExampleV1alpha1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *ExampleV1alpha1ClusterClient) TestTypes() kcpexamplev1alpha1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *ExampleV1alpha1ClusterClient) ClusterTestTypes() kcpexamplev1alpha1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ examplev1alpha1.ExampleV1alpha1Interface = (*ExampleV1alpha1Client)(nil) +func (c *ExampleV1alpha1ClusterClient) TestTypes() kcpexamplev1alpha1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type ExampleV1alpha1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *ExampleV1alpha1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *ExampleV1alpha1Client) ClusterTestTypes() examplev1alpha1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *ExampleV1alpha1Client) TestTypes(namespace string) examplev1alpha1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExampleV1alpha1Client) ClusterTestTypes() examplev1alpha1.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExampleV1alpha1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/testtype.go index ca5bbb7d9..aa710a37d 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,197 +14,86 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + v1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" + typedexamplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + typedkcpexamplev1alpha1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - applyconfigurationsexamplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" - examplev1alpha1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" - kcpexamplev1alpha1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1" + "github.com/kcp-dev/logicalcluster/v3" ) -var testTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1alpha1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1alpha1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexamplev1alpha1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +func newFakeTestTypeClusterClient(fake *ExampleV1alpha1ClusterClient) typedkcpexamplev1alpha1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList]( + fake.Fake, + examplev1alpha1.SchemeGroupVersion.WithResource("testtypes"), + examplev1alpha1.SchemeGroupVersion.WithKind("TestType"), + func() *examplev1alpha1.TestType { return &examplev1alpha1.TestType{} }, + func() *examplev1alpha1.TestTypeList { return &examplev1alpha1.TestTypeList{} }, + func(dst, src *examplev1alpha1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1alpha1.TestTypeList) []*examplev1alpha1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1alpha1.TestTypeList, items []*examplev1alpha1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. -func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &examplev1alpha1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1alpha1.TestTypeList{ListMeta: obj.(*examplev1alpha1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1alpha1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexamplev1alpha1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -// Watch returns a watch.Interface that watches the requested TestTypes across all clusters. -func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) -} - -type testTypesNamespacer struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev1alpha1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexamplev1alpha1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList, *v1alpha1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *examplev1alpha1.TestType, opts metav1.CreateOptions) (*examplev1alpha1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *examplev1alpha1.TestType, opts metav1.UpdateOptions) (*examplev1alpha1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *examplev1alpha1.TestType, opts metav1.UpdateOptions) (*examplev1alpha1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &examplev1alpha1.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1alpha1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev1alpha1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.TestType), err } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &examplev1alpha1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1alpha1.TestTypeList{ListMeta: obj.(*examplev1alpha1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1alpha1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev1alpha1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1alpha1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1alpha1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1alpha1.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1alpha1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1alpha1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &examplev1alpha1.TestType{}) - if obj == nil { - return nil, err +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexamplev1alpha1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList, *v1alpha1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + examplev1alpha1.SchemeGroupVersion.WithResource("testtypes"), + examplev1alpha1.SchemeGroupVersion.WithKind("TestType"), + func() *examplev1alpha1.TestType { return &examplev1alpha1.TestType{} }, + func() *examplev1alpha1.TestTypeList { return &examplev1alpha1.TestTypeList{} }, + func(dst, src *examplev1alpha1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1alpha1.TestTypeList) []*examplev1alpha1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1alpha1.TestTypeList, items []*examplev1alpha1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev1alpha1.TestType), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/generated_expansion.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/generated_expansion.go new file mode 100644 index 000000000..c17c3f326 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1alpha1 + +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/testtype.go index f181d3aab..ca4bc2048 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1alpha1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + typedexamplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - examplev1alpha1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -44,12 +41,13 @@ type TestTypesClusterGetter interface { // or scope down to one cluster and return a TestTypesNamespacer. type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer - List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.TestTypeList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + List(ctx context.Context, opts v1.ListOptions) (*examplev1alpha1.TestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1alpha1client.ExampleV1alpha1Client] + clientCache kcpclient.Cache[*typedexamplev1alpha1.ExampleV1alpha1Client] } // Cluster scopes the client down to a particular cluster. @@ -62,25 +60,25 @@ func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) Tes } // List returns the entire collection of all TestTypes across all clusters. -func (c *testTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*examplev1alpha1.TestTypeList, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).List(ctx, opts) +func (c *testTypesClusterInterface) List(ctx context.Context, opts v1.ListOptions) (*examplev1alpha1.TestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(v1.NamespaceAll).List(ctx, opts) } // Watch begins to watch all TestTypes across all clusters. -func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) +func (c *testTypesClusterInterface) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(v1.NamespaceAll).Watch(ctx, opts) } -// TestTypesNamespacer can scope to objects within a namespace, returning a examplev1alpha1client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexamplev1alpha1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) examplev1alpha1client.TestTypeInterface + Namespace(string) typedexamplev1alpha1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*examplev1alpha1client.ExampleV1alpha1Client] + clientCache kcpclient.Cache[*typedexamplev1alpha1.ExampleV1alpha1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev1alpha1client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedexamplev1alpha1.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/clustertesttype.go index ac21c7549..6dd9f85bb 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1beta1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - examplev1beta1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a examplev1beta1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a examplev1beta1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) examplev1beta1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*examplev1beta1.ClusterTestTypeList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Cluster(logicalcluster.Path) examplev1beta1.ClusterTestTypeInterface + List(ctx context.Context, opts v1.ListOptions) (*apisexamplev1beta1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1beta1client.ExampleV1beta1Client] + clientCache kcpclient.Cache[*examplev1beta1.ExampleV1beta1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev1beta1client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev1beta1.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,11 +60,11 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*examplev1beta1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts v1.ListOptions) (*apisexamplev1beta1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } // Watch begins to watch all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { +func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().Watch(ctx, opts) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/doc.go new file mode 100644 index 000000000..e0406a6b9 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1beta1 diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/example_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/example_client.go index 9d720f2bd..5b2fa4787 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/example_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1beta1 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + scheme "acme.corp/pkg/kcpexisting/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type ExampleV1beta1ClusterInterface interface { ExampleV1beta1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter } type ExampleV1beta1ClusterScoper interface { Cluster(logicalcluster.Path) examplev1beta1.ExampleV1beta1Interface } +// ExampleV1beta1ClusterClient is used to interact with features provided by the example.dev group. type ExampleV1beta1ClusterClient struct { clientCache kcpclient.Cache[*examplev1beta1.ExampleV1beta1Client] } @@ -53,23 +53,25 @@ func (c *ExampleV1beta1ClusterClient) Cluster(clusterPath logicalcluster.Path) e return c.clientCache.ClusterOrDie(clusterPath) } -func (c *ExampleV1beta1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *ExampleV1beta1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *ExampleV1beta1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new ExampleV1beta1ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExampleV1beta1ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new ExampleV1beta1ClusterClient for the given config and http client. @@ -81,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV1beta1Clust if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &ExampleV1beta1ClusterClient{clientCache: cache}, nil } @@ -93,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *ExampleV1beta1ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apisexamplev1beta1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/clustertesttype.go index 898b28710..31eec3f7d 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + v1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" + typedexamplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + typedkcpexamplev1beta1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - applyconfigurationsexamplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" - examplev1beta1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1beta1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1beta1", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) examplev1beta1client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1beta1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &examplev1beta1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1beta1.ClusterTestTypeList{ListMeta: obj.(*examplev1beta1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1beta1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *ExampleV1beta1ClusterClient) typedkcpexamplev1beta1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList]( + fake.Fake, + examplev1beta1.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev1beta1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev1beta1.ClusterTestType { return &examplev1beta1.ClusterTestType{} }, + func() *examplev1beta1.ClusterTestTypeList { return &examplev1beta1.ClusterTestTypeList{} }, + func(dst, src *examplev1beta1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1beta1.ClusterTestTypeList) []*examplev1beta1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1beta1.ClusterTestTypeList, items []*examplev1beta1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexamplev1beta1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList, *v1beta1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *examplev1beta1.ClusterTestType, opts metav1.CreateOptions) (*examplev1beta1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *examplev1beta1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1beta1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *examplev1beta1.ClusterTestType, opts metav1.UpdateOptions) (*examplev1beta1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &examplev1beta1.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1beta1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev1beta1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev1beta1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &examplev1beta1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1beta1.ClusterTestTypeList{ListMeta: obj.(*examplev1beta1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev1beta1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev1beta1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1beta1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1beta1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1beta1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1beta1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &examplev1beta1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexamplev1beta1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList, *v1beta1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + examplev1beta1.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev1beta1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev1beta1.ClusterTestType { return &examplev1beta1.ClusterTestType{} }, + func() *examplev1beta1.ClusterTestTypeList { return &examplev1beta1.ClusterTestTypeList{} }, + func(dst, src *examplev1beta1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1beta1.ClusterTestTypeList) []*examplev1beta1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1beta1.ClusterTestTypeList, items []*examplev1beta1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev1beta1.ClusterTestType), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/example_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/example_client.go index 4ead5bb77..de032ad31 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/example_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" kcpexamplev1beta1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpexamplev1beta1.ExampleV1beta1ClusterInterface = (*ExampleV1beta1ClusterClient)(nil) @@ -44,30 +41,30 @@ func (c *ExampleV1beta1ClusterClient) Cluster(clusterPath logicalcluster.Path) e return &ExampleV1beta1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *ExampleV1beta1ClusterClient) TestTypes() kcpexamplev1beta1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *ExampleV1beta1ClusterClient) ClusterTestTypes() kcpexamplev1beta1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ examplev1beta1.ExampleV1beta1Interface = (*ExampleV1beta1Client)(nil) +func (c *ExampleV1beta1ClusterClient) TestTypes() kcpexamplev1beta1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type ExampleV1beta1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *ExampleV1beta1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *ExampleV1beta1Client) ClusterTestTypes() examplev1beta1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *ExampleV1beta1Client) TestTypes(namespace string) examplev1beta1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExampleV1beta1Client) ClusterTestTypes() examplev1beta1.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExampleV1beta1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go index be3536bca..c19e272df 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,145 +14,86 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + v1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" + typedexamplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + typedkcpexamplev1beta1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - applyconfigurationsexamplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" - examplev1beta1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" - kcpexamplev1beta1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1" + "github.com/kcp-dev/logicalcluster/v3" ) -var testTypesResource = schema.GroupVersionResource{Group: "example", Version: "v1beta1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example", Version: "v1beta1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1beta1.TestType, *examplev1beta1.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexamplev1beta1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +func newFakeTestTypeClusterClient(fake *ExampleV1beta1ClusterClient) typedkcpexamplev1beta1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev1beta1.TestType, *examplev1beta1.TestTypeList]( + fake.Fake, + examplev1beta1.SchemeGroupVersion.WithResource("testtypes"), + examplev1beta1.SchemeGroupVersion.WithKind("TestType"), + func() *examplev1beta1.TestType { return &examplev1beta1.TestType{} }, + func() *examplev1beta1.TestTypeList { return &examplev1beta1.TestTypeList{} }, + func(dst, src *examplev1beta1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1beta1.TestTypeList) []*examplev1beta1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1beta1.TestTypeList, items []*examplev1beta1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} } -type testTypesNamespacer struct { - *kcptesting.Fake - ClusterPath logicalcluster.Path +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexamplev1beta1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -func (n *testTypesNamespacer) Namespace(namespace string) examplev1beta1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} -} - -type testTypesClient struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *examplev1beta1.TestType, opts metav1.CreateOptions) (*examplev1beta1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *examplev1beta1.TestType, opts metav1.UpdateOptions) (*examplev1beta1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.TestType), err } -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *examplev1beta1.TestType, opts metav1.UpdateOptions) (*examplev1beta1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &examplev1beta1.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &examplev1beta1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev1beta1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.TestType), err -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev1beta1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.TestType), err +func (n *testTypeNamespacer) Namespace(namespace string) typedexamplev1beta1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1beta1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1beta1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev1beta1.TestType), err +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1beta1.TestType, *examplev1beta1.TestTypeList, *v1beta1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake + ClusterPath logicalcluster.Path } -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev1beta1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev1beta1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &examplev1beta1.TestType{}) - if obj == nil { - return nil, err +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexamplev1beta1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev1beta1.TestType, *examplev1beta1.TestTypeList, *v1beta1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + examplev1beta1.SchemeGroupVersion.WithResource("testtypes"), + examplev1beta1.SchemeGroupVersion.WithKind("TestType"), + func() *examplev1beta1.TestType { return &examplev1beta1.TestType{} }, + func() *examplev1beta1.TestTypeList { return &examplev1beta1.TestTypeList{} }, + func(dst, src *examplev1beta1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev1beta1.TestTypeList) []*examplev1beta1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev1beta1.TestTypeList, items []*examplev1beta1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev1beta1.TestType), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/generated_expansion.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/generated_expansion.go new file mode 100644 index 000000000..f6728dd2e --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1beta1 + +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/testtype.go index cfae770e1..e0be63235 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,15 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1beta1 import ( + context "context" + + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + typedexamplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" "github.com/kcp-dev/logicalcluster/v3" - - examplev1beta1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -34,13 +37,17 @@ type TestTypesClusterGetter interface { TestTypes() TestTypeClusterInterface } -// TestTypeClusterInterface can scope down to one cluster and return a TestTypesNamespacer. +// TestTypeClusterInterface can operate on TestTypes across all clusters, +// or scope down to one cluster and return a TestTypesNamespacer. type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer + List(ctx context.Context, opts v1.ListOptions) (*examplev1beta1.TestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev1beta1client.ExampleV1beta1Client] + clientCache kcpclient.Cache[*typedexamplev1beta1.ExampleV1beta1Client] } // Cluster scopes the client down to a particular cluster. @@ -52,16 +59,26 @@ func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) Tes return &testTypesNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} } -// TestTypesNamespacer can scope to objects within a namespace, returning a examplev1beta1client.TestTypeInterface. +// List returns the entire collection of all TestTypes across all clusters. +func (c *testTypesClusterInterface) List(ctx context.Context, opts v1.ListOptions) (*examplev1beta1.TestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(v1.NamespaceAll).List(ctx, opts) +} + +// Watch begins to watch all TestTypes across all clusters. +func (c *testTypesClusterInterface) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(v1.NamespaceAll).Watch(ctx, opts) +} + +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexamplev1beta1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) examplev1beta1client.TestTypeInterface + Namespace(string) typedexamplev1beta1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*examplev1beta1client.ExampleV1beta1Client] + clientCache kcpclient.Cache[*typedexamplev1beta1.ExampleV1beta1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev1beta1client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedexamplev1beta1.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/clustertesttype.go index c2bc48817..2960a3925 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v2 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev2 "acme.corp/pkg/apis/example/v2" + examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" - examplev2 "acme.corp/pkg/apis/example/v2" - examplev2client "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a examplev2client.ClusterTestTypeInterface. +// or scope down to one cluster and return a examplev2.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) examplev2client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*examplev2.ClusterTestTypeList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Cluster(logicalcluster.Path) examplev2.ClusterTestTypeInterface + List(ctx context.Context, opts v1.ListOptions) (*apisexamplev2.ClusterTestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev2client.ExampleV2Client] + clientCache kcpclient.Cache[*examplev2.ExampleV2Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev2client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) examplev2.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,11 +60,11 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*examplev2.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts v1.ListOptions) (*apisexamplev2.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } // Watch begins to watch all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { +func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().Watch(ctx, opts) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/doc.go new file mode 100644 index 000000000..ad8aa3bd4 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v2 diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/example_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/example_client.go index 5096e3628..cbbc8f9f6 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/example_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v2 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev2 "acme.corp/pkg/apis/example/v2" + examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + scheme "acme.corp/pkg/kcpexisting/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type ExampleV2ClusterInterface interface { ExampleV2ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter } type ExampleV2ClusterScoper interface { Cluster(logicalcluster.Path) examplev2.ExampleV2Interface } +// ExampleV2ClusterClient is used to interact with features provided by the example.dev group. type ExampleV2ClusterClient struct { clientCache kcpclient.Cache[*examplev2.ExampleV2Client] } @@ -53,23 +53,25 @@ func (c *ExampleV2ClusterClient) Cluster(clusterPath logicalcluster.Path) exampl return c.clientCache.ClusterOrDie(clusterPath) } -func (c *ExampleV2ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *ExampleV2ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *ExampleV2ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new ExampleV2ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExampleV2ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new ExampleV2ClusterClient for the given config and http client. @@ -81,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV2ClusterCli if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &ExampleV2ClusterClient{clientCache: cache}, nil } @@ -93,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *ExampleV2ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apisexamplev2.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/clustertesttype.go index 50ed201a6..f61577af0 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev2 "acme.corp/pkg/apis/example/v2" + v2 "acme.corp/pkg/generated/applyconfigurations/example/v2" + typedexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + typedkcpexamplev2 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - examplev2 "acme.corp/pkg/apis/example/v2" - applyconfigurationsexamplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" - examplev2client "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example", Version: "v2", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example", Version: "v2", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) examplev2client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev2.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &examplev2.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev2.ClusterTestTypeList{ListMeta: obj.(*examplev2.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev2.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *ExampleV2ClusterClient) typedkcpexamplev2.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList]( + fake.Fake, + examplev2.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev2.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev2.ClusterTestType { return &examplev2.ClusterTestType{} }, + func() *examplev2.ClusterTestTypeList { return &examplev2.ClusterTestTypeList{} }, + func(dst, src *examplev2.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev2.ClusterTestTypeList) []*examplev2.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev2.ClusterTestTypeList, items []*examplev2.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexamplev2.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList, *v2.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *examplev2.ClusterTestType, opts metav1.CreateOptions) (*examplev2.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *examplev2.ClusterTestType, opts metav1.UpdateOptions) (*examplev2.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *examplev2.ClusterTestType, opts metav1.UpdateOptions) (*examplev2.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &examplev2.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &examplev2.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev2.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev2.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &examplev2.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev2.ClusterTestTypeList{ListMeta: obj.(*examplev2.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*examplev2.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev2.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev2.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev2.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev2.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev2.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &examplev2.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexamplev2.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList, *v2.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + examplev2.SchemeGroupVersion.WithResource("clustertesttypes"), + examplev2.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *examplev2.ClusterTestType { return &examplev2.ClusterTestType{} }, + func() *examplev2.ClusterTestTypeList { return &examplev2.ClusterTestTypeList{} }, + func(dst, src *examplev2.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev2.ClusterTestTypeList) []*examplev2.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *examplev2.ClusterTestTypeList, items []*examplev2.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev2.ClusterTestType), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/example_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/example_client.go index b84f4b22d..b9faa452b 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/example_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/example_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" kcpexamplev2 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpexamplev2.ExampleV2ClusterInterface = (*ExampleV2ClusterClient)(nil) @@ -44,30 +41,30 @@ func (c *ExampleV2ClusterClient) Cluster(clusterPath logicalcluster.Path) exampl return &ExampleV2Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *ExampleV2ClusterClient) TestTypes() kcpexamplev2.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *ExampleV2ClusterClient) ClusterTestTypes() kcpexamplev2.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ examplev2.ExampleV2Interface = (*ExampleV2Client)(nil) +func (c *ExampleV2ClusterClient) TestTypes() kcpexamplev2.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type ExampleV2Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *ExampleV2Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *ExampleV2Client) ClusterTestTypes() examplev2.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *ExampleV2Client) TestTypes(namespace string) examplev2.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExampleV2Client) ClusterTestTypes() examplev2.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExampleV2Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/testtype.go index 58af8e051..3ae471018 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,197 +14,82 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + examplev2 "acme.corp/pkg/apis/example/v2" + v2 "acme.corp/pkg/generated/applyconfigurations/example/v2" + typedexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + typedkcpexamplev2 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - examplev2 "acme.corp/pkg/apis/example/v2" - applyconfigurationsexamplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" - examplev2client "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" - kcpexamplev2 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2" + "github.com/kcp-dev/logicalcluster/v3" ) -var testTypesResource = schema.GroupVersionResource{Group: "example", Version: "v2", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example", Version: "v2", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev2.TestType, *examplev2.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexamplev2.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +func newFakeTestTypeClusterClient(fake *ExampleV2ClusterClient) typedkcpexamplev2.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*examplev2.TestType, *examplev2.TestTypeList]( + fake.Fake, + examplev2.SchemeGroupVersion.WithResource("testtypes"), + examplev2.SchemeGroupVersion.WithKind("TestType"), + func() *examplev2.TestType { return &examplev2.TestType{} }, + func() *examplev2.TestTypeList { return &examplev2.TestTypeList{} }, + func(dst, src *examplev2.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev2.TestTypeList) []*examplev2.TestType { return kcpgentype.ToPointerSlice(list.Items) }, + func(list *examplev2.TestTypeList, items []*examplev2.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. -func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev2.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &examplev2.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev2.TestTypeList{ListMeta: obj.(*examplev2.TestTypeList).ListMeta} - for _, item := range obj.(*examplev2.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexamplev2.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -// Watch returns a watch.Interface that watches the requested TestTypes across all clusters. -func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) -} - -type testTypesNamespacer struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev2client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexamplev2.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev2.TestType, *examplev2.TestTypeList, *v2.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *examplev2.TestType, opts metav1.CreateOptions) (*examplev2.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev2.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *examplev2.TestType, opts metav1.UpdateOptions) (*examplev2.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &examplev2.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *examplev2.TestType, opts metav1.UpdateOptions) (*examplev2.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &examplev2.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &examplev2.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &examplev2.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*examplev2.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &examplev2.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.TestType), err } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*examplev2.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &examplev2.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev2.TestTypeList{ListMeta: obj.(*examplev2.TestTypeList).ListMeta} - for _, item := range obj.(*examplev2.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*examplev2.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &examplev2.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexamplev2.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev2.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &examplev2.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*examplev2.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexamplev2.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*examplev2.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &examplev2.TestType{}) - if obj == nil { - return nil, err +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexamplev2.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*examplev2.TestType, *examplev2.TestTypeList, *v2.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + examplev2.SchemeGroupVersion.WithResource("testtypes"), + examplev2.SchemeGroupVersion.WithKind("TestType"), + func() *examplev2.TestType { return &examplev2.TestType{} }, + func() *examplev2.TestTypeList { return &examplev2.TestTypeList{} }, + func(dst, src *examplev2.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *examplev2.TestTypeList) []*examplev2.TestType { return kcpgentype.ToPointerSlice(list.Items) }, + func(list *examplev2.TestTypeList, items []*examplev2.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*examplev2.TestType), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/generated_expansion.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/generated_expansion.go new file mode 100644 index 000000000..a324d34f5 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v2 + +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/testtype.go index d140c37d5..2efdd7058 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v2 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + examplev2 "acme.corp/pkg/apis/example/v2" + typedexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" - examplev2 "acme.corp/pkg/apis/example/v2" - examplev2client "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -44,12 +41,13 @@ type TestTypesClusterGetter interface { // or scope down to one cluster and return a TestTypesNamespacer. type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer - List(ctx context.Context, opts metav1.ListOptions) (*examplev2.TestTypeList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + List(ctx context.Context, opts v1.ListOptions) (*examplev2.TestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*examplev2client.ExampleV2Client] + clientCache kcpclient.Cache[*typedexamplev2.ExampleV2Client] } // Cluster scopes the client down to a particular cluster. @@ -62,25 +60,25 @@ func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) Tes } // List returns the entire collection of all TestTypes across all clusters. -func (c *testTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*examplev2.TestTypeList, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).List(ctx, opts) +func (c *testTypesClusterInterface) List(ctx context.Context, opts v1.ListOptions) (*examplev2.TestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(v1.NamespaceAll).List(ctx, opts) } // Watch begins to watch all TestTypes across all clusters. -func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) +func (c *testTypesClusterInterface) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(v1.NamespaceAll).Watch(ctx, opts) } -// TestTypesNamespacer can scope to objects within a namespace, returning a examplev2client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexamplev2.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) examplev2client.TestTypeInterface + Namespace(string) typedexamplev2.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*examplev2client.ExampleV2Client] + clientCache kcpclient.Cache[*typedexamplev2.ExampleV2Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) examplev2client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedexamplev2.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/clustertesttype.go index adde1fd08..b03688276 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" + example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - example3v1 "acme.corp/pkg/apis/example3/v1" - example3v1client "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a example3v1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a example3v1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) example3v1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*example3v1.ClusterTestTypeList, error) + Cluster(logicalcluster.Path) example3v1.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*apisexample3v1.ClusterTestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*example3v1client.Example3V1Client] + clientCache kcpclient.Cache[*example3v1.Example3V1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) example3v1client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) example3v1.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,7 +60,7 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*example3v1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*apisexample3v1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/doc.go new file mode 100644 index 000000000..dc2c8e634 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/example3_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/example3_client.go index 2285f2cf5..7553d4bd7 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/example3_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/example3_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" + example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + scheme "acme.corp/pkg/kcpexisting/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type Example3V1ClusterInterface interface { Example3V1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter } type Example3V1ClusterScoper interface { Cluster(logicalcluster.Path) example3v1.Example3V1Interface } +// Example3V1ClusterClient is used to interact with features provided by the example3.some.corp group. type Example3V1ClusterClient struct { clientCache kcpclient.Cache[*example3v1.Example3V1Client] } @@ -53,23 +53,25 @@ func (c *Example3V1ClusterClient) Cluster(clusterPath logicalcluster.Path) examp return c.clientCache.ClusterOrDie(clusterPath) } -func (c *Example3V1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *Example3V1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *Example3V1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new Example3V1ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*Example3V1ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new Example3V1ClusterClient for the given config and http client. @@ -81,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*Example3V1ClusterCl if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &Example3V1ClusterClient{clientCache: cache}, nil } @@ -93,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *Example3V1ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apisexample3v1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go index 5905b6d77..0aa111291 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + example3v1 "acme.corp/pkg/apis/example3/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" + typedexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + typedkcpexample3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - example3v1 "acme.corp/pkg/apis/example3/v1" - applyconfigurationsexample3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" - example3v1client "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example3.some.corp", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example3.some.corp", Version: "v1", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) example3v1client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*example3v1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &example3v1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &example3v1.ClusterTestTypeList{ListMeta: obj.(*example3v1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*example3v1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *Example3V1ClusterClient) typedkcpexample3v1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList]( + fake.Fake, + example3v1.SchemeGroupVersion.WithResource("clustertesttypes"), + example3v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *example3v1.ClusterTestType { return &example3v1.ClusterTestType{} }, + func() *example3v1.ClusterTestTypeList { return &example3v1.ClusterTestTypeList{} }, + func(dst, src *example3v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *example3v1.ClusterTestTypeList) []*example3v1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *example3v1.ClusterTestTypeList, items []*example3v1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexample3v1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *example3v1.ClusterTestType, opts metav1.CreateOptions) (*example3v1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *example3v1.ClusterTestType, opts metav1.UpdateOptions) (*example3v1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *example3v1.ClusterTestType, opts metav1.UpdateOptions) (*example3v1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &example3v1.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &example3v1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*example3v1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*example3v1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &example3v1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &example3v1.ClusterTestTypeList{ListMeta: obj.(*example3v1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*example3v1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*example3v1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexample3v1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*example3v1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexample3v1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*example3v1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &example3v1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexample3v1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + example3v1.SchemeGroupVersion.WithResource("clustertesttypes"), + example3v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *example3v1.ClusterTestType { return &example3v1.ClusterTestType{} }, + func() *example3v1.ClusterTestTypeList { return &example3v1.ClusterTestTypeList{} }, + func(dst, src *example3v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *example3v1.ClusterTestTypeList) []*example3v1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *example3v1.ClusterTestTypeList, items []*example3v1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*example3v1.ClusterTestType), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/example3_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/example3_client.go index 3443f9898..4ae4c0121 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/example3_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/example3_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" kcpexample3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpexample3v1.Example3V1ClusterInterface = (*Example3V1ClusterClient)(nil) @@ -44,30 +41,30 @@ func (c *Example3V1ClusterClient) Cluster(clusterPath logicalcluster.Path) examp return &Example3V1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *Example3V1ClusterClient) TestTypes() kcpexample3v1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *Example3V1ClusterClient) ClusterTestTypes() kcpexample3v1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ example3v1.Example3V1Interface = (*Example3V1Client)(nil) +func (c *Example3V1ClusterClient) TestTypes() kcpexample3v1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type Example3V1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *Example3V1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *Example3V1Client) ClusterTestTypes() example3v1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *Example3V1Client) TestTypes(namespace string) example3v1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *Example3V1Client) ClusterTestTypes() example3v1.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *Example3V1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/testtype.go index 4c24bdd12..226060dc6 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,222 +14,121 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" + context "context" examplev1 "acme.corp/pkg/apis/example/v1" example3v1 "acme.corp/pkg/apis/example3/v1" - applyconfigurationsexample3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" - example3v1client "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" - kcpexample3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1" -) + v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" + typedexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + typedkcpexample3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1" -var testTypesResource = schema.GroupVersionResource{Group: "example3.some.corp", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example3.some.corp", Version: "v1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake -} + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexample3v1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" +) - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*example3v1.TestType, *example3v1.TestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. -func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*example3v1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &example3v1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &example3v1.TestTypeList{ListMeta: obj.(*example3v1.TestTypeList).ListMeta} - for _, item := range obj.(*example3v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeTestTypeClusterClient(fake *Example3V1ClusterClient) typedkcpexample3v1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*example3v1.TestType, *example3v1.TestTypeList]( + fake.Fake, + example3v1.SchemeGroupVersion.WithResource("testtypes"), + example3v1.SchemeGroupVersion.WithKind("TestType"), + func() *example3v1.TestType { return &example3v1.TestType{} }, + func() *example3v1.TestTypeList { return &example3v1.TestTypeList{} }, + func(dst, src *example3v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *example3v1.TestTypeList) []*example3v1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *example3v1.TestTypeList, items []*example3v1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested TestTypes across all clusters. -func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexample3v1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -type testTypesNamespacer struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) example3v1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexample3v1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*example3v1.TestType, *example3v1.TestTypeList, *v1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *example3v1.TestType, opts metav1.CreateOptions) (*example3v1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *example3v1.TestType, opts metav1.UpdateOptions) (*example3v1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *example3v1.TestType, opts metav1.UpdateOptions) (*example3v1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &example3v1.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &example3v1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*example3v1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*example3v1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &example3v1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &example3v1.TestTypeList{ListMeta: obj.(*example3v1.TestTypeList).ListMeta} - for _, item := range obj.(*example3v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*example3v1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexample3v1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*example3v1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexample3v1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*example3v1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &example3v1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*example3v1.TestType), err } -func (c *testTypesClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (*examplev1.Field, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(testTypesResource, c.ClusterPath, testTypeName, "field", c.Namespace, field), &examplev1.Field{}) +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexample3v1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*example3v1.TestType, *example3v1.TestTypeList, *v1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + example3v1.SchemeGroupVersion.WithResource("testtypes"), + example3v1.SchemeGroupVersion.WithKind("TestType"), + func() *example3v1.TestType { return &example3v1.TestType{} }, + func() *example3v1.TestTypeList { return &example3v1.TestTypeList{} }, + func(dst, src *example3v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *example3v1.TestTypeList) []*example3v1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *example3v1.TestTypeList, items []*example3v1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, + } +} + +// CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypeScopedClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, _ metav1.CreateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(c.Resource(), c.ClusterPath, testTypeName, "field", c.Namespace(), field), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } -func (c *testTypesClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (*examplev1.Field, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, field), &examplev1.Field{}) +// UpdateField takes the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypeScopedClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, _ metav1.UpdateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(c.Resource(), c.ClusterPath, "field", c.Namespace(), field), &examplev1.Field{}) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } -func (c *testTypesClient) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*examplev1.Field, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, testTypeName), &examplev1.Field{}) +// GetField takes name of the testType, and returns the corresponding field object, and an error if there is any. +func (c *testTypeScopedClient) GetField(ctx context.Context, testTypeName string, _ metav1.GetOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(c.Resource(), c.ClusterPath, c.Namespace(), "field", testTypeName), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*examplev1.Field), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/generated_expansion.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/generated_expansion.go new file mode 100644 index 000000000..21b9d4175 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/testtype.go index bee57419e..6a28c0f86 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + example3v1 "acme.corp/pkg/apis/example3/v1" + typedexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - example3v1 "acme.corp/pkg/apis/example3/v1" - example3v1client "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -46,10 +43,11 @@ type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer List(ctx context.Context, opts metav1.ListOptions) (*example3v1.TestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*example3v1client.Example3V1Client] + clientCache kcpclient.Cache[*typedexample3v1.Example3V1Client] } // Cluster scopes the client down to a particular cluster. @@ -71,16 +69,16 @@ func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListO return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) } -// TestTypesNamespacer can scope to objects within a namespace, returning a example3v1client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexample3v1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) example3v1client.TestTypeInterface + Namespace(string) typedexample3v1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*example3v1client.Example3V1Client] + clientCache kcpclient.Cache[*typedexample3v1.Example3V1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) example3v1client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedexample3v1.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..f3c907eba --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go @@ -0,0 +1,70 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + + apisexampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" +) + +// ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. +// A group's cluster client should implement this interface. +type ClusterTestTypesClusterGetter interface { + ClusterTestTypes() ClusterTestTypeClusterInterface +} + +// ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, +// or scope down to one cluster and return a exampledashedv1.ClusterTestTypeInterface. +type ClusterTestTypeClusterInterface interface { + Cluster(logicalcluster.Path) exampledashedv1.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*apisexampledashedv1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion +} + +type clusterTestTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv1.ExampleDashedV1Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ClusterTestTypeInterface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return c.clientCache.ClusterOrDie(clusterPath).ClusterTestTypes() +} + +// List returns the entire collection of all ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*apisexampledashedv1.ClusterTestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) +} + +// Watch begins to watch all ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().Watch(ctx, opts) +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/doc.go new file mode 100644 index 000000000..dc2c8e634 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go new file mode 100644 index 000000000..b37b0b10e --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go @@ -0,0 +1,109 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +import ( + http "net/http" + + apisexampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + scheme "acme.corp/pkg/kcpexisting/clients/clientset/versioned/scheme" + + rest "k8s.io/client-go/rest" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" +) + +type ExampleDashedV1ClusterInterface interface { + ExampleDashedV1ClusterScoper + ClusterTestTypesClusterGetter + TestTypesClusterGetter +} + +type ExampleDashedV1ClusterScoper interface { + Cluster(logicalcluster.Path) exampledashedv1.ExampleDashedV1Interface +} + +// ExampleDashedV1ClusterClient is used to interact with features provided by the example-dashed.some.corp group. +type ExampleDashedV1ClusterClient struct { + clientCache kcpclient.Cache[*exampledashedv1.ExampleDashedV1Client] +} + +func (c *ExampleDashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ExampleDashedV1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +func (c *ExampleDashedV1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterInterface{clientCache: c.clientCache} +} + +func (c *ExampleDashedV1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + +// NewForConfig creates a new ExampleDashedV1ClusterClient for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExampleDashedV1ClusterClient, error) { + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new ExampleDashedV1ClusterClient for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleDashedV1ClusterClient, error) { + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*exampledashedv1.ExampleDashedV1Client]{ + NewForConfigAndClient: exampledashedv1.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + + return &ExampleDashedV1ClusterClient{clientCache: cache}, nil +} + +// NewForConfigOrDie creates a new ExampleDashedV1ClusterClient for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExampleDashedV1ClusterClient { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +func setConfigDefaults(config *rest.Config) { + gv := apisexampledashedv1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go new file mode 100644 index 000000000..922d3db63 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go @@ -0,0 +1,90 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package fake + +import ( + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + typedexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + typedkcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" + + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" +) + +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList] + Fake *kcptesting.Fake +} + +func newFakeClusterTestTypeClusterClient(fake *ExampleDashedV1ClusterClient) typedkcpexampledashedv1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList]( + fake.Fake, + exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"), + exampledashedv1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *exampledashedv1.ClusterTestType { return &exampledashedv1.ClusterTestType{} }, + func() *exampledashedv1.ClusterTestTypeList { return &exampledashedv1.ClusterTestTypeList{} }, + func(dst, src *exampledashedv1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *exampledashedv1.ClusterTestTypeList) []*exampledashedv1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *exampledashedv1.ClusterTestTypeList, items []*exampledashedv1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, + } +} + +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexampledashedv1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) +} + +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexampledashedv1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"), + exampledashedv1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *exampledashedv1.ClusterTestType { return &exampledashedv1.ClusterTestType{} }, + func() *exampledashedv1.ClusterTestTypeList { return &exampledashedv1.ClusterTestTypeList{} }, + func(dst, src *exampledashedv1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *exampledashedv1.ClusterTestTypeList) []*exampledashedv1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *exampledashedv1.ClusterTestTypeList, items []*exampledashedv1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, + } +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go new file mode 100644 index 000000000..07e1775cc --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go @@ -0,0 +1,70 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package fake + +import ( + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" +) + +var _ kcpexampledashedv1.ExampleDashedV1ClusterInterface = (*ExampleDashedV1ClusterClient)(nil) + +type ExampleDashedV1ClusterClient struct { + *kcptesting.Fake +} + +func (c *ExampleDashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ExampleDashedV1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &ExampleDashedV1Client{Fake: c.Fake, ClusterPath: clusterPath} +} + +func (c *ExampleDashedV1ClusterClient) ClusterTestTypes() kcpexampledashedv1.ClusterTestTypeClusterInterface { + return newFakeClusterTestTypeClusterClient(c) +} + +func (c *ExampleDashedV1ClusterClient) TestTypes() kcpexampledashedv1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} + +type ExampleDashedV1Client struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *ExampleDashedV1Client) ClusterTestTypes() exampledashedv1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) +} + +func (c *ExampleDashedV1Client) TestTypes(namespace string) exampledashedv1.TestTypeInterface { + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExampleDashedV1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go new file mode 100644 index 000000000..d116eae28 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go @@ -0,0 +1,134 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package fake + +import ( + context "context" + + examplev1 "acme.corp/pkg/apis/example/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + typedexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + typedkcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" +) + +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*exampledashedv1.TestType, *exampledashedv1.TestTypeList] + Fake *kcptesting.Fake +} + +func newFakeTestTypeClusterClient(fake *ExampleDashedV1ClusterClient) typedkcpexampledashedv1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*exampledashedv1.TestType, *exampledashedv1.TestTypeList]( + fake.Fake, + exampledashedv1.SchemeGroupVersion.WithResource("testtypes"), + exampledashedv1.SchemeGroupVersion.WithKind("TestType"), + func() *exampledashedv1.TestType { return &exampledashedv1.TestType{} }, + func() *exampledashedv1.TestTypeList { return &exampledashedv1.TestTypeList{} }, + func(dst, src *exampledashedv1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *exampledashedv1.TestTypeList) []*exampledashedv1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *exampledashedv1.TestTypeList, items []*exampledashedv1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, + } +} + +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexampledashedv1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} +} + +type testTypeNamespacer struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (n *testTypeNamespacer) Namespace(namespace string) typedexampledashedv1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) +} + +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*exampledashedv1.TestType, *exampledashedv1.TestTypeList, *v1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexampledashedv1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*exampledashedv1.TestType, *exampledashedv1.TestTypeList, *v1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + exampledashedv1.SchemeGroupVersion.WithResource("testtypes"), + exampledashedv1.SchemeGroupVersion.WithKind("TestType"), + func() *exampledashedv1.TestType { return &exampledashedv1.TestType{} }, + func() *exampledashedv1.TestTypeList { return &exampledashedv1.TestTypeList{} }, + func(dst, src *exampledashedv1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *exampledashedv1.TestTypeList) []*exampledashedv1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *exampledashedv1.TestTypeList, items []*exampledashedv1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, + } +} + +// CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypeScopedClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, _ metav1.CreateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(c.Resource(), c.ClusterPath, testTypeName, "field", c.Namespace(), field), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} + +// UpdateField takes the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypeScopedClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, _ metav1.UpdateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(c.Resource(), c.ClusterPath, "field", c.Namespace(), field), &examplev1.Field{}) + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} + +// GetField takes name of the testType, and returns the corresponding field object, and an error if there is any. +func (c *testTypeScopedClient) GetField(ctx context.Context, testTypeName string, _ metav1.GetOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(c.Resource(), c.ClusterPath, c.Namespace(), "field", testTypeName), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/generated_expansion.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/generated_expansion.go new file mode 100644 index 000000000..21b9d4175 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/testtype.go new file mode 100644 index 000000000..286c87623 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/testtype.go @@ -0,0 +1,84 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + typedexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" +) + +// TestTypesClusterGetter has a method to return a TestTypeClusterInterface. +// A group's cluster client should implement this interface. +type TestTypesClusterGetter interface { + TestTypes() TestTypeClusterInterface +} + +// TestTypeClusterInterface can operate on TestTypes across all clusters, +// or scope down to one cluster and return a TestTypesNamespacer. +type TestTypeClusterInterface interface { + Cluster(logicalcluster.Path) TestTypesNamespacer + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion +} + +type testTypesClusterInterface struct { + clientCache kcpclient.Cache[*typedexampledashedv1.ExampleDashedV1Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) TestTypesNamespacer { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &testTypesNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} +} + +// List returns the entire collection of all TestTypes across all clusters. +func (c *testTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).List(ctx, opts) +} + +// Watch begins to watch all TestTypes across all clusters. +func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) +} + +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexampledashedv1.TestTypeInterface. +type TestTypesNamespacer interface { + Namespace(string) typedexampledashedv1.TestTypeInterface +} + +type testTypesNamespacer struct { + clientCache kcpclient.Cache[*typedexampledashedv1.ExampleDashedV1Client] + clusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) typedexampledashedv1.TestTypeInterface { + return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go index c9f0833ce..d829a5546 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - existinginterfacesv1client "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a existinginterfacesv1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a existinginterfacesv1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) existinginterfacesv1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.ClusterTestTypeList, error) + Cluster(logicalcluster.Path) existinginterfacesv1.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*apisexistinginterfacesv1.ClusterTestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*existinginterfacesv1client.ExistinginterfacesV1Client] + clientCache kcpclient.Cache[*existinginterfacesv1.ExistinginterfacesV1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) existinginterfacesv1client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) existinginterfacesv1.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,7 +60,7 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*apisexistinginterfacesv1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/doc.go new file mode 100644 index 000000000..dc2c8e634 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/existinginterfaces_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/existinginterfaces_client.go index f91869ecb..817a375d8 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/existinginterfaces_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/existinginterfaces_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + scheme "acme.corp/pkg/kcpexisting/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type ExistinginterfacesV1ClusterInterface interface { ExistinginterfacesV1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter } type ExistinginterfacesV1ClusterScoper interface { Cluster(logicalcluster.Path) existinginterfacesv1.ExistinginterfacesV1Interface } +// ExistinginterfacesV1ClusterClient is used to interact with features provided by the existinginterfaces.acme.corp group. type ExistinginterfacesV1ClusterClient struct { clientCache kcpclient.Cache[*existinginterfacesv1.ExistinginterfacesV1Client] } @@ -53,23 +53,25 @@ func (c *ExistinginterfacesV1ClusterClient) Cluster(clusterPath logicalcluster.P return c.clientCache.ClusterOrDie(clusterPath) } -func (c *ExistinginterfacesV1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *ExistinginterfacesV1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *ExistinginterfacesV1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new ExistinginterfacesV1ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*ExistinginterfacesV1ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new ExistinginterfacesV1ClusterClient for the given config and http client. @@ -81,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExistinginterfacesV if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &ExistinginterfacesV1ClusterClient{clientCache: cache}, nil } @@ -93,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *ExistinginterfacesV1ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apisexistinginterfacesv1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go index 3db29e205..8932e7262 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" + typedexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + typedkcpexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - applyconfigurationsexistinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" - existinginterfacesv1client "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "existinginterfaces.acme.corp", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "existinginterfaces.acme.corp", Version: "v1", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) existinginterfacesv1client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &existinginterfacesv1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &existinginterfacesv1.ClusterTestTypeList{ListMeta: obj.(*existinginterfacesv1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*existinginterfacesv1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *ExistinginterfacesV1ClusterClient) typedkcpexistinginterfacesv1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList]( + fake.Fake, + existinginterfacesv1.SchemeGroupVersion.WithResource("clustertesttypes"), + existinginterfacesv1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *existinginterfacesv1.ClusterTestType { return &existinginterfacesv1.ClusterTestType{} }, + func() *existinginterfacesv1.ClusterTestTypeList { return &existinginterfacesv1.ClusterTestTypeList{} }, + func(dst, src *existinginterfacesv1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *existinginterfacesv1.ClusterTestTypeList) []*existinginterfacesv1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *existinginterfacesv1.ClusterTestTypeList, items []*existinginterfacesv1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedexistinginterfacesv1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *existinginterfacesv1.ClusterTestType, opts metav1.CreateOptions) (*existinginterfacesv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *existinginterfacesv1.ClusterTestType, opts metav1.UpdateOptions) (*existinginterfacesv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *existinginterfacesv1.ClusterTestType, opts metav1.UpdateOptions) (*existinginterfacesv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &existinginterfacesv1.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &existinginterfacesv1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*existinginterfacesv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &existinginterfacesv1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &existinginterfacesv1.ClusterTestTypeList{ListMeta: obj.(*existinginterfacesv1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*existinginterfacesv1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*existinginterfacesv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexistinginterfacesv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*existinginterfacesv1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexistinginterfacesv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*existinginterfacesv1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &existinginterfacesv1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedexistinginterfacesv1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + existinginterfacesv1.SchemeGroupVersion.WithResource("clustertesttypes"), + existinginterfacesv1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *existinginterfacesv1.ClusterTestType { return &existinginterfacesv1.ClusterTestType{} }, + func() *existinginterfacesv1.ClusterTestTypeList { return &existinginterfacesv1.ClusterTestTypeList{} }, + func(dst, src *existinginterfacesv1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *existinginterfacesv1.ClusterTestTypeList) []*existinginterfacesv1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *existinginterfacesv1.ClusterTestTypeList, items []*existinginterfacesv1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*existinginterfacesv1.ClusterTestType), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/existinginterfaces_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/existinginterfaces_client.go index 4b909c615..f6df5102c 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/existinginterfaces_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/existinginterfaces_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" kcpexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpexistinginterfacesv1.ExistinginterfacesV1ClusterInterface = (*ExistinginterfacesV1ClusterClient)(nil) @@ -44,30 +41,30 @@ func (c *ExistinginterfacesV1ClusterClient) Cluster(clusterPath logicalcluster.P return &ExistinginterfacesV1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *ExistinginterfacesV1ClusterClient) TestTypes() kcpexistinginterfacesv1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *ExistinginterfacesV1ClusterClient) ClusterTestTypes() kcpexistinginterfacesv1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ existinginterfacesv1.ExistinginterfacesV1Interface = (*ExistinginterfacesV1Client)(nil) +func (c *ExistinginterfacesV1ClusterClient) TestTypes() kcpexistinginterfacesv1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type ExistinginterfacesV1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *ExistinginterfacesV1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *ExistinginterfacesV1Client) ClusterTestTypes() existinginterfacesv1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *ExistinginterfacesV1Client) TestTypes(namespace string) existinginterfacesv1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExistinginterfacesV1Client) ClusterTestTypes() existinginterfacesv1.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExistinginterfacesV1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go index b0e7bc947..541ba6899 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,197 +14,86 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" + typedexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + typedkcpexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - applyconfigurationsexistinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" - existinginterfacesv1client "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" - kcpexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var testTypesResource = schema.GroupVersionResource{Group: "existinginterfaces.acme.corp", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "existinginterfaces.acme.corp", Version: "v1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexistinginterfacesv1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +func newFakeTestTypeClusterClient(fake *ExistinginterfacesV1ClusterClient) typedkcpexistinginterfacesv1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList]( + fake.Fake, + existinginterfacesv1.SchemeGroupVersion.WithResource("testtypes"), + existinginterfacesv1.SchemeGroupVersion.WithKind("TestType"), + func() *existinginterfacesv1.TestType { return &existinginterfacesv1.TestType{} }, + func() *existinginterfacesv1.TestTypeList { return &existinginterfacesv1.TestTypeList{} }, + func(dst, src *existinginterfacesv1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *existinginterfacesv1.TestTypeList) []*existinginterfacesv1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *existinginterfacesv1.TestTypeList, items []*existinginterfacesv1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. -func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &existinginterfacesv1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &existinginterfacesv1.TestTypeList{ListMeta: obj.(*existinginterfacesv1.TestTypeList).ListMeta} - for _, item := range obj.(*existinginterfacesv1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexistinginterfacesv1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -// Watch returns a watch.Interface that watches the requested TestTypes across all clusters. -func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) -} - -type testTypesNamespacer struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) existinginterfacesv1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexistinginterfacesv1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList, *v1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *existinginterfacesv1.TestType, opts metav1.CreateOptions) (*existinginterfacesv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *existinginterfacesv1.TestType, opts metav1.UpdateOptions) (*existinginterfacesv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *existinginterfacesv1.TestType, opts metav1.UpdateOptions) (*existinginterfacesv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &existinginterfacesv1.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &existinginterfacesv1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*existinginterfacesv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &existinginterfacesv1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &existinginterfacesv1.TestTypeList{ListMeta: obj.(*existinginterfacesv1.TestTypeList).ListMeta} - for _, item := range obj.(*existinginterfacesv1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*existinginterfacesv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexistinginterfacesv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*existinginterfacesv1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*existinginterfacesv1.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexistinginterfacesv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*existinginterfacesv1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &existinginterfacesv1.TestType{}) - if obj == nil { - return nil, err +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedexistinginterfacesv1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList, *v1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + existinginterfacesv1.SchemeGroupVersion.WithResource("testtypes"), + existinginterfacesv1.SchemeGroupVersion.WithKind("TestType"), + func() *existinginterfacesv1.TestType { return &existinginterfacesv1.TestType{} }, + func() *existinginterfacesv1.TestTypeList { return &existinginterfacesv1.TestTypeList{} }, + func(dst, src *existinginterfacesv1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *existinginterfacesv1.TestTypeList) []*existinginterfacesv1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *existinginterfacesv1.TestTypeList, items []*existinginterfacesv1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*existinginterfacesv1.TestType), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/generated_expansion.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/generated_expansion.go new file mode 100644 index 000000000..21b9d4175 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/testtype.go index 3873c0502..8adce2827 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + typedexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - existinginterfacesv1client "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -46,10 +43,11 @@ type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer List(ctx context.Context, opts metav1.ListOptions) (*existinginterfacesv1.TestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*existinginterfacesv1client.ExistinginterfacesV1Client] + clientCache kcpclient.Cache[*typedexistinginterfacesv1.ExistinginterfacesV1Client] } // Cluster scopes the client down to a particular cluster. @@ -71,16 +69,16 @@ func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListO return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) } -// TestTypesNamespacer can scope to objects within a namespace, returning a existinginterfacesv1client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexistinginterfacesv1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) existinginterfacesv1client.TestTypeInterface + Namespace(string) typedexistinginterfacesv1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*existinginterfacesv1client.ExistinginterfacesV1Client] + clientCache kcpclient.Cache[*typedexistinginterfacesv1.ExistinginterfacesV1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) existinginterfacesv1client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedexistinginterfacesv1.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/clustertesttype.go index 28c948133..861ce3c8c 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - secondexamplev1client "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -41,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a secondexamplev1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a secondexamplev1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) secondexamplev1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.ClusterTestTypeList, error) + Cluster(logicalcluster.Path) secondexamplev1.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*apissecondexamplev1.ClusterTestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + ClusterTestTypeClusterExpansion } type clusterTestTypesClusterInterface struct { - clientCache kcpclient.Cache[*secondexamplev1client.SecondexampleV1Client] + clientCache kcpclient.Cache[*secondexamplev1.SecondexampleV1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) secondexamplev1client.ClusterTestTypeInterface { +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) secondexamplev1.ClusterTestTypeInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -62,7 +60,7 @@ func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Pa } // List returns the entire collection of all ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*apissecondexamplev1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/doc.go new file mode 100644 index 000000000..dc2c8e634 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/clustertesttype.go index bfa081276..0648dfef3 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,186 +14,77 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" + typedsecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + typedkcpsecondexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - applyconfigurationssecondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" - secondexamplev1client "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "secondexample", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "secondexample", Version: "v1", Kind: "ClusterTestType"} - -type clusterTestTypesClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) secondexamplev1client.ClusterTestTypeInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +// clusterTestTypeClusterClient implements ClusterTestTypeClusterInterface +type clusterTestTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList] + Fake *kcptesting.Fake } -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. -func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &secondexamplev1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &secondexamplev1.ClusterTestTypeList{ListMeta: obj.(*secondexamplev1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*secondexamplev1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } +func newFakeClusterTestTypeClusterClient(fake *SecondexampleV1ClusterClient) typedkcpsecondexamplev1.ClusterTestTypeClusterInterface { + return &clusterTestTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList]( + fake.Fake, + secondexamplev1.SchemeGroupVersion.WithResource("clustertesttypes"), + secondexamplev1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *secondexamplev1.ClusterTestType { return &secondexamplev1.ClusterTestType{} }, + func() *secondexamplev1.ClusterTestTypeList { return &secondexamplev1.ClusterTestTypeList{} }, + func(dst, src *secondexamplev1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *secondexamplev1.ClusterTestTypeList) []*secondexamplev1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *secondexamplev1.ClusterTestTypeList, items []*secondexamplev1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - return list, err } -// Watch returns a watch.Interface that watches the requested ClusterTestTypes across all clusters. -func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +func (c *clusterTestTypeClusterClient) Cluster(cluster logicalcluster.Path) typedsecondexamplev1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *secondexamplev1.ClusterTestType, opts metav1.CreateOptions) (*secondexamplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *secondexamplev1.ClusterTestType, opts metav1.UpdateOptions) (*secondexamplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *secondexamplev1.ClusterTestType, opts metav1.UpdateOptions) (*secondexamplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &secondexamplev1.ClusterTestType{}) - return err -} - -func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &secondexamplev1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*secondexamplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &secondexamplev1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &secondexamplev1.ClusterTestTypeList{ListMeta: obj.(*secondexamplev1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*secondexamplev1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) -} - -func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*secondexamplev1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationssecondexamplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*secondexamplev1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationssecondexamplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*secondexamplev1.ClusterTestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &secondexamplev1.ClusterTestType{}) - if obj == nil { - return nil, err +func newFakeClusterTestTypeClient(fake *kcptesting.Fake, clusterPath logicalcluster.Path) typedsecondexamplev1.ClusterTestTypeInterface { + return &clusterTestTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration]( + fake, + clusterPath, + "", + secondexamplev1.SchemeGroupVersion.WithResource("clustertesttypes"), + secondexamplev1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *secondexamplev1.ClusterTestType { return &secondexamplev1.ClusterTestType{} }, + func() *secondexamplev1.ClusterTestTypeList { return &secondexamplev1.ClusterTestTypeList{} }, + func(dst, src *secondexamplev1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *secondexamplev1.ClusterTestTypeList) []*secondexamplev1.ClusterTestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *secondexamplev1.ClusterTestTypeList, items []*secondexamplev1.ClusterTestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*secondexamplev1.ClusterTestType), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/doc.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/doc.go new file mode 100644 index 000000000..7799ee376 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +// Package fake has the automatically generated cluster clients. +package fake diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/secondexample_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/secondexample_client.go index b4ce6cdd9..625e20a68 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/secondexample_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/secondexample_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "k8s.io/client-go/rest" - secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" kcpsecondexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1" + + rest "k8s.io/client-go/rest" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" ) var _ kcpsecondexamplev1.SecondexampleV1ClusterInterface = (*SecondexampleV1ClusterClient)(nil) @@ -44,30 +41,30 @@ func (c *SecondexampleV1ClusterClient) Cluster(clusterPath logicalcluster.Path) return &SecondexampleV1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *SecondexampleV1ClusterClient) TestTypes() kcpsecondexamplev1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *SecondexampleV1ClusterClient) ClusterTestTypes() kcpsecondexamplev1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ secondexamplev1.SecondexampleV1Interface = (*SecondexampleV1Client)(nil) +func (c *SecondexampleV1ClusterClient) TestTypes() kcpsecondexamplev1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type SecondexampleV1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *SecondexampleV1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *SecondexampleV1Client) ClusterTestTypes() secondexamplev1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *SecondexampleV1Client) TestTypes(namespace string) secondexamplev1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *SecondexampleV1Client) ClusterTestTypes() secondexamplev1.ClusterTestTypeInterface { - return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *SecondexampleV1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/testtype.go index 4346645f7..71632f737 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/fake/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,197 +14,86 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package fake import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + v1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" + typedsecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + typedkcpsecondexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1" + kcpgentype "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/gentype" kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - applyconfigurationssecondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" - secondexamplev1client "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" - kcpsecondexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1" + "github.com/kcp-dev/logicalcluster/v3" ) -var testTypesResource = schema.GroupVersionResource{Group: "secondexample", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "secondexample", Version: "v1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*secondexamplev1.TestType, *secondexamplev1.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpsecondexamplev1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +func newFakeTestTypeClusterClient(fake *SecondexampleV1ClusterClient) typedkcpsecondexamplev1.TestTypeClusterInterface { + return &testTypeClusterClient{ + kcpgentype.NewFakeClusterClientWithList[*secondexamplev1.TestType, *secondexamplev1.TestTypeList]( + fake.Fake, + secondexamplev1.SchemeGroupVersion.WithResource("testtypes"), + secondexamplev1.SchemeGroupVersion.WithKind("TestType"), + func() *secondexamplev1.TestType { return &secondexamplev1.TestType{} }, + func() *secondexamplev1.TestTypeList { return &secondexamplev1.TestTypeList{} }, + func(dst, src *secondexamplev1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *secondexamplev1.TestTypeList) []*secondexamplev1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *secondexamplev1.TestTypeList, items []*secondexamplev1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake.Fake, } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. -func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &secondexamplev1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &secondexamplev1.TestTypeList{ListMeta: obj.(*secondexamplev1.TestTypeList).ListMeta} - for _, item := range obj.(*secondexamplev1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpsecondexamplev1.TestTypesNamespacer { + return &testTypeNamespacer{Fake: c.Fake, ClusterPath: cluster} } -// Watch returns a watch.Interface that watches the requested TestTypes across all clusters. -func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) -} - -type testTypesNamespacer struct { +type testTypeNamespacer struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) secondexamplev1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedsecondexamplev1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*secondexamplev1.TestType, *secondexamplev1.TestTypeList, *v1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *secondexamplev1.TestType, opts metav1.CreateOptions) (*secondexamplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *secondexamplev1.TestType, opts metav1.UpdateOptions) (*secondexamplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *secondexamplev1.TestType, opts metav1.UpdateOptions) (*secondexamplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &secondexamplev1.TestType{}) - return err -} - -func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) - - _, err := c.Fake.Invokes(action, &secondexamplev1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*secondexamplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err } -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &secondexamplev1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &secondexamplev1.TestTypeList{ListMeta: obj.(*secondexamplev1.TestTypeList).ListMeta} - for _, item := range obj.(*secondexamplev1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) -} - -func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*secondexamplev1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationssecondexamplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*secondexamplev1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*secondexamplev1.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationssecondexamplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*secondexamplev1.TestType, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &secondexamplev1.TestType{}) - if obj == nil { - return nil, err +func newFakeTestTypeClient(fake *kcptesting.Fake, namespace string, clusterPath logicalcluster.Path) typedsecondexamplev1.TestTypeInterface { + return &testTypeScopedClient{ + kcpgentype.NewFakeClientWithListAndApply[*secondexamplev1.TestType, *secondexamplev1.TestTypeList, *v1.TestTypeApplyConfiguration]( + fake, + clusterPath, + namespace, + secondexamplev1.SchemeGroupVersion.WithResource("testtypes"), + secondexamplev1.SchemeGroupVersion.WithKind("TestType"), + func() *secondexamplev1.TestType { return &secondexamplev1.TestType{} }, + func() *secondexamplev1.TestTypeList { return &secondexamplev1.TestTypeList{} }, + func(dst, src *secondexamplev1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *secondexamplev1.TestTypeList) []*secondexamplev1.TestType { + return kcpgentype.ToPointerSlice(list.Items) + }, + func(list *secondexamplev1.TestTypeList, items []*secondexamplev1.TestType) { + list.Items = kcpgentype.FromPointerSlice(items) + }, + ), + fake, + clusterPath, } - return obj.(*secondexamplev1.TestType), err } diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/generated_expansion.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/generated_expansion.go new file mode 100644 index 000000000..21b9d4175 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-client-gen. DO NOT EDIT. + +package v1 + +type ClusterTestTypeClusterExpansion interface{} + +type TestTypeClusterExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/secondexample_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/secondexample_client.go index f0da7668f..b82303464 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/secondexample_client.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/secondexample_client.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "net/http" + http "net/http" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + scheme "acme.corp/pkg/kcpexisting/clients/clientset/versioned/scheme" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" - secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) type SecondexampleV1ClusterInterface interface { SecondexampleV1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter } type SecondexampleV1ClusterScoper interface { Cluster(logicalcluster.Path) secondexamplev1.SecondexampleV1Interface } +// SecondexampleV1ClusterClient is used to interact with features provided by the secondexample.dev group. type SecondexampleV1ClusterClient struct { clientCache kcpclient.Cache[*secondexamplev1.SecondexampleV1Client] } @@ -53,23 +53,25 @@ func (c *SecondexampleV1ClusterClient) Cluster(clusterPath logicalcluster.Path) return c.clientCache.ClusterOrDie(clusterPath) } -func (c *SecondexampleV1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - func (c *SecondexampleV1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { return &clusterTestTypesClusterInterface{clientCache: c.clientCache} } +func (c *SecondexampleV1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new SecondexampleV1ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). func NewForConfig(c *rest.Config) (*SecondexampleV1ClusterClient, error) { - client, err := rest.HTTPClientFor(c) + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) if err != nil { return nil, err } - return NewForConfigAndClient(c, client) + return NewForConfigAndClient(&config, httpClient) } // NewForConfigAndClient creates a new SecondexampleV1ClusterClient for the given config and http client. @@ -81,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*SecondexampleV1Clus if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &SecondexampleV1ClusterClient{clientCache: cache}, nil } @@ -93,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *SecondexampleV1ClusterClient { } return client } + +func setConfigDefaults(config *rest.Config) { + gv := apissecondexamplev1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/testtype.go index fe04e5e5b..beb003f72 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,21 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-client-gen. DO NOT EDIT. package v1 import ( - "context" + context "context" - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + typedsecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - secondexamplev1client "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -46,10 +43,11 @@ type TestTypeClusterInterface interface { Cluster(logicalcluster.Path) TestTypesNamespacer List(ctx context.Context, opts metav1.ListOptions) (*secondexamplev1.TestTypeList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + TestTypeClusterExpansion } type testTypesClusterInterface struct { - clientCache kcpclient.Cache[*secondexamplev1client.SecondexampleV1Client] + clientCache kcpclient.Cache[*typedsecondexamplev1.SecondexampleV1Client] } // Cluster scopes the client down to a particular cluster. @@ -71,16 +69,16 @@ func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListO return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) } -// TestTypesNamespacer can scope to objects within a namespace, returning a secondexamplev1client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedsecondexamplev1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) secondexamplev1client.TestTypeInterface + Namespace(string) typedsecondexamplev1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*secondexamplev1client.SecondexampleV1Client] + clientCache kcpclient.Cache[*typedsecondexamplev1.SecondexampleV1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) secondexamplev1client.TestTypeInterface { +func (n *testTypesNamespacer) Namespace(namespace string) typedsecondexamplev1.TestTypeInterface { return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/interface.go index f742ac81c..13992241e 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,26 +14,27 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package example import ( - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example/v1" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example/v2" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + v1 "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example/v1" + v1alpha1 "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1" + v1beta1 "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1" + v2 "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example/v2" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" ) +// ClusterInterface provides access to each of this group's versions. type ClusterInterface interface { - // V1 provides access to the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.ClusterInterface - // V1alpha1 provides access to the shared informers in V1alpha1. + // V1alpha1 provides access to shared informers for resources in V1alpha1. V1alpha1() v1alpha1.ClusterInterface - // V1beta1 provides access to the shared informers in V1beta1. + // V1beta1 provides access to shared informers for resources in V1beta1. V1beta1() v1beta1.ClusterInterface - // V2 provides access to the shared informers in V2. + // V2 provides access to shared informers for resources in V2. V2() v2.ClusterInterface } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/clustertesttype.go index 2f2c418a1..103d6665c 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/generated/informers/externalversions/example/v1" + generatedlistersexamplev1 "acme.corp/pkg/generated/listers/example/v1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexamplev1 "acme.corp/pkg/kcpexisting/clients/listers/example/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev1 "acme.corp/pkg/apis/example/v1" - upstreamexamplev1informers "acme.corp/pkg/generated/informers/externalversions/example/v1" - upstreamexamplev1listers "acme.corp/pkg/generated/listers/example/v1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - examplev1listers "acme.corp/pkg/kcpexisting/clients/listers/example/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) examplev1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1listers.ClusterTestTypeClusterLister + Lister() listersexamplev1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -58,67 +56,73 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &examplev1.ClusterTestType{}, + &apisexamplev1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Lister() listersexamplev1.ClusterTestTypeClusterLister { + return listersexamplev1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *clusterTestTypeClusterInformer) Lister() examplev1listers.ClusterTestTypeClusterLister { - return examplev1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexamplev1listers.ClusterTestTypeLister + lister generatedlistersexamplev1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() upstreamexamplev1listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() generatedlistersexamplev1.ClusterTestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/interface.go index ebae731bf..04919a1d7 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // TestTypes returns a TestTypeClusterInformer - TestTypes() TestTypeClusterInformer - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -37,17 +34,17 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// TestTypes returns a TestTypeClusterInformer -func (v *version) TestTypes() TestTypeClusterInformer { - return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/testtype.go index a589c3f16..db3da7c3c 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apisexamplev1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/generated/informers/externalversions/example/v1" + generatedlistersexamplev1 "acme.corp/pkg/generated/listers/example/v1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexamplev1 "acme.corp/pkg/kcpexisting/clients/listers/example/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev1 "acme.corp/pkg/apis/example/v1" - upstreamexamplev1informers "acme.corp/pkg/generated/informers/externalversions/example/v1" - upstreamexamplev1listers "acme.corp/pkg/generated/listers/example/v1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - examplev1listers "acme.corp/pkg/kcpexisting/clients/listers/example/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev1informers.TestTypeInformer + Cluster(logicalcluster.Name) examplev1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1listers.TestTypeClusterLister + Lister() listersexamplev1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -58,67 +56,73 @@ type testTypeClusterInformer struct { // NewTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().TestTypes().List(context.TODO(), options) + return client.ExampleV1().TestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1().TestTypes().Watch(context.TODO(), options) + return client.ExampleV1().TestTypes().Watch(context.Background(), options) }, }, - &examplev1.TestType{}, + &apisexamplev1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, - f.tweakListOptions, - ) + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Lister() listersexamplev1.TestTypeClusterLister { + return listersexamplev1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *testTypeClusterInformer) Lister() examplev1listers.TestTypeClusterLister { - return examplev1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev1informers.TestTypeInformer { +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev1.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexamplev1listers.TestTypeLister + lister generatedlistersexamplev1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() upstreamexamplev1listers.TestTypeLister { - return f.lister +func (i *testTypeInformer) Lister() generatedlistersexamplev1.TestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/clustertesttype.go index ffa241ef2..66c9358ea 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1alpha1 import ( - "context" - "time" + context "context" + time "time" + + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/informers/externalversions/example/v1alpha1" + generatedlistersexamplev1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexamplev1alpha1 "acme.corp/pkg/kcpexisting/clients/listers/example/v1alpha1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - upstreamexamplev1alpha1informers "acme.corp/pkg/generated/informers/externalversions/example/v1alpha1" - upstreamexamplev1alpha1listers "acme.corp/pkg/generated/listers/example/v1alpha1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - examplev1alpha1listers "acme.corp/pkg/kcpexisting/clients/listers/example/v1alpha1" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev1alpha1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) examplev1alpha1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev1alpha1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1alpha1listers.ClusterTestTypeClusterLister + Lister() listersexamplev1alpha1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -58,67 +56,73 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV1alpha1().ClusterTestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV1alpha1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &examplev1alpha1.ClusterTestType{}, + &apisexamplev1alpha1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev1alpha1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1alpha1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Lister() examplev1alpha1listers.ClusterTestTypeClusterLister { - return examplev1alpha1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Lister() listersexamplev1alpha1.ClusterTestTypeClusterLister { + return listersexamplev1alpha1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev1alpha1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev1alpha1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev1alpha1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexamplev1alpha1listers.ClusterTestTypeLister + lister generatedlistersexamplev1alpha1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() upstreamexamplev1alpha1listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() generatedlistersexamplev1alpha1.ClusterTestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/interface.go index 563ec11a4..cd3b12485 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1alpha1 import ( - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // TestTypes returns a TestTypeClusterInformer - TestTypes() TestTypeClusterInformer - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -37,17 +34,17 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// TestTypes returns a TestTypeClusterInformer -func (v *version) TestTypes() TestTypeClusterInformer { - return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/testtype.go index 828c34fa6..7a50c9b61 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1alpha1 import ( - "context" - "time" + context "context" + time "time" + + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/informers/externalversions/example/v1alpha1" + generatedlistersexamplev1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexamplev1alpha1 "acme.corp/pkg/kcpexisting/clients/listers/example/v1alpha1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - upstreamexamplev1alpha1informers "acme.corp/pkg/generated/informers/externalversions/example/v1alpha1" - upstreamexamplev1alpha1listers "acme.corp/pkg/generated/listers/example/v1alpha1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - examplev1alpha1listers "acme.corp/pkg/kcpexisting/clients/listers/example/v1alpha1" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev1alpha1informers.TestTypeInformer + Cluster(logicalcluster.Name) examplev1alpha1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev1alpha1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1alpha1listers.TestTypeClusterLister + Lister() listersexamplev1alpha1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -58,67 +56,73 @@ type testTypeClusterInformer struct { // NewTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().TestTypes().List(context.TODO(), options) + return client.ExampleV1alpha1().TestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1alpha1().TestTypes().Watch(context.TODO(), options) + return client.ExampleV1alpha1().TestTypes().Watch(context.Background(), options) }, }, - &examplev1alpha1.TestType{}, + &apisexamplev1alpha1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, - f.tweakListOptions, - ) + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev1alpha1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1alpha1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Lister() examplev1alpha1listers.TestTypeClusterLister { - return examplev1alpha1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Lister() listersexamplev1alpha1.TestTypeClusterLister { + return listersexamplev1alpha1.NewTestTypeClusterLister(i.Informer().GetIndexer()) +} + +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev1alpha1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev1alpha1informers.TestTypeInformer { +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev1alpha1.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexamplev1alpha1listers.TestTypeLister + lister generatedlistersexamplev1alpha1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() upstreamexamplev1alpha1listers.TestTypeLister { - return f.lister +func (i *testTypeInformer) Lister() generatedlistersexamplev1alpha1.TestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/clustertesttype.go index 1156aa6ee..0a180867c 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1beta1 import ( - "context" - "time" + context "context" + time "time" + + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/informers/externalversions/example/v1beta1" + generatedlistersexamplev1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexamplev1beta1 "acme.corp/pkg/kcpexisting/clients/listers/example/v1beta1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - upstreamexamplev1beta1informers "acme.corp/pkg/generated/informers/externalversions/example/v1beta1" - upstreamexamplev1beta1listers "acme.corp/pkg/generated/listers/example/v1beta1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - examplev1beta1listers "acme.corp/pkg/kcpexisting/clients/listers/example/v1beta1" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev1beta1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) examplev1beta1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev1beta1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1beta1listers.ClusterTestTypeClusterLister + Lister() listersexamplev1beta1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -58,67 +56,73 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1beta1().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV1beta1().ClusterTestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV1beta1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV1beta1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &examplev1beta1.ClusterTestType{}, + &apisexamplev1beta1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev1beta1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1beta1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Lister() examplev1beta1listers.ClusterTestTypeClusterLister { - return examplev1beta1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Lister() listersexamplev1beta1.ClusterTestTypeClusterLister { + return listersexamplev1beta1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev1beta1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev1beta1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev1beta1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexamplev1beta1listers.ClusterTestTypeLister + lister generatedlistersexamplev1beta1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() upstreamexamplev1beta1listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() generatedlistersexamplev1beta1.ClusterTestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/interface.go index 667f35557..cedc3e64d 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,17 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1beta1 import ( - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -35,12 +34,17 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/testtype.go new file mode 100644 index 000000000..8e6b9caa5 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/testtype.go @@ -0,0 +1,128 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + context "context" + time "time" + + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/informers/externalversions/example/v1beta1" + generatedlistersexamplev1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexamplev1beta1 "acme.corp/pkg/kcpexisting/clients/listers/example/v1beta1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" +) + +// TestTypeClusterInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeClusterInformer interface { + Cluster(logicalcluster.Name) examplev1beta1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev1beta1.TestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() listersexamplev1beta1.TestTypeClusterLister +} + +type testTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewTestTypeClusterInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { + return kcpinformers.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1beta1().TestTypes().List(context.Background(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1beta1().TestTypes().Watch(context.Background(), options) + }, + }, + &apisexamplev1beta1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1beta1.TestType{}, i.defaultInformer) +} + +func (i *testTypeClusterInformer) Lister() listersexamplev1beta1.TestTypeClusterLister { + return listersexamplev1beta1.NewTestTypeClusterLister(i.Informer().GetIndexer()) +} + +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev1beta1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev1beta1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +type testTypeInformer struct { + informer cache.SharedIndexInformer + lister generatedlistersexamplev1beta1.TestTypeLister +} + +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer +} + +func (i *testTypeInformer) Lister() generatedlistersexamplev1beta1.TestTypeLister { + return i.lister +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/clustertesttype.go index 2747d4060..e0d9397a0 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v2 import ( - "context" - "time" + context "context" + time "time" + + apisexamplev2 "acme.corp/pkg/apis/example/v2" + examplev2 "acme.corp/pkg/generated/informers/externalversions/example/v2" + generatedlistersexamplev2 "acme.corp/pkg/generated/listers/example/v2" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexamplev2 "acme.corp/pkg/kcpexisting/clients/listers/example/v2" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev2 "acme.corp/pkg/apis/example/v2" - upstreamexamplev2informers "acme.corp/pkg/generated/informers/externalversions/example/v2" - upstreamexamplev2listers "acme.corp/pkg/generated/listers/example/v2" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - examplev2listers "acme.corp/pkg/kcpexisting/clients/listers/example/v2" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev2informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) examplev2.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev2.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev2listers.ClusterTestTypeClusterLister + Lister() listersexamplev2.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -58,67 +56,73 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().ClusterTestTypes().List(context.TODO(), options) + return client.ExampleV2().ClusterTestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExampleV2().ClusterTestTypes().Watch(context.Background(), options) }, }, - &examplev2.ClusterTestType{}, + &apisexamplev2.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev2.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev2.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Lister() examplev2listers.ClusterTestTypeClusterLister { - return examplev2listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Lister() listersexamplev2.ClusterTestTypeClusterLister { + return listersexamplev2.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev2.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev2informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev2.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexamplev2listers.ClusterTestTypeLister + lister generatedlistersexamplev2.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() upstreamexamplev2listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() generatedlistersexamplev2.ClusterTestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/interface.go index 83daf27bd..055242bc3 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v2 import ( - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // TestTypes returns a TestTypeClusterInformer - TestTypes() TestTypeClusterInformer - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -37,17 +34,17 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// TestTypes returns a TestTypeClusterInformer -func (v *version) TestTypes() TestTypeClusterInformer { - return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/testtype.go index 3e15daee1..bc783c7b9 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v2 import ( - "context" - "time" + context "context" + time "time" + + apisexamplev2 "acme.corp/pkg/apis/example/v2" + examplev2 "acme.corp/pkg/generated/informers/externalversions/example/v2" + generatedlistersexamplev2 "acme.corp/pkg/generated/listers/example/v2" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexamplev2 "acme.corp/pkg/kcpexisting/clients/listers/example/v2" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - examplev2 "acme.corp/pkg/apis/example/v2" - upstreamexamplev2informers "acme.corp/pkg/generated/informers/externalversions/example/v2" - upstreamexamplev2listers "acme.corp/pkg/generated/listers/example/v2" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - examplev2listers "acme.corp/pkg/kcpexisting/clients/listers/example/v2" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev2informers.TestTypeInformer + Cluster(logicalcluster.Name) examplev2.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev2.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev2listers.TestTypeClusterLister + Lister() listersexamplev2.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -58,67 +56,73 @@ type testTypeClusterInformer struct { // NewTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().TestTypes().List(context.TODO(), options) + return client.ExampleV2().TestTypes().List(context.Background(), options) }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExampleV2().TestTypes().Watch(context.TODO(), options) + return client.ExampleV2().TestTypes().Watch(context.Background(), options) }, }, - &examplev2.TestType{}, + &apisexamplev2.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, - f.tweakListOptions, - ) + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) } -func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&examplev2.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev2.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Lister() examplev2listers.TestTypeClusterLister { - return examplev2listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Lister() listersexamplev2.TestTypeClusterLister { + return listersexamplev2.NewTestTypeClusterLister(i.Informer().GetIndexer()) +} + +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev2.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev2informers.TestTypeInformer { +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev2.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexamplev2listers.TestTypeLister + lister generatedlistersexamplev2.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() upstreamexamplev2listers.TestTypeLister { - return f.lister +func (i *testTypeInformer) Lister() generatedlistersexamplev2.TestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/interface.go index 5dd78f30f..d6ccc6e2d 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,17 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package example3 import ( - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example3/v1" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + v1 "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example3/v1" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" ) +// ClusterInterface provides access to each of this group's versions. type ClusterInterface interface { - // V1 provides access to the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.ClusterInterface } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/clustertesttype.go index abb8a3e24..b9bcaf388 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" + example3v1 "acme.corp/pkg/generated/informers/externalversions/example3/v1" + generatedlistersexample3v1 "acme.corp/pkg/generated/listers/example3/v1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexample3v1 "acme.corp/pkg/kcpexisting/clients/listers/example3/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - example3v1 "acme.corp/pkg/apis/example3/v1" - upstreamexample3v1informers "acme.corp/pkg/generated/informers/externalversions/example3/v1" - upstreamexample3v1listers "acme.corp/pkg/generated/listers/example3/v1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - example3v1listers "acme.corp/pkg/kcpexisting/clients/listers/example3/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexample3v1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) example3v1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) example3v1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() example3v1listers.ClusterTestTypeClusterLister + Lister() listersexample3v1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -58,67 +56,73 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().ClusterTestTypes().List(context.TODO(), options) + return client.Example3V1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().ClusterTestTypes().Watch(context.TODO(), options) + return client.Example3V1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &example3v1.ClusterTestType{}, + &apisexample3v1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexample3v1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&example3v1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Lister() listersexample3v1.ClusterTestTypeClusterLister { + return listersexample3v1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *clusterTestTypeClusterInformer) Lister() example3v1listers.ClusterTestTypeClusterLister { - return example3v1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) example3v1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexample3v1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) example3v1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexample3v1listers.ClusterTestTypeLister + lister generatedlistersexample3v1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() upstreamexample3v1listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() generatedlistersexample3v1.ClusterTestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/interface.go index ebae731bf..04919a1d7 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // TestTypes returns a TestTypeClusterInformer - TestTypes() TestTypeClusterInformer - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -37,17 +34,17 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// TestTypes returns a TestTypeClusterInformer -func (v *version) TestTypes() TestTypeClusterInformer { - return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/testtype.go index e20bb2f7b..1e384ce44 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" + example3v1 "acme.corp/pkg/generated/informers/externalversions/example3/v1" + generatedlistersexample3v1 "acme.corp/pkg/generated/listers/example3/v1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexample3v1 "acme.corp/pkg/kcpexisting/clients/listers/example3/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - example3v1 "acme.corp/pkg/apis/example3/v1" - upstreamexample3v1informers "acme.corp/pkg/generated/informers/externalversions/example3/v1" - upstreamexample3v1listers "acme.corp/pkg/generated/listers/example3/v1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - example3v1listers "acme.corp/pkg/kcpexisting/clients/listers/example3/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexample3v1informers.TestTypeInformer + Cluster(logicalcluster.Name) example3v1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) example3v1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() example3v1listers.TestTypeClusterLister + Lister() listersexample3v1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -58,67 +56,73 @@ type testTypeClusterInformer struct { // NewTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().TestTypes().List(context.TODO(), options) + return client.Example3V1().TestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.Example3V1().TestTypes().Watch(context.TODO(), options) + return client.Example3V1().TestTypes().Watch(context.Background(), options) }, }, - &example3v1.TestType{}, + &apisexample3v1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, - f.tweakListOptions, - ) + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexample3v1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&example3v1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Lister() listersexample3v1.TestTypeClusterLister { + return listersexample3v1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *testTypeClusterInformer) Lister() example3v1listers.TestTypeClusterLister { - return example3v1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) example3v1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexample3v1informers.TestTypeInformer { +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) example3v1.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexample3v1listers.TestTypeLister + lister generatedlistersexample3v1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() upstreamexample3v1listers.TestTypeLister { - return f.lister +func (i *testTypeInformer) Lister() generatedlistersexample3v1.TestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/interface.go new file mode 100644 index 000000000..6f8a69981 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/interface.go @@ -0,0 +1,45 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-informer-gen. DO NOT EDIT. + +package exampledashed + +import ( + v1 "acme.corp/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" +) + +// ClusterInterface provides access to each of this group's versions. +type ClusterInterface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.ClusterInterface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new ClusterInterface. +func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { + return &group{factory: f, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.ClusterInterface. +func (g *group) V1() v1.ClusterInterface { + return v1.New(g.factory, g.tweakListOptions) +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..7ad83b1ea --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go @@ -0,0 +1,128 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-informer-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + time "time" + + apisexampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1 "acme.corp/pkg/generated/informers/externalversions/exampledashed/v1" + generatedlistersexampledashedv1 "acme.corp/pkg/generated/listers/exampledashed/v1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexampledashedv1 "acme.corp/pkg/kcpexisting/clients/listers/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" +) + +// ClusterTestTypeClusterInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeClusterInformer interface { + Cluster(logicalcluster.Name) exampledashedv1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) exampledashedv1.ClusterTestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() listersexampledashedv1.ClusterTestTypeClusterLister +} + +type clusterTestTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { + return kcpinformers.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().List(context.Background(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().Watch(context.Background(), options) + }, + }, + &apisexampledashedv1.ClusterTestType{}, + resyncPeriod, + indexers, + ) +} + +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexampledashedv1.ClusterTestType{}, i.defaultInformer) +} + +func (i *clusterTestTypeClusterInformer) Lister() listersexampledashedv1.ClusterTestTypeClusterLister { + return listersexampledashedv1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) +} + +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) exampledashedv1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) exampledashedv1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +type clusterTestTypeInformer struct { + informer cache.SharedIndexInformer + lister generatedlistersexampledashedv1.ClusterTestTypeLister +} + +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer +} + +func (i *clusterTestTypeInformer) Lister() generatedlistersexampledashedv1.ClusterTestTypeLister { + return i.lister +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/interface.go new file mode 100644 index 000000000..04919a1d7 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/interface.go @@ -0,0 +1,50 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-informer-gen. DO NOT EDIT. + +package v1 + +import ( + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. + ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { + return &version{factory: f, tweakListOptions: tweakListOptions} +} + +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. +func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { + return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go new file mode 100644 index 000000000..fe0aa76fd --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go @@ -0,0 +1,128 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-informer-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + time "time" + + apisexampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1 "acme.corp/pkg/generated/informers/externalversions/exampledashed/v1" + generatedlistersexampledashedv1 "acme.corp/pkg/generated/listers/exampledashed/v1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexampledashedv1 "acme.corp/pkg/kcpexisting/clients/listers/exampledashed/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" +) + +// TestTypeClusterInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeClusterInformer interface { + Cluster(logicalcluster.Name) exampledashedv1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) exampledashedv1.TestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() listersexampledashedv1.TestTypeClusterLister +} + +type testTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewTestTypeClusterInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { + return kcpinformers.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes().List(context.Background(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes().Watch(context.Background(), options) + }, + }, + &apisexampledashedv1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexampledashedv1.TestType{}, i.defaultInformer) +} + +func (i *testTypeClusterInformer) Lister() listersexampledashedv1.TestTypeClusterLister { + return listersexampledashedv1.NewTestTypeClusterLister(i.Informer().GetIndexer()) +} + +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) exampledashedv1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) exampledashedv1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + +type testTypeInformer struct { + informer cache.SharedIndexInformer + lister generatedlistersexampledashedv1.TestTypeLister +} + +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer +} + +func (i *testTypeInformer) Lister() generatedlistersexampledashedv1.TestTypeLister { + return i.lister +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/interface.go index cb7106362..47a8e729a 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,17 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package existinginterfaces import ( - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + v1 "acme.corp/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" ) +// ClusterInterface provides access to each of this group's versions. type ClusterInterface interface { - // V1 provides access to the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.ClusterInterface } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go index 46736b5c8..2f43ebd9e 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/informers/externalversions/existinginterfaces/v1" + generatedlistersexistinginterfacesv1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/listers/existinginterfaces/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - upstreamexistinginterfacesv1informers "acme.corp/pkg/generated/informers/externalversions/existinginterfaces/v1" - upstreamexistinginterfacesv1listers "acme.corp/pkg/generated/listers/existinginterfaces/v1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - existinginterfacesv1listers "acme.corp/pkg/kcpexisting/clients/listers/existinginterfaces/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexistinginterfacesv1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) existinginterfacesv1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) existinginterfacesv1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() existinginterfacesv1listers.ClusterTestTypeClusterLister + Lister() listersexistinginterfacesv1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -58,67 +56,73 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().ClusterTestTypes().List(context.TODO(), options) + return client.ExistinginterfacesV1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().ClusterTestTypes().Watch(context.TODO(), options) + return client.ExistinginterfacesV1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &existinginterfacesv1.ClusterTestType{}, + &apisexistinginterfacesv1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexistinginterfacesv1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&existinginterfacesv1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Lister() listersexistinginterfacesv1.ClusterTestTypeClusterLister { + return listersexistinginterfacesv1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *clusterTestTypeClusterInformer) Lister() existinginterfacesv1listers.ClusterTestTypeClusterLister { - return existinginterfacesv1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) existinginterfacesv1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexistinginterfacesv1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) existinginterfacesv1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexistinginterfacesv1listers.ClusterTestTypeLister + lister generatedlistersexistinginterfacesv1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() upstreamexistinginterfacesv1listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() generatedlistersexistinginterfacesv1.ClusterTestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/interface.go index ebae731bf..04919a1d7 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // TestTypes returns a TestTypeClusterInformer - TestTypes() TestTypeClusterInformer - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -37,17 +34,17 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// TestTypes returns a TestTypeClusterInformer -func (v *version) TestTypes() TestTypeClusterInformer { - return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/testtype.go index 0d8baaa5b..515fd7e3e 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/informers/externalversions/existinginterfaces/v1" + generatedlistersexistinginterfacesv1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listersexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/listers/existinginterfaces/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - upstreamexistinginterfacesv1informers "acme.corp/pkg/generated/informers/externalversions/existinginterfaces/v1" - upstreamexistinginterfacesv1listers "acme.corp/pkg/generated/listers/existinginterfaces/v1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - existinginterfacesv1listers "acme.corp/pkg/kcpexisting/clients/listers/existinginterfaces/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexistinginterfacesv1informers.TestTypeInformer + Cluster(logicalcluster.Name) existinginterfacesv1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) existinginterfacesv1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() existinginterfacesv1listers.TestTypeClusterLister + Lister() listersexistinginterfacesv1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -58,67 +56,73 @@ type testTypeClusterInformer struct { // NewTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().TestTypes().List(context.TODO(), options) + return client.ExistinginterfacesV1().TestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.ExistinginterfacesV1().TestTypes().Watch(context.TODO(), options) + return client.ExistinginterfacesV1().TestTypes().Watch(context.Background(), options) }, }, - &existinginterfacesv1.TestType{}, + &apisexistinginterfacesv1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, - f.tweakListOptions, - ) + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexistinginterfacesv1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&existinginterfacesv1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Lister() listersexistinginterfacesv1.TestTypeClusterLister { + return listersexistinginterfacesv1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *testTypeClusterInformer) Lister() existinginterfacesv1listers.TestTypeClusterLister { - return existinginterfacesv1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) existinginterfacesv1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexistinginterfacesv1informers.TestTypeInformer { +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) existinginterfacesv1.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexistinginterfacesv1listers.TestTypeLister + lister generatedlistersexistinginterfacesv1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() upstreamexistinginterfacesv1listers.TestTypeLister { - return f.lister +func (i *testTypeInformer) Lister() generatedlistersexistinginterfacesv1.TestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go b/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go index 2589763fc..5c10202db 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,30 +14,31 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. -package informers +package externalversions import ( - "reflect" - "sync" - "time" + reflect "reflect" + sync "sync" + time "time" + + informersexternalversions "acme.corp/pkg/generated/informers/externalversions" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + example "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example" + example3 "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example3" + exampledashed "acme.corp/pkg/kcpexisting/clients/informers/externalversions/exampledashed" + existinginterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + secondexample "acme.corp/pkg/kcpexisting/clients/informers/externalversions/secondexample" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/tools/cache" - - upstreaminformers "acme.corp/pkg/generated/informers/externalversions" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - exampleinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example" - example3informers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example3" - existinginterfacesinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - secondexampleinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/secondexample" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // SharedInformerOption defines the functional option type for SharedInformerFactory. @@ -49,14 +47,17 @@ type SharedInformerOption func(*SharedInformerOptions) *SharedInformerOptions type SharedInformerOptions struct { customResync map[reflect.Type]time.Duration tweakListOptions internalinterfaces.TweakListOptionsFunc + transform cache.TransformFunc + namespace string } type sharedInformerFactory struct { - client clientset.ClusterInterface + client versioned.ClusterInterface tweakListOptions internalinterfaces.TweakListOptionsFunc lock sync.Mutex defaultResync time.Duration customResync map[reflect.Type]time.Duration + transform cache.TransformFunc informers map[reflect.Type]kcpcache.ScopeableSharedIndexInformer // startedInformers is used for tracking which informers have been started. @@ -70,7 +71,7 @@ type sharedInformerFactory struct { } // WithCustomResyncConfig sets a custom resync period for the specified informer types. -func WithCustomResyncConfig(resyncConfig map[metav1.Object]time.Duration) SharedInformerOption { +func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { return func(opts *SharedInformerOptions) *SharedInformerOptions { for k, v := range resyncConfig { opts.customResync[reflect.TypeOf(k)] = v @@ -87,13 +88,29 @@ func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFu } } -// NewSharedInformerFactory constructs a new instance of SharedInformerFactory for all namespaces. -func NewSharedInformerFactory(client clientset.ClusterInterface, defaultResync time.Duration) SharedInformerFactory { +// WithTransform sets a transform on all informers. +func WithTransform(transform cache.TransformFunc) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + opts.transform = transform + return opts + } +} + +// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client versioned.ClusterInterface, defaultResync time.Duration) SharedInformerFactory { return NewSharedInformerFactoryWithOptions(client, defaultResync) } +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +// Deprecated: Please use NewSharedInformerFactoryWithOptions instead +func NewFilteredSharedInformerFactory(client versioned.ClusterInterface, defaultResync time.Duration, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync, WithTweakListOptions(tweakListOptions)) +} + // NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. -func NewSharedInformerFactoryWithOptions(client clientset.ClusterInterface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { +func NewSharedInformerFactoryWithOptions(client versioned.ClusterInterface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { factory := &sharedInformerFactory{ client: client, defaultResync: defaultResync, @@ -114,11 +131,11 @@ func NewSharedInformerFactoryWithOptions(client clientset.ClusterInterface, defa // Forward options to the factory factory.customResync = opts.customResync factory.tweakListOptions = opts.tweakListOptions + factory.transform = opts.transform return factory } -// Start initializes all requested informers. func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { f.lock.Lock() defer f.lock.Unlock() @@ -152,7 +169,6 @@ func (f *sharedInformerFactory) Shutdown() { f.wg.Wait() } -// WaitForCacheSync waits for all started informers' cache were synced. func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { informers := func() map[reflect.Type]kcpcache.ScopeableSharedIndexInformer { f.lock.Lock() @@ -171,10 +187,11 @@ func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[ref for informType, informer := range informers { res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) } + return res } -// InformerFor returns the SharedIndexInformer for obj. +// InformerFor returns the ScopeableSharedIndexInformer for obj using an internal client. func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer { f.lock.Lock() defer f.lock.Unlock() @@ -191,6 +208,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal } informer = newFunc(f.client, resyncPeriod) + informer.SetTransform(f.transform) f.informers[informerType] = informer return informer @@ -198,7 +216,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal type ScopedDynamicSharedInformerFactory interface { // ForResource gives generic access to a shared informer of the matching type. - ForResource(resource schema.GroupVersionResource) (upstreaminformers.GenericInformer, error) + ForResource(resource schema.GroupVersionResource) (informersexternalversions.GenericInformer, error) // Start initializes all requested informers. They are handled in goroutines // which run until the stop channel gets closed. @@ -212,11 +230,11 @@ type ScopedDynamicSharedInformerFactory interface { // // ctx, cancel := context.Background() // defer cancel() -// factory := NewSharedInformerFactoryWithOptions(client, resyncPeriod) -// defer factory.Shutdown() // Returns immediately if nothing was started. +// factory := NewSharedInformerFactory(client, resyncPeriod) +// defer factory.WaitForStop() // Returns immediately if nothing was started. // genericInformer := factory.ForResource(resource) // typedInformer := factory.SomeAPIGroup().V1().SomeType() -// factory.Start(ctx.Done()) // Start processing these informers. +// factory.Start(ctx.Done()) // Start processing these informers. // synced := factory.WaitForCacheSync(ctx.Done()) // for v, ok := range synced { // if !ok { @@ -236,6 +254,7 @@ type SharedInformerFactory interface { // Start initializes all requested informers. They are handled in goroutines // which run until the stop channel gets closed. + // Warning: Start does not block. When run in a go-routine, it will race with a later WaitForCacheSync. Start(stopCh <-chan struct{}) // Shutdown marks a factory as shutting down. At that point no new @@ -250,36 +269,42 @@ type SharedInformerFactory interface { // block until all goroutines have terminated. Shutdown() - // ForResource gives generic access to a shared informer of the matching type. - ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) - // WaitForCacheSync blocks until all started informers' caches were synced // or the stop channel gets closed. WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool - // InformerFor returns the SharedIndexInformer for obj. + // ForResource gives generic access to a shared informer of the matching type. + ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) + + // InformerFor returns the SharedIndexInformer for obj using an internal + // client. InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer - Example() exampleinformers.ClusterInterface - Example3() example3informers.ClusterInterface - Existinginterfaces() existinginterfacesinformers.ClusterInterface - Secondexample() secondexampleinformers.ClusterInterface + Example() example.ClusterInterface + Example3() example3.ClusterInterface + ExampleDashed() exampledashed.ClusterInterface + Existinginterfaces() existinginterfaces.ClusterInterface + Secondexample() secondexample.ClusterInterface +} + +func (f *sharedInformerFactory) Example() example.ClusterInterface { + return example.New(f, f.tweakListOptions) } -func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { - return exampleinformers.New(f, f.tweakListOptions) +func (f *sharedInformerFactory) Example3() example3.ClusterInterface { + return example3.New(f, f.tweakListOptions) } -func (f *sharedInformerFactory) Example3() example3informers.ClusterInterface { - return example3informers.New(f, f.tweakListOptions) +func (f *sharedInformerFactory) ExampleDashed() exampledashed.ClusterInterface { + return exampledashed.New(f, f.tweakListOptions) } -func (f *sharedInformerFactory) Existinginterfaces() existinginterfacesinformers.ClusterInterface { - return existinginterfacesinformers.New(f, f.tweakListOptions) +func (f *sharedInformerFactory) Existinginterfaces() existinginterfaces.ClusterInterface { + return existinginterfaces.New(f, f.tweakListOptions) } -func (f *sharedInformerFactory) Secondexample() secondexampleinformers.ClusterInterface { - return secondexampleinformers.New(f, f.tweakListOptions) +func (f *sharedInformerFactory) Secondexample() secondexample.ClusterInterface { + return secondexample.New(f, f.tweakListOptions) } func (f *sharedInformerFactory) Cluster(clusterName logicalcluster.Name) ScopedDynamicSharedInformerFactory { @@ -294,7 +319,7 @@ type scopedDynamicSharedInformerFactory struct { clusterName logicalcluster.Name } -func (f *scopedDynamicSharedInformerFactory) ForResource(resource schema.GroupVersionResource) (upstreaminformers.GenericInformer, error) { +func (f *scopedDynamicSharedInformerFactory) ForResource(resource schema.GroupVersionResource) (informersexternalversions.GenericInformer, error) { clusterInformer, err := f.sharedInformerFactory.ForResource(resource) if err != nil { return nil, err diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go index f6a0e1ccd..e21d34f8d 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,31 +14,34 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. -package informers +package externalversions import ( - "fmt" - - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" - - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/tools/cache" + context "context" + fmt "fmt" examplev1 "acme.corp/pkg/apis/example/v1" - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - examplev2 "acme.corp/pkg/apis/example/v2" + v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + v1beta1 "acme.corp/pkg/apis/example/v1beta1" + v2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + v1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - upstreaminformers "acme.corp/pkg/generated/informers/externalversions" + informersexternalversions "acme.corp/pkg/generated/informers/externalversions" + + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) type GenericClusterInformer interface { - Cluster(logicalcluster.Name) upstreaminformers.GenericInformer + Cluster(logicalcluster.Name) informersexternalversions.GenericInformer + ClusterWithContext(context.Context, logicalcluster.Name) informersexternalversions.GenericInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() kcpcache.GenericClusterLister } @@ -52,20 +52,29 @@ type genericClusterInformer struct { } // Informer returns the SharedIndexInformer. -func (f *genericClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.informer +func (i *genericClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.informer } -// Lister returns the GenericClusterLister. -func (f *genericClusterInformer) Lister() kcpcache.GenericClusterLister { - return kcpcache.NewGenericClusterLister(f.Informer().GetIndexer(), f.resource) +// Lister returns the GenericLister. +func (i *genericClusterInformer) Lister() kcpcache.GenericClusterLister { + return kcpcache.NewGenericClusterLister(i.Informer().GetIndexer(), i.resource) } // Cluster scopes to a GenericInformer. -func (f *genericClusterInformer) Cluster(clusterName logicalcluster.Name) upstreaminformers.GenericInformer { +func (i *genericClusterInformer) Cluster(clusterName logicalcluster.Name) informersexternalversions.GenericInformer { + return &genericInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().ByCluster(clusterName), + } +} + +// ClusterWithContext scopes to a GenericInformer and unregisters all +// handles registered through it once the provided context is canceled. +func (i *genericClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) informersexternalversions.GenericInformer { return &genericInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().ByCluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().ByCluster(clusterName), } } @@ -75,52 +84,67 @@ type genericInformer struct { } // Informer returns the SharedIndexInformer. -func (f *genericInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *genericInformer) Informer() cache.SharedIndexInformer { + return i.informer } // Lister returns the GenericLister. -func (f *genericInformer) Lister() cache.GenericLister { - return f.lister +func (i *genericInformer) Lister() cache.GenericLister { + return i.lister } // ForResource gives generic access to a shared informer of the matching type // TODO extend this to unknown resources with a client pool func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) { switch resource { - // Group=example3.some.corp, Version=V1 - case example3v1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().TestTypes().Informer()}, nil - case example3v1.SchemeGroupVersion.WithResource("clustertesttypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().ClusterTestTypes().Informer()}, nil - // Group=example, Version=V1 - case examplev1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1().TestTypes().Informer()}, nil + // Group=example-dashed.some.corp, Version=v1 + case v1.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().ClusterTestTypes().Informer()}, nil + case v1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().TestTypes().Informer()}, nil + + // Group=example.dev, Version=v1 case examplev1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1().ClusterTestTypes().Informer()}, nil - // Group=example, Version=V1alpha1 - case examplev1alpha1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1alpha1().TestTypes().Informer()}, nil - case examplev1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"): + case examplev1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1().TestTypes().Informer()}, nil + + // Group=example.dev, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1alpha1().ClusterTestTypes().Informer()}, nil - // Group=example, Version=V1beta1 - case examplev1beta1.SchemeGroupVersion.WithResource("clustertesttypes"): + case v1alpha1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1alpha1().TestTypes().Informer()}, nil + + // Group=example.dev, Version=v1beta1 + case v1beta1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().ClusterTestTypes().Informer()}, nil - // Group=example, Version=V2 - case examplev2.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V2().TestTypes().Informer()}, nil - case examplev2.SchemeGroupVersion.WithResource("clustertesttypes"): + case v1beta1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().TestTypes().Informer()}, nil + + // Group=example.dev, Version=v2 + case v2.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V2().ClusterTestTypes().Informer()}, nil - // Group=existinginterfaces.acme.corp, Version=V1 - case existinginterfacesv1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Existinginterfaces().V1().TestTypes().Informer()}, nil + case v2.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V2().TestTypes().Informer()}, nil + + // Group=example3.some.corp, Version=v1 + case example3v1.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().ClusterTestTypes().Informer()}, nil + case example3v1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().TestTypes().Informer()}, nil + + // Group=existinginterfaces.acme.corp, Version=v1 case existinginterfacesv1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Existinginterfaces().V1().ClusterTestTypes().Informer()}, nil - // Group=secondexample, Version=V1 - case secondexamplev1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Secondexample().V1().TestTypes().Informer()}, nil + case existinginterfacesv1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Existinginterfaces().V1().TestTypes().Informer()}, nil + + // Group=secondexample.dev, Version=v1 case secondexamplev1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Secondexample().V1().ClusterTestTypes().Informer()}, nil + case secondexamplev1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Secondexample().V1().TestTypes().Informer()}, nil + } return nil, fmt.Errorf("no informer found for %v", resource) diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces/factory_interfaces.go b/examples/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces/factory_interfaces.go index 6db808f71..e4c66864f 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,29 +14,29 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package internalinterfaces import ( time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" ) -// NewInformerFunc takes clientset.ClusterInterface and time.Duration to return a ScopeableSharedIndexInformer. -type NewInformerFunc func(clientset.ClusterInterface, time.Duration) kcpcache.ScopeableSharedIndexInformer +// TweakListOptionsFunc is a function that transforms a v1.ListOptions. +type TweakListOptionsFunc func(*v1.ListOptions) -// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +// NewInformerFunc takes versioned.ClusterInterface and time.Duration to return a kcpcache.ScopeableSharedIndexInformer. +type NewInformerFunc func(versioned.ClusterInterface, time.Duration) kcpcache.ScopeableSharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle. type SharedInformerFactory interface { Start(stopCh <-chan struct{}) InformerFor(obj runtime.Object, newFunc NewInformerFunc) kcpcache.ScopeableSharedIndexInformer } - -// TweakListOptionsFunc is a function that transforms a metav1.ListOptions. -type TweakListOptionsFunc func(*metav1.ListOptions) diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/interface.go index c69429356..81dbe752b 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,17 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package secondexample import ( - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + v1 "acme.corp/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1" ) +// ClusterInterface provides access to each of this group's versions. type ClusterInterface interface { - // V1 provides access to the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.ClusterInterface } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/clustertesttype.go index 53656664d..3f15af722 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/informers/externalversions/secondexample/v1" + generatedlisterssecondexamplev1 "acme.corp/pkg/generated/listers/secondexample/v1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listerssecondexamplev1 "acme.corp/pkg/kcpexisting/clients/listers/secondexample/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - upstreamsecondexamplev1informers "acme.corp/pkg/generated/informers/externalversions/secondexample/v1" - upstreamsecondexamplev1listers "acme.corp/pkg/generated/listers/secondexample/v1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - secondexamplev1listers "acme.corp/pkg/kcpexisting/clients/listers/secondexample/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamsecondexamplev1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) secondexamplev1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) secondexamplev1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() secondexamplev1listers.ClusterTestTypeClusterLister + Lister() listerssecondexamplev1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -58,67 +56,73 @@ type clusterTestTypeClusterInformer struct { // NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredClusterTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().ClusterTestTypes().List(context.TODO(), options) + return client.SecondexampleV1().ClusterTestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().ClusterTestTypes().Watch(context.TODO(), options) + return client.SecondexampleV1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &secondexamplev1.ClusterTestType{}, + &apissecondexamplev1.ClusterTestType{}, resyncPeriod, indexers, ) } -func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *clusterTestTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apissecondexamplev1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&secondexamplev1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Lister() listerssecondexamplev1.ClusterTestTypeClusterLister { + return listerssecondexamplev1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *clusterTestTypeClusterInformer) Lister() secondexamplev1listers.ClusterTestTypeClusterLister { - return secondexamplev1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) secondexamplev1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamsecondexamplev1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) secondexamplev1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamsecondexamplev1listers.ClusterTestTypeLister + lister generatedlisterssecondexamplev1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() upstreamsecondexamplev1listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() generatedlisterssecondexamplev1.ClusterTestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/interface.go index ebae731bf..04919a1d7 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/interface.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" ) type ClusterInterface interface { - // TestTypes returns a TestTypeClusterInformer - TestTypes() TestTypeClusterInformer - // ClusterTestTypes returns a ClusterTestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer. ClusterTestTypes() ClusterTestTypeClusterInformer + // TestTypes returns a TestTypeClusterInformer. + TestTypes() TestTypeClusterInformer } type version struct { @@ -37,17 +34,17 @@ type version struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -// New returns a new ClusterInterface. +// New returns a new Interface. func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { return &version{factory: f, tweakListOptions: tweakListOptions} } -// TestTypes returns a TestTypeClusterInformer -func (v *version) TestTypes() TestTypeClusterInformer { - return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - -// ClusterTestTypes returns a ClusterTestTypeClusterInformer +// ClusterTestTypes returns a ClusterTestTypeClusterInformer. func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeClusterInformer. +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/testtype.go index aa01847e4..e85ed5847 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,37 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-informer-gen. DO NOT EDIT. package v1 import ( - "context" - "time" + context "context" + time "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/informers/externalversions/secondexample/v1" + generatedlisterssecondexamplev1 "acme.corp/pkg/generated/listers/secondexample/v1" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + internalinterfaces "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + listerssecondexamplev1 "acme.corp/pkg/kcpexisting/clients/listers/secondexample/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - upstreamsecondexamplev1informers "acme.corp/pkg/generated/informers/externalversions/secondexample/v1" - upstreamsecondexamplev1listers "acme.corp/pkg/generated/listers/secondexample/v1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - secondexamplev1listers "acme.corp/pkg/kcpexisting/clients/listers/secondexample/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamsecondexamplev1informers.TestTypeInformer + Cluster(logicalcluster.Name) secondexamplev1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) secondexamplev1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() secondexamplev1listers.TestTypeClusterLister + Lister() listerssecondexamplev1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -58,67 +56,73 @@ type testTypeClusterInformer struct { // NewTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { +func NewTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) } // NewFilteredTestTypeClusterInformer constructs a new informer for TestType type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { +func NewFilteredTestTypeClusterInformer(client versioned.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { return kcpinformers.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().TestTypes().List(context.TODO(), options) + return client.SecondexampleV1().TestTypes().List(context.Background(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.SecondexampleV1().TestTypes().Watch(context.TODO(), options) + return client.SecondexampleV1().TestTypes().Watch(context.Background(), options) }, }, - &secondexamplev1.TestType{}, + &apissecondexamplev1.TestType{}, resyncPeriod, indexers, ) } -func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { +func (i *testTypeClusterInformer) defaultInformer(client versioned.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, - f.tweakListOptions, - ) + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc, + }, i.tweakListOptions) +} + +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apissecondexamplev1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&secondexamplev1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Lister() listerssecondexamplev1.TestTypeClusterLister { + return listerssecondexamplev1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *testTypeClusterInformer) Lister() secondexamplev1listers.TestTypeClusterLister { - return secondexamplev1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) secondexamplev1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), + } } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamsecondexamplev1informers.TestTypeInformer { +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) secondexamplev1.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamsecondexamplev1listers.TestTypeLister + lister generatedlisterssecondexamplev1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() upstreamsecondexamplev1listers.TestTypeLister { - return f.lister +func (i *testTypeInformer) Lister() generatedlisterssecondexamplev1.TestTypeLister { + return i.lister } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype.go index c289b01a1..7c789d6c0 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,82 +14,79 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev1 "acme.corp/pkg/apis/example/v1" + listersexamplev1 "acme.corp/pkg/generated/listers/example/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev1 "acme.corp/pkg/apis/example/v1" - examplev1listers "acme.corp/pkg/generated/listers/example/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev1.ClusterTestType, err error) // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) examplev1listers.ClusterTestTypeLister + Cluster(clusterName logicalcluster.Name) listersexamplev1.ClusterTestTypeLister ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev1.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*examplev1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev1.ClusterTestType)) - }) - return ret, err +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) examplev1listers.ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// clusterTestTypeLister implements the examplev1listers.ClusterTestTypeLister interface. +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexamplev1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*examplev1.ClusterTestType] } -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*examplev1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1.ClusterTestType)) - }) - return ret, err -} +var _ listersexamplev1.ClusterTestTypeLister = new(clusterTestTypeLister) -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*examplev1.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1.Resource("clustertesttypes"), name) +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) listersexamplev1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), } - return obj.(*examplev1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexamplev1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + kcplisters.ResourceIndexer[*examplev1.ClusterTestType] } diff --git a/examples/pkg/kcp/clients/listers/example/v1/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/example/v1/expansion_generated.go similarity index 62% rename from examples/pkg/kcp/clients/listers/example/v1/clustertesttype_expansion.go rename to examples/pkg/kcpexisting/clients/listers/example/v1/expansion_generated.go index a85e878f1..41011dc91 100644 --- a/examples/pkg/kcp/clients/listers/example/v1/clustertesttype_expansion.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,12 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. type ClusterTestTypeClusterListerExpansion interface{} -// ClusterTestTypeListerExpansion allows custom methods to be added to ClusterTestTypeLister. -type ClusterTestTypeListerExpansion interface{} +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} + +// WithoutVerbTypeClusterListerExpansion allows custom methods to be added to +// WithoutVerbTypeClusterLister. +type WithoutVerbTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/example/v1/testtype.go index 028a87771..f316d62f0 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,103 +14,103 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev1 "acme.corp/pkg/apis/example/v1" + listersexamplev1 "acme.corp/pkg/generated/listers/example/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev1 "acme.corp/pkg/apis/example/v1" - examplev1listers "acme.corp/pkg/generated/listers/example/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. // All objects returned here must be treated as read-only. type TestTypeClusterLister interface { // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev1.TestType, err error) // Cluster returns a lister that can list and get TestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) examplev1listers.TestTypeLister + Cluster(clusterName logicalcluster.Name) listersexamplev1.TestTypeLister TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev1.TestType] } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*examplev1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev1.TestType)) - }) - return ret, err +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev1.TestType](indexer, examplev1.Resource("testtype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) examplev1listers.TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1.TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// testTypeLister implements the examplev1listers.TestTypeLister interface. +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a listersexamplev1.TestTypeNamespaceLister for one namespace. type testTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*examplev1.TestType] } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*examplev1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1.TestType)) - }) - return ret, err -} +var _ listersexamplev1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) examplev1listers.TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +func (l *testTypeLister) TestTypes(namespace string) listersexamplev1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } -// testTypeNamespaceLister implements the examplev1listers.TestTypeNamespaceLister interface. +// testTypeNamespaceLister implements the listersexamplev1.TestTypeNamespaceLister +// interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string + kcplisters.ResourceIndexer[*examplev1.TestType] } -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*examplev1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1.TestType)) - }) - return ret, err -} +var _ listersexamplev1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*examplev1.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err +// NewTestTypeLister returns a new TestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) listersexamplev1.TestTypeLister { + return &testTypeLister{ + kcplisters.New[*examplev1.TestType](indexer, examplev1.Resource("testtype")), } - if !exists { - return nil, errors.NewNotFound(examplev1.Resource("testtypes"), name) +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexamplev1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + kcplisters.ResourceIndexer[*examplev1.TestType] +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), } - return obj.(*examplev1.TestType), nil } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1/withoutverbtype.go b/examples/pkg/kcpexisting/clients/listers/example/v1/withoutverbtype.go new file mode 100644 index 000000000..61e1ef48c --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/example/v1/withoutverbtype.go @@ -0,0 +1,116 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-lister-gen. DO NOT EDIT. + +package v1 + +import ( + examplev1 "acme.corp/pkg/apis/example/v1" + listersexamplev1 "acme.corp/pkg/generated/listers/example/v1" + + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" +) + +// WithoutVerbTypeClusterLister helps list WithoutVerbTypes across all workspaces, +// or scope down to a WithoutVerbTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type WithoutVerbTypeClusterLister interface { + // List lists all WithoutVerbTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*examplev1.WithoutVerbType, err error) + // Cluster returns a lister that can list and get WithoutVerbTypes in one workspace. + Cluster(clusterName logicalcluster.Name) listersexamplev1.WithoutVerbTypeLister + WithoutVerbTypeClusterListerExpansion +} + +// withoutVerbTypeClusterLister implements the WithoutVerbTypeClusterLister interface. +type withoutVerbTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev1.WithoutVerbType] +} + +var _ WithoutVerbTypeClusterLister = new(withoutVerbTypeClusterLister) + +// NewWithoutVerbTypeClusterLister returns a new WithoutVerbTypeClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewWithoutVerbTypeClusterLister(indexer cache.Indexer) WithoutVerbTypeClusterLister { + return &withoutVerbTypeClusterLister{ + kcplisters.NewCluster[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype")), + } +} + +// Cluster scopes the lister to one workspace, allowing users to list and get WithoutVerbTypes. +func (l *withoutVerbTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1.WithoutVerbTypeLister { + return &withoutVerbTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } +} + +// withoutVerbTypeLister can list all WithoutVerbTypes inside a workspace +// or scope down to a listersexamplev1.WithoutVerbTypeNamespaceLister for one namespace. +type withoutVerbTypeLister struct { + kcplisters.ResourceIndexer[*examplev1.WithoutVerbType] +} + +var _ listersexamplev1.WithoutVerbTypeLister = new(withoutVerbTypeLister) + +// WithoutVerbTypes returns an object that can list and get WithoutVerbTypes in one namespace. +func (l *withoutVerbTypeLister) WithoutVerbTypes(namespace string) listersexamplev1.WithoutVerbTypeNamespaceLister { + return &withoutVerbTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} + +// withoutVerbTypeNamespaceLister implements the listersexamplev1.WithoutVerbTypeNamespaceLister +// interface. +type withoutVerbTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*examplev1.WithoutVerbType] +} + +var _ listersexamplev1.WithoutVerbTypeNamespaceLister = new(withoutVerbTypeNamespaceLister) + +// NewWithoutVerbTypeLister returns a new WithoutVerbTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewWithoutVerbTypeLister(indexer cache.Indexer) listersexamplev1.WithoutVerbTypeLister { + return &withoutVerbTypeLister{ + kcplisters.New[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype")), + } +} + +// withoutVerbTypeScopedLister can list all WithoutVerbTypes inside a workspace +// or scope down to a listersexamplev1.WithoutVerbTypeNamespaceLister for one namespace. +type withoutVerbTypeScopedLister struct { + kcplisters.ResourceIndexer[*examplev1.WithoutVerbType] +} + +// WithoutVerbTypes returns an object that can list and get WithoutVerbTypes in one namespace. +func (l *withoutVerbTypeScopedLister) WithoutVerbTypes(namespace string) listersexamplev1.WithoutVerbTypeLister { + return &withoutVerbTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype.go index 44ab6bff9..a8eb8f226 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,82 +14,79 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1alpha1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + listersexamplev1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - examplev1alpha1listers "acme.corp/pkg/generated/listers/example/v1alpha1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev1alpha1.ClusterTestType, err error) // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) examplev1alpha1listers.ClusterTestTypeLister + Cluster(clusterName logicalcluster.Name) listersexamplev1alpha1.ClusterTestTypeLister ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev1alpha1.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*examplev1alpha1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev1alpha1.ClusterTestType)) - }) - return ret, err +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) examplev1alpha1listers.ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1alpha1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// clusterTestTypeLister implements the examplev1alpha1listers.ClusterTestTypeLister interface. +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexamplev1alpha1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*examplev1alpha1.ClusterTestType] } -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*examplev1alpha1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1alpha1.ClusterTestType)) - }) - return ret, err -} +var _ listersexamplev1alpha1.ClusterTestTypeLister = new(clusterTestTypeLister) -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*examplev1alpha1.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1alpha1.Resource("clustertesttypes"), name) +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) listersexamplev1alpha1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), } - return obj.(*examplev1alpha1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexamplev1alpha1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + kcplisters.ResourceIndexer[*examplev1alpha1.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/expansion_generated.go similarity index 73% rename from examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype_expansion.go rename to examples/pkg/kcpexisting/clients/listers/example/v1alpha1/expansion_generated.go index 5532a01ca..3115d701b 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype_expansion.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,9 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1alpha1 -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. type ClusterTestTypeClusterListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype.go b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype.go index 74468b758..c6fc02cca 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,103 +14,103 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1alpha1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + listersexamplev1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - examplev1alpha1listers "acme.corp/pkg/generated/listers/example/v1alpha1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. // All objects returned here must be treated as read-only. type TestTypeClusterLister interface { // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) // Cluster returns a lister that can list and get TestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) examplev1alpha1listers.TestTypeLister + Cluster(clusterName logicalcluster.Name) listersexamplev1alpha1.TestTypeLister TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev1alpha1.TestType] } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev1alpha1.TestType)) - }) - return ret, err +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) examplev1alpha1listers.TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1alpha1.TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// testTypeLister implements the examplev1alpha1listers.TestTypeLister interface. +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a listersexamplev1alpha1.TestTypeNamespaceLister for one namespace. type testTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*examplev1alpha1.TestType] } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1alpha1.TestType)) - }) - return ret, err -} +var _ listersexamplev1alpha1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) examplev1alpha1listers.TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +func (l *testTypeLister) TestTypes(namespace string) listersexamplev1alpha1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } -// testTypeNamespaceLister implements the examplev1alpha1listers.TestTypeNamespaceLister interface. +// testTypeNamespaceLister implements the listersexamplev1alpha1.TestTypeNamespaceLister +// interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string + kcplisters.ResourceIndexer[*examplev1alpha1.TestType] } -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*examplev1alpha1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1alpha1.TestType)) - }) - return ret, err -} +var _ listersexamplev1alpha1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*examplev1alpha1.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err +// NewTestTypeLister returns a new TestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) listersexamplev1alpha1.TestTypeLister { + return &testTypeLister{ + kcplisters.New[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), } - if !exists { - return nil, errors.NewNotFound(examplev1alpha1.Resource("testtypes"), name) +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexamplev1alpha1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + kcplisters.ResourceIndexer[*examplev1alpha1.TestType] +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev1alpha1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), } - return obj.(*examplev1alpha1.TestType), nil } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype.go index f28f04c76..8340fca94 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,82 +14,79 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1beta1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + listersexamplev1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - examplev1beta1listers "acme.corp/pkg/generated/listers/example/v1beta1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev1beta1.ClusterTestType, err error) // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) examplev1beta1listers.ClusterTestTypeLister + Cluster(clusterName logicalcluster.Name) listersexamplev1beta1.ClusterTestTypeLister ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev1beta1.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*examplev1beta1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev1beta1.ClusterTestType)) - }) - return ret, err +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) examplev1beta1listers.ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1beta1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// clusterTestTypeLister implements the examplev1beta1listers.ClusterTestTypeLister interface. +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexamplev1beta1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*examplev1beta1.ClusterTestType] } -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*examplev1beta1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1beta1.ClusterTestType)) - }) - return ret, err -} +var _ listersexamplev1beta1.ClusterTestTypeLister = new(clusterTestTypeLister) -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*examplev1beta1.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev1beta1.Resource("clustertesttypes"), name) +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) listersexamplev1beta1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), } - return obj.(*examplev1beta1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexamplev1beta1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + kcplisters.ResourceIndexer[*examplev1beta1.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/expansion_generated.go similarity index 73% rename from examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype_expansion.go rename to examples/pkg/kcpexisting/clients/listers/example/v1beta1/expansion_generated.go index 06ff57611..5417de576 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype_expansion.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,9 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1beta1 -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. type ClusterTestTypeClusterListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/testtype.go b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/testtype.go new file mode 100644 index 000000000..236fe7197 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/testtype.go @@ -0,0 +1,116 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-lister-gen. DO NOT EDIT. + +package v1beta1 + +import ( + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + listersexamplev1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" + + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" +) + +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type TestTypeClusterLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*examplev1beta1.TestType, err error) + // Cluster returns a lister that can list and get TestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) listersexamplev1beta1.TestTypeLister + TestTypeClusterListerExpansion +} + +// testTypeClusterLister implements the TestTypeClusterLister interface. +type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev1beta1.TestType] +} + +var _ TestTypeClusterLister = new(testTypeClusterLister) + +// NewTestTypeClusterLister returns a new TestTypeClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), + } +} + +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1beta1.TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } +} + +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a listersexamplev1beta1.TestTypeNamespaceLister for one namespace. +type testTypeLister struct { + kcplisters.ResourceIndexer[*examplev1beta1.TestType] +} + +var _ listersexamplev1beta1.TestTypeLister = new(testTypeLister) + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeLister) TestTypes(namespace string) listersexamplev1beta1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} + +// testTypeNamespaceLister implements the listersexamplev1beta1.TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*examplev1beta1.TestType] +} + +var _ listersexamplev1beta1.TestTypeNamespaceLister = new(testTypeNamespaceLister) + +// NewTestTypeLister returns a new TestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) listersexamplev1beta1.TestTypeLister { + return &testTypeLister{ + kcplisters.New[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), + } +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexamplev1beta1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + kcplisters.ResourceIndexer[*examplev1beta1.TestType] +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev1beta1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} diff --git a/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype.go index d587dcc46..920973631 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,82 +14,79 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v2 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev2 "acme.corp/pkg/apis/example/v2" + listersexamplev2 "acme.corp/pkg/generated/listers/example/v2" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev2 "acme.corp/pkg/apis/example/v2" - examplev2listers "acme.corp/pkg/generated/listers/example/v2" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev2.ClusterTestType, err error) // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) examplev2listers.ClusterTestTypeLister + Cluster(clusterName logicalcluster.Name) listersexamplev2.ClusterTestTypeLister ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev2.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*examplev2.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev2.ClusterTestType)) - }) - return ret, err +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) examplev2listers.ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev2.ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// clusterTestTypeLister implements the examplev2listers.ClusterTestTypeLister interface. +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexamplev2.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*examplev2.ClusterTestType] } -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*examplev2.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev2.ClusterTestType)) - }) - return ret, err -} +var _ listersexamplev2.ClusterTestTypeLister = new(clusterTestTypeLister) -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*examplev2.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(examplev2.Resource("clustertesttypes"), name) +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) listersexamplev2.ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), } - return obj.(*examplev2.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexamplev2.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + kcplisters.ResourceIndexer[*examplev2.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/example/v2/expansion_generated.go similarity index 73% rename from examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype_expansion.go rename to examples/pkg/kcpexisting/clients/listers/example/v2/expansion_generated.go index 8743bfbe7..ab8905793 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype_expansion.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v2/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,9 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v2 -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. type ClusterTestTypeClusterListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/example/v2/testtype.go b/examples/pkg/kcpexisting/clients/listers/example/v2/testtype.go index b94a32c92..e7c306e76 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v2/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v2/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,103 +14,103 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v2 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + examplev2 "acme.corp/pkg/apis/example/v2" + listersexamplev2 "acme.corp/pkg/generated/listers/example/v2" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - examplev2 "acme.corp/pkg/apis/example/v2" - examplev2listers "acme.corp/pkg/generated/listers/example/v2" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. // All objects returned here must be treated as read-only. type TestTypeClusterLister interface { // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*examplev2.TestType, err error) // Cluster returns a lister that can list and get TestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) examplev2listers.TestTypeLister + Cluster(clusterName logicalcluster.Name) listersexamplev2.TestTypeLister TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*examplev2.TestType] } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*examplev2.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev2.TestType)) - }) - return ret, err +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev2.TestType](indexer, examplev2.Resource("testtype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) examplev2listers.TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev2.TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// testTypeLister implements the examplev2listers.TestTypeLister interface. +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a listersexamplev2.TestTypeNamespaceLister for one namespace. type testTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*examplev2.TestType] } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*examplev2.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev2.TestType)) - }) - return ret, err -} +var _ listersexamplev2.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) examplev2listers.TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +func (l *testTypeLister) TestTypes(namespace string) listersexamplev2.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } -// testTypeNamespaceLister implements the examplev2listers.TestTypeNamespaceLister interface. +// testTypeNamespaceLister implements the listersexamplev2.TestTypeNamespaceLister +// interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string + kcplisters.ResourceIndexer[*examplev2.TestType] } -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*examplev2.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*examplev2.TestType)) - }) - return ret, err -} +var _ listersexamplev2.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*examplev2.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err +// NewTestTypeLister returns a new TestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) listersexamplev2.TestTypeLister { + return &testTypeLister{ + kcplisters.New[*examplev2.TestType](indexer, examplev2.Resource("testtype")), } - if !exists { - return nil, errors.NewNotFound(examplev2.Resource("testtypes"), name) +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexamplev2.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + kcplisters.ResourceIndexer[*examplev2.TestType] +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev2.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), } - return obj.(*examplev2.TestType), nil } diff --git a/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype.go index 13b06d11e..40f227312 100644 --- a/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,82 +14,79 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + example3v1 "acme.corp/pkg/apis/example3/v1" + listersexample3v1 "acme.corp/pkg/generated/listers/example3/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - example3v1 "acme.corp/pkg/apis/example3/v1" - example3v1listers "acme.corp/pkg/generated/listers/example3/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*example3v1.ClusterTestType, err error) // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) example3v1listers.ClusterTestTypeLister + Cluster(clusterName logicalcluster.Name) listersexample3v1.ClusterTestTypeLister ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*example3v1.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*example3v1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*example3v1.ClusterTestType)) - }) - return ret, err +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) example3v1listers.ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexample3v1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// clusterTestTypeLister implements the example3v1listers.ClusterTestTypeLister interface. +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexample3v1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*example3v1.ClusterTestType] } -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*example3v1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*example3v1.ClusterTestType)) - }) - return ret, err -} +var _ listersexample3v1.ClusterTestTypeLister = new(clusterTestTypeLister) -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*example3v1.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(example3v1.Resource("clustertesttypes"), name) +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) listersexample3v1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), } - return obj.(*example3v1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexample3v1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + kcplisters.ResourceIndexer[*example3v1.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/example3/v1/expansion_generated.go similarity index 73% rename from examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype_expansion.go rename to examples/pkg/kcpexisting/clients/listers/example3/v1/expansion_generated.go index 08fb95b1c..4baaf1768 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype_expansion.go +++ b/examples/pkg/kcpexisting/clients/listers/example3/v1/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,9 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. type ClusterTestTypeClusterListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/example3/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/example3/v1/testtype.go index e7dd12058..3eba1dd2b 100644 --- a/examples/pkg/kcpexisting/clients/listers/example3/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example3/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,103 +14,103 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + example3v1 "acme.corp/pkg/apis/example3/v1" + listersexample3v1 "acme.corp/pkg/generated/listers/example3/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - example3v1 "acme.corp/pkg/apis/example3/v1" - example3v1listers "acme.corp/pkg/generated/listers/example3/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. // All objects returned here must be treated as read-only. type TestTypeClusterLister interface { // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*example3v1.TestType, err error) // Cluster returns a lister that can list and get TestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) example3v1listers.TestTypeLister + Cluster(clusterName logicalcluster.Name) listersexample3v1.TestTypeLister TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*example3v1.TestType] } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*example3v1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*example3v1.TestType)) - }) - return ret, err +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*example3v1.TestType](indexer, example3v1.Resource("testtype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) example3v1listers.TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexample3v1.TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// testTypeLister implements the example3v1listers.TestTypeLister interface. +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a listersexample3v1.TestTypeNamespaceLister for one namespace. type testTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*example3v1.TestType] } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*example3v1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*example3v1.TestType)) - }) - return ret, err -} +var _ listersexample3v1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) example3v1listers.TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +func (l *testTypeLister) TestTypes(namespace string) listersexample3v1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } -// testTypeNamespaceLister implements the example3v1listers.TestTypeNamespaceLister interface. +// testTypeNamespaceLister implements the listersexample3v1.TestTypeNamespaceLister +// interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string + kcplisters.ResourceIndexer[*example3v1.TestType] } -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*example3v1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*example3v1.TestType)) - }) - return ret, err -} +var _ listersexample3v1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*example3v1.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err +// NewTestTypeLister returns a new TestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) listersexample3v1.TestTypeLister { + return &testTypeLister{ + kcplisters.New[*example3v1.TestType](indexer, example3v1.Resource("testtype")), } - if !exists { - return nil, errors.NewNotFound(example3v1.Resource("testtypes"), name) +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexample3v1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + kcplisters.ResourceIndexer[*example3v1.TestType] +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexample3v1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), } - return obj.(*example3v1.TestType), nil } diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..48889bb6e --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go @@ -0,0 +1,92 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-lister-gen. DO NOT EDIT. + +package v1 + +import ( + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + listersexampledashedv1 "acme.corp/pkg/generated/listers/exampledashed/v1" + + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" +) + +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type ClusterTestTypeClusterLister interface { + // List lists all ClusterTestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) + // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) listersexampledashedv1.ClusterTestTypeLister + ClusterTestTypeClusterListerExpansion +} + +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. +type clusterTestTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*exampledashedv1.ClusterTestType] +} + +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + +// NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), + } +} + +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexampledashedv1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } +} + +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexampledashedv1.ClusterTestTypeNamespaceLister for one namespace. +type clusterTestTypeLister struct { + kcplisters.ResourceIndexer[*exampledashedv1.ClusterTestType] +} + +var _ listersexampledashedv1.ClusterTestTypeLister = new(clusterTestTypeLister) + +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) listersexampledashedv1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), + } +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexampledashedv1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + kcplisters.ResourceIndexer[*exampledashedv1.ClusterTestType] +} diff --git a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/expansion_generated.go similarity index 73% rename from examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype_expansion.go rename to examples/pkg/kcpexisting/clients/listers/exampledashed/v1/expansion_generated.go index 08fb95b1c..4baaf1768 100644 --- a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype_expansion.go +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,9 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. type ClusterTestTypeClusterListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go new file mode 100644 index 000000000..a2a49d73d --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go @@ -0,0 +1,116 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by cluster-lister-gen. DO NOT EDIT. + +package v1 + +import ( + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + listersexampledashedv1 "acme.corp/pkg/generated/listers/exampledashed/v1" + + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" +) + +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type TestTypeClusterLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) + // Cluster returns a lister that can list and get TestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) listersexampledashedv1.TestTypeLister + TestTypeClusterListerExpansion +} + +// testTypeClusterLister implements the TestTypeClusterLister interface. +type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*exampledashedv1.TestType] +} + +var _ TestTypeClusterLister = new(testTypeClusterLister) + +// NewTestTypeClusterLister returns a new TestTypeClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), + } +} + +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexampledashedv1.TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } +} + +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a listersexampledashedv1.TestTypeNamespaceLister for one namespace. +type testTypeLister struct { + kcplisters.ResourceIndexer[*exampledashedv1.TestType] +} + +var _ listersexampledashedv1.TestTypeLister = new(testTypeLister) + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeLister) TestTypes(namespace string) listersexampledashedv1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} + +// testTypeNamespaceLister implements the listersexampledashedv1.TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*exampledashedv1.TestType] +} + +var _ listersexampledashedv1.TestTypeNamespaceLister = new(testTypeNamespaceLister) + +// NewTestTypeLister returns a new TestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) listersexampledashedv1.TestTypeLister { + return &testTypeLister{ + kcplisters.New[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), + } +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexampledashedv1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + kcplisters.ResourceIndexer[*exampledashedv1.TestType] +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexampledashedv1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), + } +} diff --git a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype.go index 01298dafb..2e3cf89bc 100644 --- a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,82 +14,79 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + listersexistinginterfacesv1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - existinginterfacesv1listers "acme.corp/pkg/generated/listers/existinginterfaces/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*existinginterfacesv1.ClusterTestType, err error) // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) existinginterfacesv1listers.ClusterTestTypeLister + Cluster(clusterName logicalcluster.Name) listersexistinginterfacesv1.ClusterTestTypeLister ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*existinginterfacesv1.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*existinginterfacesv1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*existinginterfacesv1.ClusterTestType)) - }) - return ret, err +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) existinginterfacesv1listers.ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexistinginterfacesv1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// clusterTestTypeLister implements the existinginterfacesv1listers.ClusterTestTypeLister interface. +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexistinginterfacesv1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*existinginterfacesv1.ClusterTestType] } -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*existinginterfacesv1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*existinginterfacesv1.ClusterTestType)) - }) - return ret, err -} +var _ listersexistinginterfacesv1.ClusterTestTypeLister = new(clusterTestTypeLister) -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*existinginterfacesv1.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(existinginterfacesv1.Resource("clustertesttypes"), name) +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) listersexistinginterfacesv1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), } - return obj.(*existinginterfacesv1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexistinginterfacesv1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + kcplisters.ResourceIndexer[*existinginterfacesv1.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/expansion_generated.go similarity index 73% rename from examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype_expansion.go rename to examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/expansion_generated.go index 08fb95b1c..4baaf1768 100644 --- a/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype_expansion.go +++ b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,9 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. type ClusterTestTypeClusterListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype.go index 12b3eeb50..36a3fe684 100644 --- a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,103 +14,103 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + listersexistinginterfacesv1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - existinginterfacesv1listers "acme.corp/pkg/generated/listers/existinginterfaces/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. // All objects returned here must be treated as read-only. type TestTypeClusterLister interface { // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) // Cluster returns a lister that can list and get TestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) existinginterfacesv1listers.TestTypeLister + Cluster(clusterName logicalcluster.Name) listersexistinginterfacesv1.TestTypeLister TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*existinginterfacesv1.TestType] } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*existinginterfacesv1.TestType)) - }) - return ret, err +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) existinginterfacesv1listers.TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexistinginterfacesv1.TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// testTypeLister implements the existinginterfacesv1listers.TestTypeLister interface. +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a listersexistinginterfacesv1.TestTypeNamespaceLister for one namespace. type testTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*existinginterfacesv1.TestType] } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*existinginterfacesv1.TestType)) - }) - return ret, err -} +var _ listersexistinginterfacesv1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) existinginterfacesv1listers.TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +func (l *testTypeLister) TestTypes(namespace string) listersexistinginterfacesv1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } -// testTypeNamespaceLister implements the existinginterfacesv1listers.TestTypeNamespaceLister interface. +// testTypeNamespaceLister implements the listersexistinginterfacesv1.TestTypeNamespaceLister +// interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string + kcplisters.ResourceIndexer[*existinginterfacesv1.TestType] } -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*existinginterfacesv1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*existinginterfacesv1.TestType)) - }) - return ret, err -} +var _ listersexistinginterfacesv1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*existinginterfacesv1.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err +// NewTestTypeLister returns a new TestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) listersexistinginterfacesv1.TestTypeLister { + return &testTypeLister{ + kcplisters.New[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), } - if !exists { - return nil, errors.NewNotFound(existinginterfacesv1.Resource("testtypes"), name) +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexistinginterfacesv1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + kcplisters.ResourceIndexer[*existinginterfacesv1.TestType] +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexistinginterfacesv1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), } - return obj.(*existinginterfacesv1.TestType), nil } diff --git a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype.go index 107514938..9322631ae 100644 --- a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,82 +14,79 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + listerssecondexamplev1 "acme.corp/pkg/generated/listers/secondexample/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - secondexamplev1listers "acme.corp/pkg/generated/listers/secondexample/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// ClusterTestTypeClusterLister helps list ClusterTestTypes across all workspaces, +// or scope down to a ClusterTestTypeLister for one workspace. // All objects returned here must be treated as read-only. type ClusterTestTypeClusterLister interface { // List lists all ClusterTestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*secondexamplev1.ClusterTestType, err error) // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) secondexamplev1listers.ClusterTestTypeLister + Cluster(clusterName logicalcluster.Name) listerssecondexamplev1.ClusterTestTypeLister ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*secondexamplev1.ClusterTestType] } +var _ ClusterTestTypeClusterLister = new(clusterTestTypeClusterLister) + // NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { - return &clusterTestTypeClusterLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*secondexamplev1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*secondexamplev1.ClusterTestType)) - }) - return ret, err +func NewClusterTestTypeClusterLister(indexer cache.Indexer) ClusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) secondexamplev1listers.ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listerssecondexamplev1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// clusterTestTypeLister implements the secondexamplev1listers.ClusterTestTypeLister interface. +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace +// or scope down to a listerssecondexamplev1.ClusterTestTypeNamespaceLister for one namespace. type clusterTestTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*secondexamplev1.ClusterTestType] } -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*secondexamplev1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*secondexamplev1.ClusterTestType)) - }) - return ret, err -} +var _ listerssecondexamplev1.ClusterTestTypeLister = new(clusterTestTypeLister) -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*secondexamplev1.ClusterTestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(secondexamplev1.Resource("clustertesttypes"), name) +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeLister(indexer cache.Indexer) listerssecondexamplev1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), } - return obj.(*secondexamplev1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listerssecondexamplev1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + kcplisters.ResourceIndexer[*secondexamplev1.ClusterTestType] } diff --git a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/expansion_generated.go similarity index 73% rename from examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype_expansion.go rename to examples/pkg/kcpexisting/clients/listers/secondexample/v1/expansion_generated.go index 08fb95b1c..4baaf1768 100644 --- a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype_expansion.go +++ b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/expansion_generated.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,9 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to +// ClusterTestTypeClusterLister. type ClusterTestTypeClusterListerExpansion interface{} + +// TestTypeClusterListerExpansion allows custom methods to be added to +// TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype.go index 699c26089..7a0953936 100644 --- a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype.go @@ -1,6 +1,3 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - /* Copyright The KCP Authors. @@ -17,103 +14,103 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by kcp code-generator. DO NOT EDIT. +// Code generated by cluster-lister-gen. DO NOT EDIT. package v1 import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + listerssecondexamplev1 "acme.corp/pkg/generated/listers/secondexample/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/tools/cache" - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - secondexamplev1listers "acme.corp/pkg/generated/listers/secondexample/v1" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" + "github.com/kcp-dev/logicalcluster/v3" ) -// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// TestTypeClusterLister helps list TestTypes across all workspaces, +// or scope down to a TestTypeLister for one workspace. // All objects returned here must be treated as read-only. type TestTypeClusterLister interface { // List lists all TestTypes in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) // Cluster returns a lister that can list and get TestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) secondexamplev1listers.TestTypeLister + Cluster(clusterName logicalcluster.Name) listerssecondexamplev1.TestTypeLister TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { - indexer cache.Indexer + kcplisters.ResourceClusterIndexer[*secondexamplev1.TestType] } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index -func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*secondexamplev1.TestType)) - }) - return ret, err +func NewTestTypeClusterLister(indexer cache.Indexer) TestTypeClusterLister { + return &testTypeClusterLister{ + kcplisters.NewCluster[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), + } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) secondexamplev1listers.TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listerssecondexamplev1.TestTypeLister { + return &testTypeLister{ + l.ResourceClusterIndexer.WithCluster(clusterName), + } } -// testTypeLister implements the secondexamplev1listers.TestTypeLister interface. +// testTypeLister can list all TestTypes inside a workspace +// or scope down to a listerssecondexamplev1.TestTypeNamespaceLister for one namespace. type testTypeLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name + kcplisters.ResourceIndexer[*secondexamplev1.TestType] } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*secondexamplev1.TestType)) - }) - return ret, err -} +var _ listerssecondexamplev1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) secondexamplev1listers.TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +func (l *testTypeLister) TestTypes(namespace string) listerssecondexamplev1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + l.ResourceIndexer.WithNamespace(namespace), + } } -// testTypeNamespaceLister implements the secondexamplev1listers.TestTypeNamespaceLister interface. +// testTypeNamespaceLister implements the listerssecondexamplev1.TestTypeNamespaceLister +// interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string + kcplisters.ResourceIndexer[*secondexamplev1.TestType] } -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*secondexamplev1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*secondexamplev1.TestType)) - }) - return ret, err -} +var _ listerssecondexamplev1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*secondexamplev1.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err +// NewTestTypeLister returns a new TestTypeLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) listerssecondexamplev1.TestTypeLister { + return &testTypeLister{ + kcplisters.New[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), } - if !exists { - return nil, errors.NewNotFound(secondexamplev1.Resource("testtypes"), name) +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listerssecondexamplev1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + kcplisters.ResourceIndexer[*secondexamplev1.TestType] +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listerssecondexamplev1.TestTypeLister { + return &testTypeLister{ + l.ResourceIndexer.WithNamespace(namespace), } - return obj.(*secondexamplev1.TestType), nil } diff --git a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype_expansion.go b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype_expansion.go deleted file mode 100644 index 835da85d6..000000000 --- a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype_expansion.go +++ /dev/null @@ -1,25 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by kcp code-generator. DO NOT EDIT. - -package v1 - -// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. -type TestTypeClusterListerExpansion interface{} diff --git a/examples/test/kcp/controller_test.go b/examples/test/kcp/controller_test.go new file mode 100644 index 000000000..129b9af91 --- /dev/null +++ b/examples/test/kcp/controller_test.go @@ -0,0 +1,101 @@ +/* +Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package kcp + +import ( + "context" + "testing" + "time" + + examplev1 "acme.corp/pkg/apis/example/v1" + "acme.corp/pkg/kcp/clients/clientset/versioned/fake" + informers "acme.corp/pkg/kcp/clients/informers/externalversions" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" + + clienttesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" +) + +// TestFakeClient demonstrates how to use a fake client with SharedInformerFactory in tests. +func TestFakeClient(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + watcherStarted := make(chan struct{}) + // Create the fake client. + client := fake.NewSimpleClientset() + // A catch-all watch reactor that allows us to inject the watcherStarted channel. + client.PrependWatchReactor("*", func(action clienttesting.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := client.Tracker().Watch(gvr, ns) + if err != nil { + return false, nil, err + } + close(watcherStarted) + return true, watch, nil + }) + + // We will create an informer that writes added testTypes to a channel. + testTypes := make(chan *examplev1.TestType, 1) + informerFactory := informers.NewSharedInformerFactory(client, 0) + testTypeInformer := informerFactory.Example().V1().TestTypes().Informer() + if _, err := testTypeInformer.AddEventHandler(&cache.ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { + testType := obj.(*examplev1.TestType) + t.Logf("testType added: %s/%s", testType.Namespace, testType.Name) + testTypes <- testType + }, + }); err != nil { + t.Fatalf("Failed to add event handler: %v", err) + } + + // Make sure informers are running. + informerFactory.Cluster(logicalcluster.Name("root")).Start(ctx.Done()) + + // This is not required in tests, but it serves as a proof-of-concept by + // ensuring that the informer goroutine have warmed up and called List before + // we send any events to it. + cache.WaitForCacheSync(ctx.Done(), testTypeInformer.HasSynced) + + // The fake client doesn't support resource version. Any writes to the client + // after the informer's initial LIST and before the informer establishing the + // watcher will be missed by the informer. Therefore we wait until the watcher + // starts. + // Note that the fake client isn't designed to work with informer. It + // doesn't support resource version. It's encouraged to use a real client + // in an integration/E2E test if you need to test complex behavior with + // informer/controllers. + <-watcherStarted + // Inject an event into the fake client. + p := &examplev1.TestType{ObjectMeta: metav1.ObjectMeta{Name: "my-testobj"}} + _, err := client.ExampleV1().TestTypes().Cluster(logicalcluster.NewPath("root")).Namespace("test-ns").Create(ctx, p, metav1.CreateOptions{}) + if err != nil { + t.Fatalf("error injecting testType add: %v", err) + } + + select { + case testType := <-testTypes: + t.Logf("Got testType from channel: %s/%s", testType.Namespace, testType.Name) + case <-time.After(wait.ForeverTestTimeout): + t.Error("Informer did not get the added testType") + } +} diff --git a/examples/test/kcpexisting/controller_test.go b/examples/test/kcpexisting/controller_test.go new file mode 100644 index 000000000..b06f4f2db --- /dev/null +++ b/examples/test/kcpexisting/controller_test.go @@ -0,0 +1,101 @@ +/* +Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package kcpexisting + +import ( + "context" + "testing" + "time" + + examplev1 "acme.corp/pkg/apis/example/v1" + "acme.corp/pkg/kcpexisting/clients/clientset/versioned/fake" + informers "acme.corp/pkg/kcpexisting/clients/informers/externalversions" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" + + clienttesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "github.com/kcp-dev/logicalcluster/v3" +) + +// TestFakeClient demonstrates how to use a fake client with SharedInformerFactory in tests. +func TestFakeClient(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + watcherStarted := make(chan struct{}) + // Create the fake client. + client := fake.NewSimpleClientset() + // A catch-all watch reactor that allows us to inject the watcherStarted channel. + client.PrependWatchReactor("*", func(action clienttesting.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := client.Tracker().Watch(gvr, ns) + if err != nil { + return false, nil, err + } + close(watcherStarted) + return true, watch, nil + }) + + // We will create an informer that writes added testTypes to a channel. + testTypes := make(chan *examplev1.TestType, 1) + informerFactory := informers.NewSharedInformerFactory(client, 0) + testTypeInformer := informerFactory.Example().V1().TestTypes().Informer() + if _, err := testTypeInformer.AddEventHandler(&cache.ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { + testType := obj.(*examplev1.TestType) + t.Logf("testType added: %s/%s", testType.Namespace, testType.Name) + testTypes <- testType + }, + }); err != nil { + t.Fatalf("Failed to add event handler: %v", err) + } + + // Make sure informers are running. + informerFactory.Cluster(logicalcluster.Name("root")).Start(ctx.Done()) + + // This is not required in tests, but it serves as a proof-of-concept by + // ensuring that the informer goroutine have warmed up and called List before + // we send any events to it. + cache.WaitForCacheSync(ctx.Done(), testTypeInformer.HasSynced) + + // The fake client doesn't support resource version. Any writes to the client + // after the informer's initial LIST and before the informer establishing the + // watcher will be missed by the informer. Therefore we wait until the watcher + // starts. + // Note that the fake client isn't designed to work with informer. It + // doesn't support resource version. It's encouraged to use a real client + // in an integration/E2E test if you need to test complex behavior with + // informer/controllers. + <-watcherStarted + // Inject an event into the fake client. + p := &examplev1.TestType{ObjectMeta: metav1.ObjectMeta{Name: "my-testobj"}} + _, err := client.ExampleV1().TestTypes().Cluster(logicalcluster.NewPath("root")).Namespace("test-ns").Create(ctx, p, metav1.CreateOptions{}) + if err != nil { + t.Fatalf("error injecting testType add: %v", err) + } + + select { + case testType := <-testTypes: + t.Logf("Got testType from channel: %s/%s", testType.Namespace, testType.Name) + case <-time.After(wait.ForeverTestTimeout): + t.Error("Informer did not get the added testType") + } +} diff --git a/examples/test/singlecluster/controller_test.go b/examples/test/singlecluster/controller_test.go new file mode 100644 index 000000000..b9e37140f --- /dev/null +++ b/examples/test/singlecluster/controller_test.go @@ -0,0 +1,99 @@ +/* +Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package singlecluster + +import ( + "context" + "testing" + "time" + + examplev1 "acme.corp/pkg/apis/example/v1" + "acme.corp/pkg/generated/clientset/versioned/fake" + informers "acme.corp/pkg/generated/informers/externalversions" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/apimachinery/pkg/watch" + clienttesting "k8s.io/client-go/testing" + "k8s.io/client-go/tools/cache" +) + +// TestFakeClient demonstrates how to use a fake client with SharedInformerFactory in tests. +func TestFakeClient(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + watcherStarted := make(chan struct{}) + // Create the fake client. + client := fake.NewSimpleClientset() + // A catch-all watch reactor that allows us to inject the watcherStarted channel. + client.PrependWatchReactor("*", func(action clienttesting.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := client.Tracker().Watch(gvr, ns) + if err != nil { + return false, nil, err + } + close(watcherStarted) + return true, watch, nil + }) + + // We will create an informer that writes added testTypes to a channel. + testTypes := make(chan *examplev1.TestType, 1) + informerFactory := informers.NewSharedInformerFactory(client, 0) + testTypeInformer := informerFactory.Example().V1().TestTypes().Informer() + if _, err := testTypeInformer.AddEventHandler(&cache.ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { + testType := obj.(*examplev1.TestType) + t.Logf("testType added: %s/%s", testType.Namespace, testType.Name) + testTypes <- testType + }, + }); err != nil { + t.Fatalf("Failed to add event handler: %v", err) + } + + // Make sure informers are running. + informerFactory.Start(ctx.Done()) + + // This is not required in tests, but it serves as a proof-of-concept by + // ensuring that the informer goroutine have warmed up and called List before + // we send any events to it. + cache.WaitForCacheSync(ctx.Done(), testTypeInformer.HasSynced) + + // The fake client doesn't support resource version. Any writes to the client + // after the informer's initial LIST and before the informer establishing the + // watcher will be missed by the informer. Therefore we wait until the watcher + // starts. + // Note that the fake client isn't designed to work with informer. It + // doesn't support resource version. It's encouraged to use a real client + // in an integration/E2E test if you need to test complex behavior with + // informer/controllers. + <-watcherStarted + // Inject an event into the fake client. + p := &examplev1.TestType{ObjectMeta: metav1.ObjectMeta{Name: "my-testobj"}} + _, err := client.ExampleV1().TestTypes("test-ns").Create(ctx, p, metav1.CreateOptions{}) + if err != nil { + t.Fatalf("error injecting testType add: %v", err) + } + + select { + case testType := <-testTypes: + t.Logf("Got testType from channel: %s/%s", testType.Namespace, testType.Name) + case <-time.After(wait.ForeverTestTimeout): + t.Error("Informer did not get the added testType") + } +} diff --git a/go.mod b/go.mod index f583be6b9..af8f42c41 100644 --- a/go.mod +++ b/go.mod @@ -1,35 +1,18 @@ -module github.com/kcp-dev/code-generator/v2 +module github.com/kcp-dev/code-generator/v3 -go 1.19 +go 1.24.0 require ( - github.com/onsi/ginkgo v1.16.5 - github.com/onsi/gomega v1.23.0 - github.com/spf13/cobra v1.4.0 - github.com/spf13/pflag v1.0.5 - golang.org/x/tools v0.2.0 - k8s.io/apimachinery v0.26.3 - k8s.io/code-generator v0.26.3 - k8s.io/gengo v0.0.0-20220902162205-c0856e24416d - k8s.io/klog/v2 v2.80.1 - sigs.k8s.io/controller-tools v0.8.0 + github.com/spf13/pflag v1.0.6 + golang.org/x/text v0.25.0 + k8s.io/code-generator v0.33.3 + k8s.io/gengo/v2 v2.0.0-20250513215321-e3bc6f1e78b4 + k8s.io/klog/v2 v2.130.1 ) require ( - github.com/fatih/color v1.12.0 // indirect - github.com/fsnotify/fsnotify v1.4.9 // indirect - github.com/go-logr/logr v1.2.3 // indirect - github.com/google/go-cmp v0.5.9 // indirect - github.com/inconshreveable/mousetrap v1.0.0 // indirect - github.com/mattn/go-colorable v0.1.8 // indirect - github.com/mattn/go-isatty v0.0.12 // indirect - github.com/nxadm/tail v1.4.8 // indirect - golang.org/x/mod v0.6.0 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect - sigs.k8s.io/yaml v1.3.0 // indirect + github.com/go-logr/logr v1.4.2 // indirect + golang.org/x/mod v0.24.0 // indirect + golang.org/x/sync v0.14.0 // indirect + golang.org/x/tools v0.33.0 // indirect ) diff --git a/go.sum b/go.sum index c9c56e31a..b15ffb151 100644 --- a/go.sum +++ b/go.sum @@ -1,143 +1,20 @@ -github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc= -github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= -github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= -github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= -github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys= -github.com/onsi/gomega v1.23.0/go.mod h1:Z/NWtiqwBrwUt4/2loMmHL63EDLnYHmVbuBpDr2vQAg= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q= -github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I= -golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200505023115-26f46d2f7ef8/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE= -golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/apimachinery v0.26.3 h1:dQx6PNETJ7nODU3XPtrwkfuubs6w7sX0M8n61zHIV/k= -k8s.io/apimachinery v0.26.3/go.mod h1:ats7nN1LExKHvJ9TmwootT00Yz05MuYqPXEXaVeOy5I= -k8s.io/code-generator v0.26.3 h1:DNYPsWoeFwmg4qFg97Z1cHSSv7KSG10mAEIFoZGTQM8= -k8s.io/code-generator v0.26.3/go.mod h1:ryaiIKwfxEJEaywEzx3dhWOydpVctKYbqLajJf0O8dI= -k8s.io/gengo v0.0.0-20220902162205-c0856e24416d h1:U9tB195lKdzwqicbJvyJeOXV7Klv+wNAWENRnXEGi08= -k8s.io/gengo v0.0.0-20220902162205-c0856e24416d/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= -k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= -k8s.io/klog/v2 v2.80.1 h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4= -k8s.io/klog/v2 v2.80.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= -sigs.k8s.io/controller-tools v0.8.0 h1:uUkfTGEwrguqYYfcI2RRGUnC8mYdCFDqfwPKUcNJh1o= -sigs.k8s.io/controller-tools v0.8.0/go.mod h1:qE2DXhVOiEq5ijmINcFbqi9GZrrUjzB1TuJU0xa6eoY= -sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= +github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= +golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= +golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= +golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= +golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= +golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc= +golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI= +k8s.io/code-generator v0.33.3 h1:6+34LhYkIuQ/yn/E3qlpVqjQaP8smzCu4NE1A8b0LWs= +k8s.io/code-generator v0.33.3/go.mod h1:6Y02+HQJYgNphv9z3wJB5w+sjYDIEBQW7sh62PkufvA= +k8s.io/gengo/v2 v2.0.0-20250513215321-e3bc6f1e78b4 h1:iicENHE63xPBlGQeany8LqrH40Wh/48QhMRI/mGVsqA= +k8s.io/gengo/v2 v2.0.0-20250513215321-e3bc6f1e78b4/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU= +k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= +k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= diff --git a/hack/boilerplate/boilerplate.go.txt b/hack/boilerplate/boilerplate.go.txt index f6d7ed844..01213edc3 100644 --- a/hack/boilerplate/boilerplate.go.txt +++ b/hack/boilerplate/boilerplate.go.txt @@ -1,5 +1,6 @@ /* Copyright YEAR The KCP Authors. +Copyright 2025 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/hack/boilerplate/examples/boilerplate.generatego.txt b/hack/boilerplate/examples/boilerplate.generatego.txt new file mode 100644 index 000000000..2d3aa5143 --- /dev/null +++ b/hack/boilerplate/examples/boilerplate.generatego.txt @@ -0,0 +1,16 @@ +/* +Copyright The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + diff --git a/hack/boilerplate/examples/boilerplate.go.txt b/hack/boilerplate/examples/boilerplate.go.txt new file mode 100644 index 000000000..f6d7ed844 --- /dev/null +++ b/hack/boilerplate/examples/boilerplate.go.txt @@ -0,0 +1,16 @@ +/* +Copyright YEAR The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + diff --git a/hack/go-install.sh b/hack/go-install.sh deleted file mode 100755 index b88e1d8fa..000000000 --- a/hack/go-install.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2021 The KCP Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Originally copied from -# https://github.com/kubernetes-sigs/cluster-api-provider-gcp/blob/c26a68b23e9317323d5d37660fe9d29b3d2ff40c/scripts/go_install.sh - -set -o errexit -set -o nounset -set -o pipefail - -if [ -z "${1}" ]; then - echo "must provide module as first parameter" - exit 1 -fi - -if [ -z "${2}" ]; then - echo "must provide binary name as second parameter" - exit 1 -fi - -if [ -z "${3}" ]; then - echo "must provide version as third parameter" - exit 1 -fi - -if [ -z "${GOBIN}" ]; then - echo "GOBIN is not set. Must set GOBIN to install the bin in a specified directory." - exit 1 -fi - -mkdir -p "${GOBIN}" - -tmp_dir=$(mktemp -d -t goinstall_XXXXXXXXXX) -function clean { - rm -rf "${tmp_dir}" -} -trap clean EXIT - -rm "${GOBIN}/${2}"* > /dev/null 2>&1 || true - -cd "${tmp_dir}" - -# create a new module in the tmp directory -go mod init fake/mod - -# install the golang module specified as the first argument -go install -tags tools "${1}@${3}" -mv "${GOBIN}/${2}" "${GOBIN}/${2}-${3}" -ln -sf "${GOBIN}/${2}-${3}" "${GOBIN}/${2}" \ No newline at end of file diff --git a/hack/tools.go b/hack/tools.go new file mode 100644 index 000000000..1b5952ffa --- /dev/null +++ b/hack/tools.go @@ -0,0 +1,26 @@ +//go:build tools +// +build tools + +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package tools + +// This package imports things required by this repository, to force `go mod` to see them as dependencies +import ( + _ "k8s.io/code-generator/cmd/client-gen" +) diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 55b4b1a52..9fb89534c 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright 2022 The KCP Authors. +# Copyright 2025 The KCP Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,68 +20,70 @@ set -o pipefail set -o xtrace if [[ -z "${MAKELEVEL:-}" ]]; then - echo 'You must invoke this script via make' - exit 1 + echo 'You must invoke this script via make' + exit 1 fi -pushd ./examples +SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; go list -f '{{.Dir}}' -m k8s.io/code-generator)} -# Generate deepcopy functions -${CONTROLLER_GEN} object paths=./pkg/apis/... +source "${CODEGEN_PKG}/kube_codegen.sh" +source cluster_codegen.sh -# Generate standard clientset -${KUBE_CLIENT_GEN} \ - --clientset-name versioned \ - --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ - --input-base acme.corp/pkg/apis \ - --input example/v1 \ - --input example/v1alpha1 \ - --input example/v1beta1 \ - --input example/v2 \ - --input example3/v1 \ - --input secondexample/v1 \ - --input existinginterfaces/v1 \ - --output-base . \ - --output-package acme.corp/pkg/generated/clientset \ - --trim-path-prefix acme.corp +pushd ./examples -${KUBE_APPLYCONFIGURATION_GEN} \ - --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ - --input-dirs acme.corp/pkg/apis/example/v1,acme.corp/pkg/apis/example/v1alpha1,acme.corp/pkg/apis/example/v1beta1,acme.corp/pkg/apis/example/v2,acme.corp/pkg/apis/example3/v1,acme.corp/pkg/apis/secondexample/v1,acme.corp/pkg/apis/existinginterfaces/v1 \ - --output-base . \ - --output-package acme.corp/pkg/generated/applyconfigurations \ - --trim-path-prefix acme.corp +# Generate deepcopy functions +kube::codegen::gen_helpers \ + --boilerplate ./../hack/boilerplate/examples/boilerplate.generatego.txt \ + ./pkg/apis -${KUBE_LISTER_GEN} \ - --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ - --input-dirs acme.corp/pkg/apis/example/v1,acme.corp/pkg/apis/example/v1alpha1,acme.corp/pkg/apis/example/v1beta1,acme.corp/pkg/apis/example/v2,acme.corp/pkg/apis/example3/v1,acme.corp/pkg/apis/secondexample/v1,acme.corp/pkg/apis/existinginterfaces/v1 \ - --output-base . \ - --output-package acme.corp/pkg/generated/listers \ - --trim-path-prefix acme.corp +# Generate standard clientset, listers and informers +rm -rf pkg/generated +mkdir -p pkg/generated/{clientset,applyconfigurations,listers,informers} -${KUBE_INFORMER_GEN} \ - --versioned-clientset-package acme.corp/pkg/generated/clientset/versioned \ - --listers-package acme.corp/pkg/generated/listers \ - --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ - --input-dirs acme.corp/pkg/apis/example/v1,acme.corp/pkg/apis/example/v1alpha1,acme.corp/pkg/apis/example/v1beta1,acme.corp/pkg/apis/example/v2,acme.corp/pkg/apis/example3/v1,acme.corp/pkg/apis/secondexample/v1,acme.corp/pkg/apis/existinginterfaces/v1 \ - --output-base . \ - --output-package acme.corp/pkg/generated/informers \ - --trim-path-prefix acme.corp +kube::codegen::gen_client \ + --boilerplate ./../hack/boilerplate/examples/boilerplate.generatego.txt \ + --output-dir pkg/generated \ + --output-pkg acme.corp/pkg/generated \ + --with-applyconfig \ + --applyconfig-name applyconfigurations \ + --with-watch \ + ./pkg/apis # Generate cluster-aware clients, informers and listers using generated single-cluster code -./../bin/code-generator \ - "client:standalone=true,outputPackagePath=acme.corp/pkg/kcpexisting/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterApplyConfigurationsPackagePath=acme.corp/pkg/generated/applyconfigurations,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ - "lister:apiPackagePath=acme.corp/pkg/apis,singleClusterListerPackagePath=acme.corp/pkg/generated/listers,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ - "informer:standalone=true,outputPackagePath=acme.corp/pkg/kcpexisting/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterListerPackagePath=acme.corp/pkg/generated/listers,singleClusterInformerPackagePath=acme.corp/pkg/generated/informers/externalversions,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ - "paths=./pkg/apis/..." \ - "output:dir=./pkg/kcpexisting/clients" +rm -rf pkg/kcpexisting +mkdir -p pkg/kcpexisting/clients/{clientset/versioned,listers,informers/externalversions} + +cluster::codegen::gen_client \ + --boilerplate ../hack/boilerplate/examples/boilerplate.generatego.txt \ + --output-dir pkg/kcpexisting/clients \ + --output-pkg acme.corp/pkg/kcpexisting/clients \ + --versioned-clientset-dir pkg/kcpexisting/clients/clientset/versioned \ + --versioned-clientset-pkg acme.corp/pkg/kcpexisting/clients/clientset/versioned \ + --informers-dir pkg/kcpexisting/clients/informers/externalversions \ + --informers-pkg acme.corp/pkg/kcpexisting/clients/informers/externalversions \ + --with-watch \ + --single-cluster-versioned-clientset-pkg acme.corp/pkg/generated/clientset/versioned \ + --single-cluster-applyconfigurations-pkg acme.corp/pkg/generated/applyconfigurations \ + --single-cluster-listers-pkg acme.corp/pkg/generated/listers \ + --single-cluster-informers-pkg acme.corp/pkg/generated/informers/externalversions \ + pkg/apis # Generate cluster-aware clients, informers and listers assuming no single-cluster listers or informers -./../bin/code-generator \ - "client:standalone=true,outputPackagePath=acme.corp/pkg/kcp/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterApplyConfigurationsPackagePath=acme.corp/pkg/generated/applyconfigurations,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ - "lister:apiPackagePath=acme.corp/pkg/apis,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ - "informer:standalone=true,outputPackagePath=acme.corp/pkg/kcp/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ - "paths=./pkg/apis/..." \ - "output:dir=./pkg/kcp/clients" +rm -rf pkg/kcp +mkdir -p pkg/kcp/clients/{clientset/versioned,listers,informers/externalversions} + +cluster::codegen::gen_client \ + --boilerplate ../hack/boilerplate/examples/boilerplate.generatego.txt \ + --output-dir pkg/kcp/clients \ + --output-pkg acme.corp/pkg/kcp/clients \ + --versioned-clientset-dir pkg/kcp/clients/clientset/versioned \ + --versioned-clientset-pkg acme.corp/pkg/kcp/clients/clientset/versioned \ + --informers-dir pkg/kcp/clients/informers/externalversions \ + --informers-pkg acme.corp/pkg/kcp/clients/informers/externalversions \ + --with-watch \ + --single-cluster-versioned-clientset-pkg acme.corp/pkg/generated/clientset/versioned \ + --single-cluster-applyconfigurations-pkg acme.corp/pkg/generated/applyconfigurations \ + pkg/apis -popd \ No newline at end of file +popd diff --git a/main.go b/main.go deleted file mode 100644 index d8e9d7ed3..000000000 --- a/main.go +++ /dev/null @@ -1,258 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import ( - "encoding/json" - "fmt" - "io" - "os" - "strings" - - "github.com/spf13/cobra" - - "sigs.k8s.io/controller-tools/pkg/genall" - "sigs.k8s.io/controller-tools/pkg/genall/help" - prettyhelp "sigs.k8s.io/controller-tools/pkg/genall/help/pretty" - "sigs.k8s.io/controller-tools/pkg/markers" - "sigs.k8s.io/controller-tools/pkg/version" - - "github.com/kcp-dev/code-generator/v2/pkg/generators/clientgen" - "github.com/kcp-dev/code-generator/v2/pkg/generators/informergen" - "github.com/kcp-dev/code-generator/v2/pkg/generators/listergen" -) - -// Options are specified to controller-gen by turning generators and output rules into -// markers, and then parsing them using the standard registry logic (without the "+"). -// Each marker and output rule should thus be usable as a marker target. - -var ( - // allGenerators maintains the list of all known generators, giving - // them names for use on the command line. - // each turns into a command line option, - // and has options for output forms. - allGenerators = map[string]genall.Generator{ - "client": clientgen.Generator{}, - "lister": listergen.Generator{}, - "informer": informergen.Generator{}, - } - - // allOutputRules defines the list of all known output rules, giving - // them names for use on the command line. - // Each output rule turns into two command line options: - // - output::
(per-generator output) - // - output: (default output) - allOutputRules = map[string]genall.OutputRule{ - "dir": genall.OutputToDirectory(""), - "none": genall.OutputToNothing, - "stdout": genall.OutputToStdout, - "artifacts": genall.OutputArtifacts{}, - } - - // optionsRegistry contains all the marker definitions used to process command line options - optionsRegistry = &markers.Registry{} -) - -func init() { - for genName, gen := range allGenerators { - // make the generator options marker itself - defn := markers.Must(markers.MakeDefinition(genName, markers.DescribesPackage, gen)) - if err := optionsRegistry.Register(defn); err != nil { - panic(err) - } - if helpGiver, hasHelp := gen.(genall.HasHelp); hasHelp { - if help := helpGiver.Help(); help != nil { - optionsRegistry.AddHelp(defn, help) - } - } - - // make per-generation output rule markers - for ruleName, rule := range allOutputRules { - ruleMarker := markers.Must(markers.MakeDefinition(fmt.Sprintf("output:%s:%s", genName, ruleName), markers.DescribesPackage, rule)) - if err := optionsRegistry.Register(ruleMarker); err != nil { - panic(err) - } - if helpGiver, hasHelp := rule.(genall.HasHelp); hasHelp { - if help := helpGiver.Help(); help != nil { - optionsRegistry.AddHelp(ruleMarker, help) - } - } - } - } - - // make "default output" output rule markers - for ruleName, rule := range allOutputRules { - ruleMarker := markers.Must(markers.MakeDefinition("output:"+ruleName, markers.DescribesPackage, rule)) - if err := optionsRegistry.Register(ruleMarker); err != nil { - panic(err) - } - if helpGiver, hasHelp := rule.(genall.HasHelp); hasHelp { - if help := helpGiver.Help(); help != nil { - optionsRegistry.AddHelp(ruleMarker, help) - } - } - } - - // add in the common options markers - if err := genall.RegisterOptionsMarkers(optionsRegistry); err != nil { - panic(err) - } -} - -// noUsageError suppresses usage printing when it occurs -// (since cobra doesn't provide a good way to avoid printing -// out usage in only certain situations). -type noUsageError struct{ error } - -func main() { - helpLevel := 0 - whichLevel := 0 - showVersion := false - - cmd := &cobra.Command{ - Use: "code-generator", - Short: "Generate Cluster-Aware Kubernetes API clients, informers and listers.", - Long: "Generate Cluster-Aware Kubernetes API libraries.", - Example: ` # Generate listers for all types under apis/, - # outputting them to /tmp/clients - code-generator lister:apiPackagePath=acme.corp/pkg/apis,singleClusterListerPackagePath=acme.corp/pkg/generated/listers,headerFile=./../hack/boilerplate/boilerplate.go.txt paths=./apis/... output:dir=/tmp - - # Run all the generators for a given project - code-generator \ - "client:name=versioned,outputPackagePath=acme.corp/pkg/kcp,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,headerFile=./../hack/boilerplate/boilerplate.go.txt,year=2022" \ - "lister:apiPackagePath=acme.corp/pkg/apis,singleClusterListerPackagePath=acme.corp/pkg/generated/listers,headerFile=./../hack/boilerplate/boilerplate.go.txt,year=2022" \ - "informer:outputPackagePath=acme.corp/pkg/kcp,apiPackagePath=acme.corp/pkg/apis,headerFile=./../hack/boilerplate/boilerplate.go.txt,year=2022" \ - "paths=./pkg/apis/..." \ - "output:dir=./pkg/kcpclients - - # Explain the markers for generating listers, and their arguments - code-generator lister -ww -`, - RunE: func(c *cobra.Command, rawOpts []string) error { - // print version if asked for it - if showVersion { - version.Print() - return nil - } - - // print the help if we asked for it (since we've got a different help flag :-/), then bail - if helpLevel > 0 { - return c.Usage() - } - - // print the marker docs if we asked for them, then bail - if whichLevel > 0 { - return printMarkerDocs(c, rawOpts, whichLevel) - } - - // otherwise, set up the runtime for actually running the generators - rt, err := genall.FromOptions(optionsRegistry, rawOpts) - if err != nil { - return err - } - if len(rt.Generators) == 0 { - return fmt.Errorf("no generators specified") - } - - if hadErrs := rt.Run(); hadErrs { - // don't obscure the actual error with a bunch of usage - return noUsageError{fmt.Errorf("not all generators ran successfully")} - } - return nil - }, - SilenceUsage: true, // silence the usage, then print it out ourselves if it wasn't suppressed - } - cmd.Flags().CountVarP(&whichLevel, "which-markers", "w", "print out all markers available with the requested generators\n(up to -www for the most detailed output, or -wwww for json output)") - cmd.Flags().CountVarP(&helpLevel, "detailed-help", "h", "print out more detailed help\n(up to -hhh for the most detailed output, or -hhhh for json output)") - cmd.Flags().BoolVar(&showVersion, "version", false, "show version") - cmd.Flags().Bool("help", false, "print out usage and a summary of options") - oldUsage := cmd.UsageFunc() - cmd.SetUsageFunc(func(c *cobra.Command) error { - if err := oldUsage(c); err != nil { - return err - } - if helpLevel == 0 { - helpLevel = summaryHelp - } - fmt.Fprintf(c.OutOrStderr(), "\n\nOptions\n\n") - return helpForLevels(c.OutOrStdout(), c.OutOrStderr(), helpLevel, optionsRegistry, help.SortByOption) - }) - - if err := cmd.Execute(); err != nil { - if _, noUsage := err.(noUsageError); !noUsage { - // print the usage unless we suppressed it - if err := cmd.Usage(); err != nil { - panic(err) - } - } - fmt.Fprintf(cmd.OutOrStderr(), "run `%[1]s %[2]s -w` to see all available markers, or `%[1]s %[2]s -h` for usage\n", cmd.CalledAs(), strings.Join(os.Args[1:], " ")) - os.Exit(1) - } -} - -// printMarkerDocs prints out marker help for the given generators specified in -// the rawOptions, at the given level. -func printMarkerDocs(c *cobra.Command, rawOptions []string, whichLevel int) error { - // just grab a registry so we don't lag while trying to load roots - // (like we'd do if we just constructed the full runtime). - reg, err := genall.RegistryFromOptions(optionsRegistry, rawOptions) - if err != nil { - return err - } - - return helpForLevels(c.OutOrStdout(), c.OutOrStderr(), whichLevel, reg, help.SortByCategory) -} - -func helpForLevels(mainOut io.Writer, errOut io.Writer, whichLevel int, reg *markers.Registry, sorter help.SortGroup) error { - helpInfo := help.ByCategory(reg, sorter) - switch whichLevel { - case jsonHelp: - if err := json.NewEncoder(mainOut).Encode(helpInfo); err != nil { - return err - } - case detailedHelp, fullHelp: - fullDetail := whichLevel == fullHelp - for _, cat := range helpInfo { - if cat.Category == "" { - continue - } - contents := prettyhelp.MarkersDetails(fullDetail, cat.Category, cat.Markers) - if err := contents.WriteTo(errOut); err != nil { - return err - } - } - case summaryHelp: - for _, cat := range helpInfo { - if cat.Category == "" { - continue - } - contents := prettyhelp.MarkersSummary(cat.Category, cat.Markers) - if err := contents.WriteTo(errOut); err != nil { - return err - } - } - } - return nil -} - -const ( - _ = iota - summaryHelp - detailedHelp - fullHelp - jsonHelp -) diff --git a/pkg/flag/flags.go b/pkg/flag/flags.go deleted file mode 100644 index e6f2a096a..000000000 --- a/pkg/flag/flags.go +++ /dev/null @@ -1,80 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package flag - -import ( - "errors" - - "github.com/spf13/pflag" -) - -// Flags - Options accepted by generator -type Flags struct { - // OutputDir is where the generated code is to be written to. - OutputDir string - // InputDir is path to the input APIs (types.go) - InputDir string - // ClientsetAPIPath is the path to where client sets are scaffolded by codegen. - ClientsetAPIPath string - // InformersPackage is the path to where informers are scaffolded by codegen. Only used for generating upstream-interface compatible informers. - InformersPackage string - // InformersInternalInterfacesPackage is the path to where the interfaces for informers are scaffolded by codegen. Only used for generating upstream-interface compatible informers. - InformersInternalInterfacesPackage string - // ListersPackage is the path to where listers are scaffolded by codegen. Only used for generating upstream-interface compatible listers. - ListersPackage string - // optional package of apply configurations, generated by applyconfiguration-gen, that are required to generate Apply functions for each type in the clientset. - // By default Apply functions are not generated. If this is provided, then wrappers for Apply functions will be generated. - ApplyConfigurationPackage string - // List of group versions for which the wrappers are to be generated. - GroupVersions []string - // Path to the headerfile. - GoHeaderFilePath string -} - -func (f *Flags) AddTo(flagset *pflag.FlagSet) { - // TODO: Figure out if its worth defaulting it to pkg/api/... - flagset.StringVar(&f.InputDir, "input-dir", "", "Input directory where types are defined. It is assumed that 'types.go' is present inside /pkg/apis.") - flagset.StringVar(&f.OutputDir, "output-dir", "output", "Output directory where wrapped clients will be generated. The wrappers will be present in '/generated' path.") - - flagset.StringVar(&f.ClientsetAPIPath, "clientset-api-path", "/apis", "package path where clients are generated.") - flagset.StringVar(&f.InformersPackage, "informers-package", "", "package path where informers are generated.") - flagset.StringVar(&f.InformersInternalInterfacesPackage, "informers-internal-interfaces-package", "", "package path where informer internal interfaces are generated.") - flagset.StringVar(&f.ListersPackage, "listers-package", "", "package path where listers are generated.") - flagset.StringVar(&f.ApplyConfigurationPackage, "apply-configuration-package", "", "optional package of apply configurations, generated by applyconfiguration-gen, that are required to generate Apply functions for each type in the clientset. If this is provided, then wrappers for Apply functions will be generated.") - flagset.StringArrayVar(&f.GroupVersions, "group-versions", []string{}, "specify group versions for the clients.") - flagset.StringVar(&f.GoHeaderFilePath, "go-header-file", "", "path to headerfile for the generated text.") -} - -// ValidateFlags checks if the inputs provided through flags are valid and -// if so, sets defaults. -// TODO: Remove this and bind options to all the generators, see -// https://github.com/kcp-dev/code-generator/issues/4 -func ValidateFlags(f Flags) error { - if f.InputDir == "" { - return errors.New("input path to API definition is required.") - } - - if f.ClientsetAPIPath == "" { - return errors.New("specifying client API path is required currently.") - } - - if len(f.GroupVersions) == 0 { - return errors.New("list of group versions for which the clients are to be generated is required.") - } - - return nil -} diff --git a/pkg/flag/flags_test.go b/pkg/flag/flags_test.go deleted file mode 100644 index 6617851e0..000000000 --- a/pkg/flag/flags_test.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package flag - -import ( - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -// TODO: Rewrite into generic Go Testing format -func TestMetadata(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Test flags suite") -} - -var _ = Describe("Test flag inputs", func() { - var ( - f Flags - ) - - BeforeEach(func() { - f = Flags{} - f.InputDir = "test" - f.ClientsetAPIPath = "testdata/" - f.GroupVersions = []string{"apps:v1"} - }) - - It("Should not error when input in set right", func() { - Expect(ValidateFlags(f)).NotTo(HaveOccurred()) - }) - It("verify input path error", func() { - f.InputDir = "" - err := ValidateFlags(f) - Expect(err.Error()).To(ContainSubstring("input path to API definition is required.")) - }) - - It("verify clientsetAPI path", func() { - f.ClientsetAPIPath = "" - err := ValidateFlags(f) - Expect(err.Error()).To(ContainSubstring("specifying client API path is required currently.")) - }) - - It("verify group version list", func() { - f.GroupVersions = []string{} - err := ValidateFlags(f) - Expect(err.Error()).To(ContainSubstring("list of group versions for which the clients are to be generated is required.")) - }) - -}) diff --git a/pkg/generators/clientgen/clientgen.go b/pkg/generators/clientgen/clientgen.go deleted file mode 100644 index e81f7a6fb..000000000 --- a/pkg/generators/clientgen/clientgen.go +++ /dev/null @@ -1,251 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package clientgen - -import ( - "path/filepath" - "sort" - "strings" - - "k8s.io/code-generator/cmd/client-gen/types" - "k8s.io/gengo/namer" - "k8s.io/klog/v2" - "sigs.k8s.io/controller-tools/pkg/genall" - "sigs.k8s.io/controller-tools/pkg/markers" - - "github.com/kcp-dev/code-generator/v2/pkg/internal/clientgen" - "github.com/kcp-dev/code-generator/v2/pkg/parser" - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -type Generator struct { - // Name is the name of this client-set, e.g. "kubernetes" - Name string `marker:",optional"` - - // ExternalOnly toggles the creation of a "versioned" sub-directory. Set to true if you are generating - // custom code for a project that's not using k8s.io/code-generator/generate-groups.sh for their types. - ExternalOnly bool `marker:",optional"` - - // Standalone toggles the creation of a "cluster" sub-directory. Set to true if you are placing cluster- - // aware code somewhere outside of the normal client tree. - Standalone bool `marker:",optional"` - - // HeaderFile specifies the header text (e.g. license) to prepend to generated files. - HeaderFile string `marker:",optional"` - - // Year specifies the year to substitute for " YEAR" in the header file. - Year string `marker:",optional"` - - // SingleClusterClientPackagePath is the root directory under which single-cluster-aware clients exist. - // e.g. "k8s.io/client-go/kubernetes" - SingleClusterClientPackagePath string `marker:""` - - // SingleClusterApplyConfigurationsPackagePath is the root directory under which single-cluster-aware apply configurations exist. - // e.g. "k8s.io/client-go/applyconfigurations" - SingleClusterApplyConfigurationsPackagePath string `marker:",optional"` - - // OutputPackagePath is the root directory under which this tool will output files. - // e.g. "github.com/kcp-dev/client-go/clients" - OutputPackagePath string `marker:""` - - // APIPackagePath is the root directory under which API types exist. - // e.g. "k8s.io/api" - APIPackagePath string `marker:"apiPackagePath"` -} - -func (Generator) RegisterMarkers(into *markers.Registry) error { - return markers.RegisterAll(into, - parser.GenclientMarker, - parser.NonNamespacedMarker, - parser.GroupNameMarker, - parser.NoVerbsMarker, - parser.ReadOnlyMarker, - parser.SkipVerbsMarker, - parser.OnlyVerbsMarker, - ) -} - -// Generate will generate clients for all types that have generated clients. -func (g Generator) Generate(ctx *genall.GenerationContext) error { - var headerText string - - if g.HeaderFile != "" { - headerBytes, err := ctx.ReadFile(g.HeaderFile) - if err != nil { - return err - } - headerText = string(headerBytes) - } - var replacement string - if g.Year != "" { - replacement = " " + g.Year - } - headerText = strings.ReplaceAll(headerText, " YEAR", replacement) - - if g.Name == "" { - g.Name = "clientset" - } - - groupVersionKinds, err := parser.CollectKinds(ctx) - if err != nil { - return err - } - - groupInfo := toGroupVersionInfos(groupVersionKinds) - - clientsetDir := g.Name - if !g.ExternalOnly { - clientsetDir = filepath.Join(clientsetDir, "versioned") - } - if !g.Standalone { - clientsetDir = filepath.Join(clientsetDir, "cluster") - } - clientsetFile := filepath.Join(clientsetDir, "clientset.go") - logger := klog.Background().WithValues("clientset", g.Name) - logger.WithValues("path", clientsetFile).Info("generating clientset") - - if err := util.WriteGeneratedCode(ctx, headerText, &clientgen.ClientSet{ - Name: g.Name, - PackagePath: filepath.Join(g.OutputPackagePath, clientsetDir), - Groups: groupInfo, - SingleClusterClientPackagePath: g.SingleClusterClientPackagePath, - }, clientsetFile); err != nil { - return err - } - - // TODO: do we actually need the scheme? no, right? k8s client-gen will do it for you - schemeDir := filepath.Join(clientsetDir, "scheme") - schemeFile := filepath.Join(schemeDir, "register.go") - logger.WithValues("path", schemeFile).Info("generating scheme") - - if err := util.WriteGeneratedCode(ctx, headerText, &clientgen.Scheme{ - Groups: groupInfo, - APIPackagePath: g.APIPackagePath, - }, schemeFile); err != nil { - return err - } - - fakeClientsetDir := filepath.Join(clientsetDir, "fake") - fakeClientsetFile := filepath.Join(fakeClientsetDir, "clientset.go") - logger.WithValues("path", fakeClientsetFile).Info("generating scheme") - - if err := util.WriteGeneratedCode(ctx, headerText, &clientgen.FakeClientset{ - Name: g.Name, - PackagePath: filepath.Join(g.OutputPackagePath, clientsetDir), - Groups: groupInfo, - SingleClusterClientPackagePath: g.SingleClusterClientPackagePath, - }, fakeClientsetFile); err != nil { - return err - } - - for group, versions := range groupVersionKinds { - for version, kinds := range versions { - groupDir := filepath.Join(clientsetDir, "typed", group.PackageName(), version.PackageName()) - outputFile := filepath.Join(groupDir, group.PackageName()+"_client.go") - logger := logger.WithValues( - "group", group.String(), - "version", version.String(), - ) - logger.WithValues("path", outputFile).Info("generating group client") - groupInfo := toGroupVersionInfo(group, version) - if err := util.WriteGeneratedCode(ctx, headerText, &clientgen.Group{ - Group: groupInfo, - Kinds: kinds, - SingleClusterClientPackagePath: g.SingleClusterClientPackagePath, - }, outputFile); err != nil { - return err - } - - fakeGroupDir := filepath.Join(groupDir, "fake") - outputFile = filepath.Join(fakeGroupDir, group.PackageName()+"_client.go") - logger = logger.WithValues( - "group", group.String(), - "version", version.String(), - ) - logger.WithValues("path", outputFile).Info("generating fake group client") - if err := util.WriteGeneratedCode(ctx, headerText, &clientgen.FakeGroup{ - Group: groupInfo, - Kinds: kinds, - PackagePath: filepath.Join(g.OutputPackagePath, clientsetDir), - SingleClusterClientPackagePath: g.SingleClusterClientPackagePath, - }, outputFile); err != nil { - return err - } - - for _, kind := range kinds { - outputFile := filepath.Join(groupDir, strings.ToLower(kind.String())+".go") - logger := logger.WithValues( - "kind", kind.String(), - ) - logger.WithValues("path", outputFile).Info("generating client for kind") - - if err := util.WriteGeneratedCode(ctx, headerText, &clientgen.TypedClient{ - Group: groupInfo, - Kind: kind, - APIPackagePath: g.APIPackagePath, - SingleClusterClientPackagePath: g.SingleClusterClientPackagePath, - }, outputFile); err != nil { - return err - } - - outputFile = filepath.Join(fakeGroupDir, strings.ToLower(kind.String())+".go") - logger = logger.WithValues( - "kind", kind.String(), - ) - logger.WithValues("path", outputFile).Info("generating fake client for kind") - - if err := util.WriteGeneratedCode(ctx, headerText, &clientgen.FakeTypedClient{ - Group: groupInfo, - Kind: kind, - APIPackagePath: g.APIPackagePath, - PackagePath: filepath.Join(g.OutputPackagePath, clientsetDir), - SingleClusterClientPackagePath: g.SingleClusterClientPackagePath, - SingleClusterApplyConfigurationsPackagePath: g.SingleClusterApplyConfigurationsPackagePath, - }, outputFile); err != nil { - return err - } - } - } - } - - return nil -} - -// adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[types.PackageVersion][]parser.Kind) []types.GroupVersionInfo { - var info []types.GroupVersionInfo - for group, versions := range groupVersionKinds { - for version := range versions { - info = append(info, toGroupVersionInfo(group, version)) - } - } - sort.Slice(info, func(i, j int) bool { - return info[i].PackageAlias < info[j].PackageAlias - }) - return info -} - -// adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfo(group parser.Group, version types.PackageVersion) types.GroupVersionInfo { - return types.GroupVersionInfo{ - Group: group.Group, - Version: types.Version(namer.IC(version.Version.String())), - PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, - LowerCaseGroupGoName: namer.IL(group.GoName), - } -} diff --git a/pkg/generators/informergen/informergen.go b/pkg/generators/informergen/informergen.go deleted file mode 100644 index 1f288c921..000000000 --- a/pkg/generators/informergen/informergen.go +++ /dev/null @@ -1,271 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package informergen - -import ( - "path/filepath" - "sort" - "strings" - - "k8s.io/code-generator/cmd/client-gen/types" - "k8s.io/gengo/namer" - "k8s.io/klog/v2" - "sigs.k8s.io/controller-tools/pkg/genall" - "sigs.k8s.io/controller-tools/pkg/markers" - - "github.com/kcp-dev/code-generator/v2/pkg/internal/informergen" - "github.com/kcp-dev/code-generator/v2/pkg/parser" - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -type Generator struct { - // Name is the name of the clientset, e.g. "kubernetes" - ClientsetName string `marker:",optional"` - - // ExternalOnly toggles the creation of a "externalversions" sub-directory. Set to true if you are generating - // custom code for a project that's not using k8s.io/code-generator/generate-groups.sh for their types. - ExternalOnly bool `marker:",optional"` - - // Standalone toggles the creation of a "cluster" sub-directory. Set to true if you are placing cluster- - // aware code somewhere outside of the normal client tree. - Standalone bool `marker:",optional"` - - // HeaderFile specifies the header text (e.g. license) to prepend to generated files. - HeaderFile string `marker:",optional"` - - // Year specifies the year to substitute for " YEAR" in the header file. - Year string `marker:",optional"` - - // OutputPackagePath is the root directory under which this tool will output files. - // e.g. "github.com/kcp-dev/client-go/clients" - OutputPackagePath string `marker:""` - - // APIPackagePath is the root directory under which API types exist. - // e.g. "k8s.io/api" - APIPackagePath string `marker:"apiPackagePath"` - - // SingleClusterClientPackagePath is the root directory under which single-cluster-aware clients exist. - // e.g. "k8s.io/client-go/kubernetes" - SingleClusterClientPackagePath string `marker:""` - - // SingleClusterInformerPackagePath is the package under which the cluster-unaware listers are exposed. - // e.g. "k8s.io/client-go/informers" - SingleClusterInformerPackagePath string `marker:",optional"` - - // SingleClusterListerPackagePath is the root directory under which single-cluster-aware listers exist, - // for the case where we're only generating new code "on top" to enable multi-cluster use-cases. - // e.g. "k8s.io/client-go/listers" - SingleClusterListerPackagePath string `marker:",optional"` -} - -func (g Generator) RegisterMarkers(into *markers.Registry) error { - return markers.RegisterAll(into, - parser.GenclientMarker, - parser.NonNamespacedMarker, - parser.GroupNameMarker, - parser.NoVerbsMarker, - parser.ReadOnlyMarker, - parser.SkipVerbsMarker, - parser.OnlyVerbsMarker, - ) -} - -func (g Generator) Generate(ctx *genall.GenerationContext) error { - var headerText string - - if g.HeaderFile != "" { - headerBytes, err := ctx.ReadFile(g.HeaderFile) - if err != nil { - return err - } - headerText = string(headerBytes) - } - var replacement string - if g.Year != "" { - replacement = " " + g.Year - } - headerText = strings.ReplaceAll(headerText, " YEAR", replacement) - - groupVersionKinds, err := parser.CollectKinds(ctx, "list", "watch") - if err != nil { - return err - } - - groupInfo := toGroupVersionInfos(groupVersionKinds) - - logger := klog.Background() - - var onlyGroups []parser.Group - for group := range groupVersionKinds { - onlyGroups = append(onlyGroups, group) - } - sort.Slice(onlyGroups, func(i, j int) bool { - return onlyGroups[i].Group.PackageName() < onlyGroups[j].Group.PackageName() - }) - - if g.ClientsetName == "" { - g.ClientsetName = "clientset" - } - - clientsetDir := g.ClientsetName - if !g.ExternalOnly { - clientsetDir = filepath.Join(clientsetDir, "versioned") - } - if !g.Standalone { - clientsetDir = filepath.Join(clientsetDir, "cluster") - } - listersDir := "listers" - - informersDir := "informers" - if !g.ExternalOnly { - informersDir = filepath.Join(informersDir, "externalversions") - } - factoryPath := filepath.Join(informersDir, "factory.go") - logger.WithValues("path", factoryPath).Info("generating informer factory") - if err := util.WriteGeneratedCode(ctx, headerText, &informergen.Factory{ - Groups: onlyGroups, - PackagePath: filepath.Join(g.OutputPackagePath, informersDir), - ClientsetPackagePath: filepath.Join(g.OutputPackagePath, clientsetDir), - SingleClusterClientPackagePath: g.SingleClusterClientPackagePath, - SingleClusterInformerPackagePath: g.SingleClusterInformerPackagePath, - }, factoryPath); err != nil { - return err - } - - gvks := map[types.Group]map[types.Version][]parser.Kind{} - for group, versions := range groupVersionKinds { - for version, kinds := range versions { - info := toGroupVersionInfo(group, version) - if _, exists := gvks[info.Group]; !exists { - gvks[info.Group] = map[types.Version][]parser.Kind{} - } - gvks[info.Group][info.Version] = kinds - } - } - genericPath := filepath.Join(informersDir, "generic.go") - logger.WithValues("path", factoryPath).Info("generating generic informers") - if err := util.WriteGeneratedCode(ctx, headerText, &informergen.Generic{ - Groups: groupInfo, - GroupVersionKinds: gvks, - APIPackagePath: g.APIPackagePath, - SingleClusterInformerPackagePath: g.SingleClusterInformerPackagePath, - }, genericPath); err != nil { - return err - } - - interfacesPath := filepath.Join(informersDir, "internalinterfaces", "factory_interfaces.go") - logger.WithValues("path", factoryPath).Info("generating internal informer interfaces") - if err := util.WriteGeneratedCode(ctx, headerText, &informergen.FactoryInterface{ - ClientsetPackagePath: filepath.Join(g.OutputPackagePath, clientsetDir), - SingleClusterClientPackagePath: g.SingleClusterClientPackagePath, - UseUpstreamInterfaces: g.SingleClusterInformerPackagePath != "", - }, interfacesPath); err != nil { - return err - } - - for group, versions := range groupVersionKinds { - groupDir := filepath.Join(informersDir, group.PackageName()) - outputFile := filepath.Join(groupDir, "interface.go") - logger := logger.WithValues( - "group", group.String(), - ) - - var onlyVersions []types.Version - for version := range versions { - onlyVersions = append(onlyVersions, types.Version(namer.IC(version.Version.String()))) - } - sort.Slice(onlyVersions, func(i, j int) bool { - return onlyVersions[i].PackageName() < onlyVersions[j].PackageName() - }) - - logger.WithValues("path", outputFile).Info("generating group interface") - if err := util.WriteGeneratedCode(ctx, headerText, &informergen.GroupInterface{ - Group: group, - Versions: onlyVersions, - PackagePath: filepath.Join(g.OutputPackagePath, informersDir), - UseUpstreamInterfaces: g.SingleClusterInformerPackagePath != "", - }, outputFile); err != nil { - return err - } - for version, kinds := range versions { - versionDir := filepath.Join(groupDir, version.PackageName()) - outputFile := filepath.Join(versionDir, "interface.go") - logger := logger.WithValues( - "version", version.String(), - ) - - logger.WithValues("path", outputFile).Info("generating version interface") - if err := util.WriteGeneratedCode(ctx, headerText, &informergen.VersionInterface{ - Version: types.Version(namer.IC(version.Version.String())), - Kinds: kinds, - PackagePath: filepath.Join(g.OutputPackagePath, informersDir), - UseUpstreamInterfaces: g.SingleClusterInformerPackagePath != "", - }, outputFile); err != nil { - return err - } - - for _, kind := range kinds { - outputFile := filepath.Join(versionDir, strings.ToLower(kind.String())+".go") - logger := logger.WithValues( - "kind", kind.String(), - ) - logger.WithValues("path", outputFile).Info("generating informer for kind") - - if err := util.WriteGeneratedCode(ctx, headerText, &informergen.Informer{ - Group: toGroupVersionInfo(group, version), - Kind: kind, - APIPackagePath: g.APIPackagePath, - PackagePath: filepath.Join(g.OutputPackagePath, informersDir), - ClientsetPackagePath: filepath.Join(g.OutputPackagePath, clientsetDir), - ListerPackagePath: filepath.Join(g.OutputPackagePath, listersDir), - SingleClusterClientPackagePath: g.SingleClusterClientPackagePath, - SingleClusterInformerPackagePath: g.SingleClusterInformerPackagePath, - SingleClusterListerPackagePath: g.SingleClusterListerPackagePath, - }, outputFile); err != nil { - return err - } - } - } - } - - return nil -} - -// adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[types.PackageVersion][]parser.Kind) []types.GroupVersionInfo { - var info []types.GroupVersionInfo - for group, versions := range groupVersionKinds { - for version := range versions { - info = append(info, toGroupVersionInfo(group, version)) - } - } - sort.Slice(info, func(i, j int) bool { - return info[i].PackageAlias < info[j].PackageAlias - }) - return info -} - -// adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfo(group parser.Group, version types.PackageVersion) types.GroupVersionInfo { - return types.GroupVersionInfo{ - Group: group.Group, - Version: types.Version(namer.IC(version.Version.String())), - PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, - LowerCaseGroupGoName: namer.IL(group.GoName), - } -} diff --git a/pkg/generators/listergen/listergen.go b/pkg/generators/listergen/listergen.go deleted file mode 100644 index 33bd3a5c4..000000000 --- a/pkg/generators/listergen/listergen.go +++ /dev/null @@ -1,137 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package listergen - -import ( - "path/filepath" - "strings" - - "k8s.io/code-generator/cmd/client-gen/types" - "k8s.io/gengo/namer" - "k8s.io/klog/v2" - "sigs.k8s.io/controller-tools/pkg/genall" - "sigs.k8s.io/controller-tools/pkg/markers" - - "github.com/kcp-dev/code-generator/v2/pkg/internal/listergen" - "github.com/kcp-dev/code-generator/v2/pkg/parser" - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -type Generator struct { - // HeaderFile specifies the header text (e.g. license) to prepend to generated files. - HeaderFile string `marker:",optional"` - - // Year specifies the year to substitute for " YEAR" in the header file. - Year string `marker:",optional"` - - // APIPackagePath is the root directory under which API types exist. - // e.g. "k8s.io/api" - APIPackagePath string `marker:"apiPackagePath"` - - // SingleClusterListerPackagePath is the root directory under which single-cluster-aware listers exist, - // for the case where we're only generating new code "on top" to enable multi-cluster use-cases. - // e.g. "k8s.io/client-go/listers" - SingleClusterListerPackagePath string `marker:",optional"` -} - -func (Generator) RegisterMarkers(into *markers.Registry) error { - return markers.RegisterAll(into, - parser.GenclientMarker, - parser.NonNamespacedMarker, - parser.GroupNameMarker, - parser.NoVerbsMarker, - parser.ReadOnlyMarker, - parser.SkipVerbsMarker, - parser.OnlyVerbsMarker, - ) -} - -// Generate will generate listers for all types that have generated clients and support LIST + WATCH verbs. -func (g Generator) Generate(ctx *genall.GenerationContext) error { - var headerText string - - if g.HeaderFile != "" { - headerBytes, err := ctx.ReadFile(g.HeaderFile) - if err != nil { - return err - } - headerText = string(headerBytes) - } - var replacement string - if g.Year != "" { - replacement = " " + g.Year - } - headerText = strings.ReplaceAll(headerText, " YEAR", replacement) - - groupVersionKinds, err := parser.CollectKinds(ctx, "list", "watch") - if err != nil { - return err - } - - for group, versions := range groupVersionKinds { - for version, kinds := range versions { - groupInfo := toGroupVersionInfo(group, version) - for _, kind := range kinds { - listerDir := filepath.Join("listers", group.PackageName(), version.PackageName()) - outputFile := filepath.Join(listerDir, strings.ToLower(kind.String())+".go") - logger := klog.Background().WithValues( - "group", group.String(), - "version", version.String(), - "kind", kind.String(), - "path", outputFile, - ) - logger.Info("generating lister") - - if err := util.WriteGeneratedCode(ctx, headerText, &listergen.Lister{ - Group: groupInfo, - APIPackagePath: g.APIPackagePath, - Kind: kind, - SingleClusterListerPackagePath: g.SingleClusterListerPackagePath, - }, outputFile); err != nil { - return err - } - - outputFile = filepath.Join(listerDir, strings.ToLower(kind.String())+"_expansion.go") - logger = logger.WithValues( - "path", outputFile, - ) - logger.Info("generating lister expansion") - - if err := util.InitializeGeneratedCode(ctx, headerText, &listergen.Expansions{ - Group: groupInfo, - Kind: kind, - UseUpstreamInterfaces: g.SingleClusterListerPackagePath != "", - }, outputFile); err != nil { - return err - } - } - } - } - - return nil -} - -// adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfo(group parser.Group, version types.PackageVersion) types.GroupVersionInfo { - return types.GroupVersionInfo{ - Group: group.Group, - Version: types.Version(namer.IC(version.Version.String())), - PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, - LowerCaseGroupGoName: namer.IL(group.GoName), - } -} diff --git a/pkg/imports/kcptracker.go b/pkg/imports/kcptracker.go new file mode 100644 index 000000000..f022326a1 --- /dev/null +++ b/pkg/imports/kcptracker.go @@ -0,0 +1,88 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package imports + +import ( + "go/token" + "path/filepath" + "strings" + + "k8s.io/gengo/v2/generator" + "k8s.io/gengo/v2/namer" + "k8s.io/gengo/v2/types" + "k8s.io/klog/v2" +) + +// NewImportTrackerForPackage returns a tracker that will automatically prefix any +// import from github.com/kcp-dev/* with "kcp", so such imports are easily distinguishable +// from the generated single-cluster code. +func NewImportTrackerForPackage(local string, typesToAdd ...*types.Type) *namer.DefaultImportTracker { + tracker := generator.NewImportTrackerForPackage(local, typesToAdd...) + tracker.LocalName = func(name types.Name) string { return goTrackerLocalName(tracker, local, name) } + + return tracker +} + +// goTrackerLocalName is copied from upstream and just extended to include the kcp prefix. +func goTrackerLocalName(tracker namer.ImportTracker, localPkg string, t types.Name) string { + path := t.Package + isKcp := strings.HasPrefix(path, "github.com/kcp-dev/") + + if path == "github.com/kcp-dev/logicalcluster/v3" { + return "logicalcluster" + } + + // Using backslashes in package names causes gengo to produce Go code which + // will not compile with the gc compiler. See the comment on GoSeperator. + if strings.ContainsRune(path, '\\') { + klog.Warningf("Warning: backslash used in import path '%v', this is unsupported.\n", path) + } + localLeaf := filepath.Base(localPkg) + + dirs := strings.Split(path, namer.GoSeperator) + for n := len(dirs) - 1; n >= 0; n-- { + // follow kube convention of not having anything between directory names + name := strings.Join(dirs[n:], "") + name = strings.ReplaceAll(name, "_", "") + // These characters commonly appear in import paths for go + // packages, but aren't legal go names. So we'll sanitize. + name = strings.ReplaceAll(name, ".", "") + name = strings.ReplaceAll(name, "-", "") + + if isKcp { + name = "kcp" + name + } + + if _, found := tracker.PathOf(name); found || name == localLeaf { + // This name collides with some other package. + // Or, this name is the same name as the local package, + // which we avoid because it can be confusing. For example, + // if the local package is v1, we to avoid importing + // another package using the v1 name, and instead import + // it with a more qualified name, such as metav1. + continue + } + + // If the import name is a Go keyword, prefix with an underscore. + if token.Lookup(name).IsKeyword() { + name = "_" + name + } + return name + } + panic("can't find import for " + path) +} diff --git a/pkg/internal/clientgen/clientset.go b/pkg/internal/clientgen/clientset.go deleted file mode 100644 index 943a15fbb..000000000 --- a/pkg/internal/clientgen/clientset.go +++ /dev/null @@ -1,176 +0,0 @@ -package clientgen - -import ( - "io" - "strings" - "text/template" - - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -type ClientSet struct { - // Name is the name of the clientset, e.g. "kubernetes" - Name string - - // Groups are the groups in this client-set. - Groups []types.GroupVersionInfo - - // PackagePath is the package under which this client-set will be exposed. - // TODO(skuznets) we should be able to figure this out from the output dir, ideally - PackagePath string - - // SingleClusterClientPackagePath is the root directory under which single-cluster-aware clients exist. - // e.g. "k8s.io/client-go/kubernetes" - SingleClusterClientPackagePath string -} - -func (c *ClientSet) WriteContent(w io.Writer) error { - templ, err := template.New("clientset").Funcs(template.FuncMap{ - "upperFirst": util.UpperFirst, - "lowerFirst": util.LowerFirst, - "toLower": strings.ToLower, - }).Parse(clientset) - if err != nil { - return err - } - - m := map[string]interface{}{ - "name": c.Name, - "packagePath": c.PackagePath, - "groups": c.Groups, - "singleClusterClientPackagePath": c.SingleClusterClientPackagePath, - } - return templ.Execute(w, m) -} - -var clientset = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package {{.name}} - -import ( - "fmt" - "net/http" - - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" - - client "{{.singleClusterClientPackagePath}}" - - "k8s.io/client-go/discovery" - "k8s.io/client-go/rest" - "k8s.io/client-go/util/flowcontrol" - -{{range .groups}} {{.PackageAlias}} "{{$.packagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}" -{{end -}} -) - -type ClusterInterface interface { - Cluster(logicalcluster.Path) client.Interface - Discovery() discovery.DiscoveryInterface -{{range .groups}} {{.GroupGoName}}{{.Version}}() {{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface -{{end -}} -} - -// ClusterClientset contains the clients for groups. -type ClusterClientset struct { - *discovery.DiscoveryClient - clientCache kcpclient.Cache[*client.Clientset] -{{range .groups}} {{.LowerCaseGroupGoName}}{{.Version}} *{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterClient -{{end -}} -} - -// Discovery retrieves the DiscoveryClient -func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { - if c == nil { - return nil - } - return c.DiscoveryClient -} - -{{range .groups}} -// {{.GroupGoName}}{{.Version}} retrieves the {{.GroupGoName}}{{.Version}}ClusterClient. -func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() {{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { - return c.{{.LowerCaseGroupGoName}}{{.Version}} -} -{{end -}} - -// Cluster scopes this clientset to one cluster. -func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - return c.clientCache.ClusterOrDie(clusterPath) -} - -// NewForConfig creates a new ClusterClientset for the given config. -// If config's RateLimiter is not set and QPS and Burst are acceptable, -// NewForConfig will generate a rate-limiter in configShallowCopy. -// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), -// where httpClient was generated with rest.HTTPClientFor(c). -func NewForConfig(c *rest.Config) (*ClusterClientset, error) { - configShallowCopy := *c - - if configShallowCopy.UserAgent == "" { - configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent() - } - - // share the transport between all clients - httpClient, err := rest.HTTPClientFor(&configShallowCopy) - if err != nil { - return nil, err - } - - return NewForConfigAndClient(&configShallowCopy, httpClient) -} - -// NewForConfigAndClient creates a new ClusterClientset for the given config and http client. -// Note the http client provided takes precedence over the configured transport values. -// If config's RateLimiter is not set and QPS and Burst are acceptable, -// NewForConfigAndClient will generate a rate-limiter in configShallowCopy. -func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterClientset, error) { - configShallowCopy := *c - if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { - if configShallowCopy.Burst <= 0 { - return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") - } - configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) - } - - cache := kcpclient.NewCache(c, httpClient, &kcpclient.Constructor[*client.Clientset]{ - NewForConfigAndClient: client.NewForConfigAndClient, - }) - if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { - return nil, err - } - - var cs ClusterClientset - cs.clientCache = cache - var err error -{{range .groups}} cs.{{.LowerCaseGroupGoName}}{{.Version}}, err = {{.PackageAlias}}.NewForConfigAndClient(&configShallowCopy, httpClient) - if err != nil { - return nil, err - } -{{end}} - cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient) - if err != nil { - return nil, err - } - return &cs, nil -} - -// NewForConfigOrDie creates a new ClusterClientset for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *ClusterClientset { - cs, err := NewForConfig(c) - if err!=nil { - panic(err) - } - return cs -} -` diff --git a/pkg/internal/clientgen/fake_clientset.go b/pkg/internal/clientgen/fake_clientset.go deleted file mode 100644 index 511f61e70..000000000 --- a/pkg/internal/clientgen/fake_clientset.go +++ /dev/null @@ -1,155 +0,0 @@ -package clientgen - -import ( - "io" - "strings" - "text/template" - - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -type FakeClientset struct { - // Name is the name of the clientset, e.g. "kubernetes" - Name string - - // Groups are the groups in this client-set. - Groups []types.GroupVersionInfo - - // PackagePath is the package under which this client-set will be exposed. - // TODO(skuznets) we should be able to figure this out from the output dir, ideally - PackagePath string - - // SingleClusterClientPackagePath is the root directory under which single-cluster-aware clients exist. - // e.g. "k8s.io/client-go/kubernetes" - SingleClusterClientPackagePath string -} - -func (c *FakeClientset) WriteContent(w io.Writer) error { - templ, err := template.New("fakeClientset").Funcs(template.FuncMap{ - "upperFirst": util.UpperFirst, - "lowerFirst": util.LowerFirst, - "toLower": strings.ToLower, - }).Parse(fakeClientset) - if err != nil { - return err - } - - m := map[string]interface{}{ - "name": c.Name, - "packagePath": c.PackagePath, - "groups": c.Groups, - "singleClusterClientPackagePath": c.SingleClusterClientPackagePath, - } - return templ.Execute(w, m) -} - -var fakeClientset = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package fake - -import ( - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - kcpfakediscovery "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/discovery/fake" - "github.com/kcp-dev/logicalcluster/v3" - - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/client-go/discovery" - - client "{{.singleClusterClientPackagePath}}" - clientscheme "{{.singleClusterClientPackagePath}}/scheme" - - kcpclient "{{.packagePath}}" -{{range .groups}} {{.PackageAlias}} "{{$.singleClusterClientPackagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}" -{{end -}} -{{range .groups}} kcp{{.PackageAlias}} "{{$.packagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}" -{{end -}} -{{range .groups}} fake{{.PackageAlias}} "{{$.packagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}/fake" -{{end -}} -) - -// NewSimpleClientset returns a clientset that will respond with the provided objects. -// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement -// for a real clientset and is mostly useful in simple unit tests. -func NewSimpleClientset(objects ...runtime.Object) *ClusterClientset { - o := kcptesting.NewObjectTracker(clientscheme.Scheme, clientscheme.Codecs.UniversalDecoder()) - o.AddAll(objects...) - - cs := &ClusterClientset{Fake: &kcptesting.Fake{}, tracker: o} - cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: cs.Fake, ClusterPath: logicalcluster.Wildcard} - cs.AddReactor("*", "*", kcptesting.ObjectReaction(o)) - cs.AddWatchReactor("*", kcptesting.WatchReaction(o)) - - return cs -} - -var _ kcpclient.ClusterInterface = (*ClusterClientset)(nil) - -// ClusterClientset contains the clients for groups. -type ClusterClientset struct { - *kcptesting.Fake - discovery *kcpfakediscovery.FakeDiscovery - tracker kcptesting.ObjectTracker -} - -// Discovery retrieves the DiscoveryClient -func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { - return c.discovery -} - -func (c *ClusterClientset) Tracker() kcptesting.ObjectTracker { - return c.tracker -} - -{{range .groups}} -// {{.GroupGoName}}{{.Version}} retrieves the {{.GroupGoName}}{{.Version}}ClusterClient. -func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() kcp{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { - return &fake{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterClient{Fake: c.Fake} -} -{{end -}} - -// Cluster scopes this clientset to one cluster. -func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - return &Clientset{ - Fake: c.Fake, - discovery: &kcpfakediscovery.FakeDiscovery{Fake: c.Fake, ClusterPath: clusterPath}, - tracker: c.tracker.Cluster(clusterPath), - clusterPath: clusterPath, - } -} - -var _ client.Interface = (*Clientset)(nil) - -// Clientset contains the clients for groups. -type Clientset struct { - *kcptesting.Fake - discovery *kcpfakediscovery.FakeDiscovery - tracker kcptesting.ScopedObjectTracker - clusterPath logicalcluster.Path -} - -// Discovery retrieves the DiscoveryClient -func (c *Clientset) Discovery() discovery.DiscoveryInterface { - return c.discovery -} - -func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { - return c.tracker -} - -{{range .groups}} -// {{.GroupGoName}}{{.Version}} retrieves the {{.GroupGoName}}{{.Version}}Client. -func (c *Clientset) {{.GroupGoName}}{{.Version}}() {{.PackageAlias}}.{{.GroupGoName}}{{.Version}}Interface { - return &fake{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}Client{Fake: c.Fake, ClusterPath: c.clusterPath} -} -{{end -}} -` diff --git a/pkg/internal/clientgen/fake_group.go b/pkg/internal/clientgen/fake_group.go deleted file mode 100644 index cd3b96b0b..000000000 --- a/pkg/internal/clientgen/fake_group.go +++ /dev/null @@ -1,102 +0,0 @@ -package clientgen - -import ( - "io" - "strings" - "text/template" - - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -type FakeGroup struct { - // Group is the group in this client. - Group types.GroupVersionInfo - - // Kinds are the kinds in the group. - Kinds []parser.Kind - - // PackagePath is the package under which this client-set will be exposed. - // TODO(skuznets) we should be able to figure this out from the output dir, ideally - PackagePath string - - // SingleClusterClientPackagePath is the root directory under which single-cluster-aware clients exist. - // e.g. "k8s.io/client-go/kubernetes" - SingleClusterClientPackagePath string -} - -func (g *FakeGroup) WriteContent(w io.Writer) error { - templ, err := template.New("fakeGroup").Funcs(template.FuncMap{ - "upperFirst": util.UpperFirst, - "lowerFirst": util.LowerFirst, - "toLower": strings.ToLower, - }).Parse(fakeGroup) - if err != nil { - return err - } - - m := map[string]interface{}{ - "group": g.Group, - "kinds": g.Kinds, - "packagePath": g.PackagePath, - "singleClusterClientPackagePath": g.SingleClusterClientPackagePath, - } - return templ.Execute(w, m) -} - -var fakeGroup = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package fake - -import ( - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - "github.com/kcp-dev/logicalcluster/v3" - - "k8s.io/client-go/rest" - kcp{{.group.PackageAlias}} "{{.packagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - {{.group.PackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" -) - -var _ kcp{{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}ClusterInterface = (*{{.group.GroupGoName}}{{.group.Version}}ClusterClient)(nil) - -type {{.group.GroupGoName}}{{.group.Version}}ClusterClient struct { - *kcptesting.Fake -} - -func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - return &{{.group.GroupGoName}}{{.group.Version}}Client{Fake: c.Fake, ClusterPath: clusterPath} -} - -{{ range .kinds}} -func (c *{{$.group.GroupGoName}}{{$.group.Version}}ClusterClient) {{.Plural}}() kcp{{$.group.PackageAlias}}.{{.String}}ClusterInterface { - return &{{.Plural | lowerFirst}}ClusterClient{Fake: c.Fake} -} -{{end -}} - -var _ {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface = (*{{.group.GroupGoName}}{{.group.Version}}Client)(nil) - -type {{.group.GroupGoName}}{{.group.Version}}Client struct { - *kcptesting.Fake - ClusterPath logicalcluster.Path -} - -func (c *{{.group.GroupGoName}}{{.group.Version}}Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret -} - -{{ range .kinds}} -func (c *{{$.group.GroupGoName}}{{$.group.Version}}Client) {{.Plural}}({{if .IsNamespaced}}namespace string{{end}}) {{$.group.PackageAlias}}.{{.String}}Interface { - return &{{.Plural | lowerFirst}}Client{Fake: c.Fake, ClusterPath: c.ClusterPath{{if .IsNamespaced}}, Namespace: namespace{{end}}} -} -{{end -}} -` diff --git a/pkg/internal/clientgen/fake_type.go b/pkg/internal/clientgen/fake_type.go deleted file mode 100644 index c52abf527..000000000 --- a/pkg/internal/clientgen/fake_type.go +++ /dev/null @@ -1,463 +0,0 @@ -package clientgen - -import ( - "fmt" - "io" - "path/filepath" - "strings" - "text/template" - - "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -type FakeTypedClient struct { - // Group is the group in this client. - Group types.GroupVersionInfo - - // Kind is the kinds in this file. - Kind parser.Kind - - // PackagePath is the package under which this client-set will be exposed. - // TODO(skuznets) we should be able to figure this out from the output dir, ideally - PackagePath string - - // APIPackagePath is the root directory under which API types exist. - // e.g. "k8s.io/api" - APIPackagePath string - - // SingleClusterClientPackagePath is the root directory under which single-cluster-aware clients exist. - // e.g. "k8s.io/client-go/kubernetes" - SingleClusterClientPackagePath string - - // SingleClusterApplyConfigurationsPackagePath is the root directory under which single-cluster-aware clients exist. - // e.g. "k8s.io/client-go/applyconfigurations" - SingleClusterApplyConfigurationsPackagePath string -} - -func aliasFor(path string) ([]string, error) { - var alias []string - parts := strings.Split(path, "/") - switch len(parts) { - case 0: - return nil, fmt.Errorf("invalid override path: %v", path) - case 1: - alias = []string{parts[0]} - default: - alias = parts[len(parts)-2:] - } - return alias, nil -} - -func (c *FakeTypedClient) WriteContent(w io.Writer) error { - templ, err := template.New("fakeTypedClient").Funcs(template.FuncMap{ - "upperFirst": util.UpperFirst, - "lowerFirst": util.LowerFirst, - "toLower": strings.ToLower, - }).Parse(fakeTypedClient) - if err != nil { - return err - } - - importAliases := map[string]string{} // import path -> alias - extraImports := map[string]string{ // import path -> alias - "": c.Group.PackageAlias, // unset paths on input/output tags use the default api package - } - extensionVerbs := sets.New[string]() - for i, extension := range c.Kind.Extensions { - extensionVerbs.Insert(extension.Verb) - for _, importPath := range []string{extension.InputPath, extension.ResultPath} { - if importPath == "" { - continue - } - alias, err := aliasFor(importPath) - if err != nil { - return err - } - extraImports[importPath] = strings.Join(alias, "") - if importPath != filepath.Join(c.APIPackagePath, c.Group.Group.PackageName(), c.Group.Version.PackageName()) { - importAliases[importPath] = strings.Join(alias, "") - } - } - if extension.Verb == "apply" { - var alias []string - if extension.InputPath != "" { - alias, err = aliasFor(extension.InputPath) - if err != nil { - return err - } - } else { - alias = []string{c.Group.Group.PackageName(), c.Group.Version.PackageName()} - } - hack := filepath.Join(append([]string{c.SingleClusterApplyConfigurationsPackagePath}, alias...)...) - extraImports[hack] = "applyconfigurations" + strings.Join(alias, "") - if extension.InputPath != "" { - importAliases[hack] = "applyconfigurations" + strings.Join(alias, "") - } - c.Kind.Extensions[i].InputPath = hack - c.Kind.Extensions[i].InputType += "ApplyConfiguration" - } - } - allVerbs := c.Kind.SupportedVerbs.Union(extensionVerbs) - - groupName := c.Group.Group.String() - if groupName == "core" { - groupName = "" - } - - m := map[string]interface{}{ - "group": c.Group, - "groupName": groupName, - "kind": &c.Kind, - "extraImports": extraImports, - "importAliases": importAliases, - "hasMethods": c.Kind.SupportedVerbs.Len() > 0 || len(c.Kind.Extensions) > 0, - "needsApply": allVerbs.Has("apply"), - "needsList": allVerbs.Has("list"), - "needsPatch": allVerbs.Has("patch"), - "apiPackagePath": c.APIPackagePath, - "packagePath": c.PackagePath, - "singleClusterClientPackagePath": c.SingleClusterClientPackagePath, - "singleClusterApplyConfigurationsPackagePath": c.SingleClusterApplyConfigurationsPackagePath, - "generateApplyVerbs": len(c.SingleClusterApplyConfigurationsPackagePath) > 0, - } - return templ.Execute(w, m) -} - -var fakeTypedClient = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package fake - -import ( - "github.com/kcp-dev/logicalcluster/v3" - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - - "k8s.io/apimachinery/pkg/runtime/schema" - -{{- range $path, $alias := .importAliases }} - {{if $path}}{{$alias}} "{{$path}}"{{end}} -{{end -}} - -{{- if .hasMethods }} - "context" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" -{{end}} - -{{- if "watch" | .kind.SupportedVerbs.Has }} - "k8s.io/apimachinery/pkg/watch" -{{end}} - -{{- if .needsList }} - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/testing" -{{end}} - -{{- if and .generateApplyVerbs .needsApply }} - "fmt" - "encoding/json" -{{end}} -{{- if or (and .generateApplyVerbs .needsApply) .needsPatch }} - "k8s.io/apimachinery/pkg/types" -{{end}} -{{- if and .generateApplyVerbs ("apply" | .kind.SupportedVerbs.Has) }} - applyconfigurations{{.group.PackageAlias}} "{{.singleClusterApplyConfigurationsPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" -{{end}} - -{{- if .kind.IsNamespaced}} - kcp{{.group.PackageAlias}} "{{.packagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" -{{end}} - {{.group.PackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" -) - -var {{.kind.Plural | lowerFirst}}Resource = schema.GroupVersionResource{Group: "{{.groupName}}", Version: "{{.group.Version.String | toLower}}", Resource: "{{.kind.Plural | toLower}}"} -var {{.kind.Plural | lowerFirst}}Kind = schema.GroupVersionKind{Group: "{{.groupName}}", Version: "{{.group.Version.String | toLower}}", Kind: "{{.kind.String}}"} - -type {{.kind.Plural | lowerFirst}}ClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *{{.kind.Plural | lowerFirst}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{if .kind.IsNamespaced}}kcp{{.group.PackageAlias}}.{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}} { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } -{{ if .kind.IsNamespaced }} - return &{{.kind.Plural | lowerFirst}}Namespacer{Fake: c.Fake, ClusterPath: clusterPath} -{{ else }} - return &{{.kind.Plural | lowerFirst}}Client{Fake: c.Fake, ClusterPath: clusterPath} -{{ end -}} -} - -{{ if .kind.SupportsListWatch }} -// List takes label and field selectors, and returns the list of {{.kind.Plural}} that match those selectors across all clusters. -func (c *{{.kind.Plural | lowerFirst}}ClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.PackageAlias}}.{{.kind.String}}List, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}ListAction({{.kind.Plural | lowerFirst}}Resource, {{.kind.Plural | lowerFirst}}Kind, logicalcluster.Wildcard, {{if .kind.IsNamespaced}}metav1.NamespaceAll, {{end}}opts), &{{.group.PackageAlias}}.{{.kind.String}}List{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &{{.group.PackageAlias}}.{{.kind.String}}List{ListMeta: obj.(*{{.group.PackageAlias}}.{{.kind.String}}List).ListMeta} - for _, item := range obj.(*{{.group.PackageAlias}}.{{.kind.String}}List).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested {{.kind.Plural}} across all clusters. -func (c *{{.kind.Plural | lowerFirst}}ClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}WatchAction({{.kind.Plural | lowerFirst}}Resource, logicalcluster.Wildcard, {{if .kind.IsNamespaced}}metav1.NamespaceAll, {{end}}opts)) -} -{{ end -}} - -{{ if .kind.IsNamespaced -}} -type {{.kind.Plural | lowerFirst}}Namespacer struct { - *kcptesting.Fake - ClusterPath logicalcluster.Path -} - -func (n *{{.kind.Plural | lowerFirst}}Namespacer) Namespace(namespace string) {{.group.PackageAlias}}client.{{.kind.String}}Interface { - return &{{.kind.Plural | lowerFirst}}Client{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} -} -{{ end -}} - -type {{.kind.Plural | lowerFirst}}Client struct { - *kcptesting.Fake - ClusterPath logicalcluster.Path - {{if .kind.IsNamespaced}}Namespace string{{end}} -} - -{{if "create" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Create(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.PackageAlias}}.{{.kind.String}}, opts metav1.CreateOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}CreateAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.PackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err -} -{{end -}} - -{{if "update" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Update(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.PackageAlias}}.{{.kind.String}}, opts metav1.UpdateOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}UpdateAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.PackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err -} -{{end -}} - -{{if "updateStatus" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) UpdateStatus(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.PackageAlias}}.{{.kind.String}}, opts metav1.UpdateOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}UpdateSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, "status", {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.PackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err -} -{{end -}} - -{{if "delete" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}DeleteActionWithOptions({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name, opts), &{{.group.PackageAlias}}.{{.kind.String}}{}) - return err -} -{{end -}} - -{{if "deleteCollection" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}DeleteCollectionAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}listOpts) - - _, err := c.Fake.Invokes(action, &{{.group.PackageAlias}}.{{.kind.String}}List{}) - return err -} -{{end -}} - -{{if "get" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Get(ctx context.Context, name string, options metav1.GetOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}GetAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name), &{{.group.PackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err -} -{{end -}} - -{{if "list" | .kind.SupportedVerbs.Has}} -// List takes label and field selectors, and returns the list of {{.kind.Plural}} that match those selectors. -func (c *{{.kind.Plural | lowerFirst}}Client) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.PackageAlias}}.{{.kind.String}}List, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}ListAction({{.kind.Plural | lowerFirst}}Resource, {{.kind.Plural | lowerFirst}}Kind, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}opts), &{{.group.PackageAlias}}.{{.kind.String}}List{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &{{.group.PackageAlias}}.{{.kind.String}}List{ListMeta: obj.(*{{.group.PackageAlias}}.{{.kind.String}}List).ListMeta} - for _, item := range obj.(*{{.group.PackageAlias}}.{{.kind.String}}List).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} -{{end -}} - -{{if "watch" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}WatchAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}opts)) -} -{{end -}} - -{{if "patch" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name, pt, data, subresources...), &{{.group.PackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err -} -{{end -}} - -{{if and .generateApplyVerbs ("apply" | .kind.SupportedVerbs.Has) }} -func (c *{{.kind.Plural | lowerFirst}}Client) Apply(ctx context.Context, applyConfiguration *applyconfigurations{{.group.PackageAlias}}.{{.kind.String}}ApplyConfiguration, opts metav1.ApplyOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}*name, types.ApplyPatchType, data), &{{.group.PackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err -} -{{end -}} - -{{if and .generateApplyVerbs ("applyStatus" | .kind.SupportedVerbs.Has) }} -func (c *{{.kind.Plural | lowerFirst}}Client) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurations{{.group.PackageAlias}}.{{.kind.String}}ApplyConfiguration, opts metav1.ApplyOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}*name, types.ApplyPatchType, data, "status"), &{{.group.PackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err -} -{{end -}} - -{{range .kind.Extensions}} -{{if eq .Verb "create"}} -func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, {{if .InputType}}{{.InputType | lowerFirst}} *{{index $.extraImports .InputPath}}.{{.InputType}}{{else}}{{$.kind.String | lowerFirst}} *{{.group.PackageAlias}}.{{$.kind.String}}{{end}}, opts metav1.CreateOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not $.kind.IsNamespaced}}Root{{end}}CreateSubresourceAction({{$.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{$.kind.String | lowerFirst}}Name, "{{.Subresource}}", {{if $.kind.IsNamespaced}}c.Namespace, {{end}}{{if .InputType}}{{.InputType | lowerFirst}}{{else}}{{$.kind.String | lowerFirst}}{{end}}), &{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}), err -} -{{end -}} - -{{if eq .Verb "update"}} -func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, {{if .InputType}}{{.InputType | lowerFirst}} *{{index $.extraImports .InputPath}}.{{.InputType}}{{else}}{{$.kind.String | lowerFirst}} *{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}{{end}}, opts metav1.UpdateOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not $.kind.IsNamespaced}}Root{{end}}UpdateSubresourceAction({{$.kind.Plural | lowerFirst}}Resource, c.ClusterPath, "{{.Subresource}}", {{if $.kind.IsNamespaced}}c.Namespace, {{end}}{{if .InputType}}{{.InputType | lowerFirst}}{{else}}{{$.kind.String | lowerFirst}}{{end}}), &{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}), err -} -{{end -}} - -{{if eq .Verb "get"}} -func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, options metav1.GetOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not $.kind.IsNamespaced}}Root{{end}}GetSubresourceAction({{$.kind.Plural | lowerFirst}}Resource, c.ClusterPath, "{{.Subresource}}", {{if $.kind.IsNamespaced}}c.Namespace, {{end}}{{$.kind.String | lowerFirst}}Name), &{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}), err -} -{{end -}} - -{{if eq .Verb "list"}} -// List takes label and field selectors, and returns the list of {{$.kind.Plural}} that match those selectors. -func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, opts metav1.ListOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}List, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not $.kind.IsNamespaced}}Root{{end}}ListAction({{$.kind.Plural | lowerFirst}}Resource, {{$.kind.Plural | lowerFirst}}Kind, c.ClusterPath, {{if $.kind.IsNamespaced}}c.Namespace, {{end}}opts), &{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}List{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}List{ListMeta: obj.(*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}List).ListMeta} - for _, item := range obj.(*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}List).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} -{{end -}} - -{{if eq .Verb "patch"}} -func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not $.kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{$.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if $.kind.IsNamespaced}}c.Namespace, {{end}}{{$.kind.String | lowerFirst}}Name, pt, data, subresources...), &{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}), err -} -{{end -}} - -{{if and $.generateApplyVerbs (eq .Verb "apply") }} -func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, applyConfiguration {{if .InputType}}*{{index $.extraImports .InputPath}}.{{.InputType}}{{else}}*applyconfigurations{{$.group.PackageAlias}}.{{$.kind.String}}ApplyConfiguration,{{end}}, opts metav1.ApplyOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.New{{if not $.kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{$.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if $.kind.IsNamespaced}}c.Namespace, {{end}}*name, types.ApplyPatchType, data), &{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}), err -} -{{end -}} -{{end -}} -` diff --git a/pkg/internal/clientgen/group.go b/pkg/internal/clientgen/group.go deleted file mode 100644 index 9421c1733..000000000 --- a/pkg/internal/clientgen/group.go +++ /dev/null @@ -1,122 +0,0 @@ -package clientgen - -import ( - "io" - "strings" - "text/template" - - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -type Group struct { - // Group is the group in this client. - Group types.GroupVersionInfo - - // Kinds are the kinds in the group. - Kinds []parser.Kind - - // SingleClusterClientPackagePath is the root directory under which single-cluster-aware clients exist. - // e.g. "k8s.io/client-go/kubernetes" - SingleClusterClientPackagePath string -} - -func (g *Group) WriteContent(w io.Writer) error { - templ, err := template.New("group").Funcs(template.FuncMap{ - "upperFirst": util.UpperFirst, - "lowerFirst": util.LowerFirst, - "toLower": strings.ToLower, - }).Parse(group) - if err != nil { - return err - } - - m := map[string]interface{}{ - "group": g.Group, - "kinds": g.Kinds, - "singleClusterClientPackagePath": g.SingleClusterClientPackagePath, - } - return templ.Execute(w, m) -} - -var group = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package {{.group.Version.PackageName}} - -import ( - "net/http" - - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" - - "k8s.io/client-go/rest" - - {{.group.PackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" -) - -type {{.group.GroupGoName}}{{.group.Version}}ClusterInterface interface { - {{.group.GroupGoName}}{{.group.Version}}ClusterScoper -{{range .kinds}} {{.Plural}}ClusterGetter -{{end -}} -} - -type {{.group.GroupGoName}}{{.group.Version}}ClusterScoper interface { - Cluster(logicalcluster.Path) {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface -} - -type {{.group.GroupGoName}}{{.group.Version}}ClusterClient struct { - clientCache kcpclient.Cache[*{{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Client] -} - -func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - return c.clientCache.ClusterOrDie(clusterPath) -} - -{{ range .kinds}} -func (c *{{$.group.GroupGoName}}{{$.group.Version}}ClusterClient) {{.Plural}}() {{.String}}ClusterInterface { - return &{{.Plural | lowerFirst}}ClusterInterface{clientCache: c.clientCache} -} -{{end -}} - -// NewForConfig creates a new {{.group.GroupGoName}}{{.group.Version}}ClusterClient for the given config. -// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), -// where httpClient was generated with rest.HTTPClientFor(c). -func NewForConfig(c *rest.Config) (*{{.group.GroupGoName}}{{.group.Version}}ClusterClient, error) { - client, err := rest.HTTPClientFor(c) - if err != nil { - return nil, err - } - return NewForConfigAndClient(c, client) -} - -// NewForConfigAndClient creates a new {{.group.GroupGoName}}{{.group.Version}}ClusterClient for the given config and http client. -// Note the http client provided takes precedence over the configured transport values. -func NewForConfigAndClient(c *rest.Config, h *http.Client) (*{{.group.GroupGoName}}{{.group.Version}}ClusterClient, error) { - cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*{{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Client]{ - NewForConfigAndClient: {{.group.PackageAlias}}.NewForConfigAndClient, - }) - if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { - return nil, err - } - return &{{.group.GroupGoName}}{{.group.Version}}ClusterClient{clientCache: cache}, nil -} - -// NewForConfigOrDie creates a new {{.group.GroupGoName}}{{.group.Version}}ClusterClient for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *{{.group.GroupGoName}}{{.group.Version}}ClusterClient { - client, err := NewForConfig(c) - if err != nil { - panic(err) - } - return client -} -` diff --git a/pkg/internal/clientgen/scheme.go b/pkg/internal/clientgen/scheme.go deleted file mode 100644 index 6b5524e35..000000000 --- a/pkg/internal/clientgen/scheme.go +++ /dev/null @@ -1,86 +0,0 @@ -package clientgen - -import ( - "io" - "strings" - "text/template" - - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -type Scheme struct { - // Groups are the groups in this client-set. - Groups []types.GroupVersionInfo - - // APIPackagePath is the root directory under which API types exist. - // e.g. "k8s.io/api" - APIPackagePath string -} - -func (c *Scheme) WriteContent(w io.Writer) error { - templ, err := template.New("scheme").Funcs(template.FuncMap{ - "upperFirst": util.UpperFirst, - "lowerFirst": util.LowerFirst, - "toLower": strings.ToLower, - }).Parse(scheme) - if err != nil { - return err - } - - m := map[string]interface{}{ - "groups": c.Groups, - "apiPackagePath": c.APIPackagePath, - } - return templ.Execute(w, m) -} - -var scheme = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package scheme - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/runtime/serializer" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - -{{range .groups}} {{.PackageAlias}} "{{$.apiPackagePath}}/{{.Group.PackageName}}/{{.Version.PackageName}}" -{{end -}} -) - -var Scheme = runtime.NewScheme() -var Codecs = serializer.NewCodecFactory(Scheme) -var ParameterCodec = runtime.NewParameterCodec(Scheme) -var localSchemeBuilder = runtime.SchemeBuilder{ -{{range .groups}} {{.PackageAlias}}.AddToScheme, -{{end -}} -} - -// AddToScheme adds all types of this clientset into the given scheme. This allows composition -// of clientsets, like in: -// -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) -// -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) -// -// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types -// correctly. -var AddToScheme = localSchemeBuilder.AddToScheme - -func init() { - metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) - utilruntime.Must(AddToScheme(Scheme)) -} -` diff --git a/pkg/internal/clientgen/type.go b/pkg/internal/clientgen/type.go deleted file mode 100644 index bb5a95e33..000000000 --- a/pkg/internal/clientgen/type.go +++ /dev/null @@ -1,134 +0,0 @@ -package clientgen - -import ( - "io" - "strings" - "text/template" - - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -type TypedClient struct { - // Group is the group in this client. - Group types.GroupVersionInfo - - // Kind is the kinds in this file. - Kind parser.Kind - - // APIPackagePath is the root directory under which API types exist. - // e.g. "k8s.io/api" - APIPackagePath string - - // SingleClusterClientPackagePath is the root directory under which single-cluster-aware clients exist. - // e.g. "k8s.io/client-go/kubernetes" - SingleClusterClientPackagePath string -} - -func (c *TypedClient) WriteContent(w io.Writer) error { - templ, err := template.New("fakeTypedClient").Funcs(template.FuncMap{ - "upperFirst": util.UpperFirst, - "lowerFirst": util.LowerFirst, - "toLower": strings.ToLower, - }).Parse(typedClient) - if err != nil { - return err - } - - m := map[string]interface{}{ - "group": c.Group, - "kind": &c.Kind, - "apiPackagePath": c.APIPackagePath, - "singleClusterClientPackagePath": c.SingleClusterClientPackagePath, - } - return templ.Execute(w, m) -} - -var typedClient = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package {{.group.Version.PackageName}} - -import ( - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" - -{{- if .kind.SupportsListWatch }} - "context" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" -{{end}} - - {{.group.PackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" -) - -// {{.kind.Plural}}ClusterGetter has a method to return a {{.kind.String}}ClusterInterface. -// A group's cluster client should implement this interface. -type {{.kind.Plural}}ClusterGetter interface { - {{.kind.Plural}}() {{.kind.String}}ClusterInterface -} - -{{ if .kind.SupportsListWatch -}} -// {{.kind.String}}ClusterInterface can operate on {{.kind.Plural}} across all clusters, -// or scope down to one cluster and return a {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}}. -{{ else -}} -// {{.kind.String}}ClusterInterface can scope down to one cluster and return a {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}}. -{{ end -}} -type {{.kind.String}}ClusterInterface interface { - Cluster(logicalcluster.Path) {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}} -{{- if .kind.SupportsListWatch }} - List(ctx context.Context, opts metav1.ListOptions) (*{{.group.PackageAlias}}.{{.kind.String}}List, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) -{{ end -}} -} - -type {{.kind.Plural | lowerFirst}}ClusterInterface struct { - clientCache kcpclient.Cache[*{{.group.PackageAlias}}client.{{.group.GroupGoName}}{{.group.Version}}Client] -} - -// Cluster scopes the client down to a particular cluster. -func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) Cluster(clusterPath logicalcluster.Path) {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}} { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } -{{ if .kind.IsNamespaced }} - return &{{.kind.Plural | lowerFirst}}Namespacer{clientCache: c.clientCache, clusterPath: clusterPath} -{{ else }} - return c.clientCache.ClusterOrDie(clusterPath).{{.kind.Plural}}() -{{ end -}} -} - -{{ if .kind.SupportsListWatch }} -// List returns the entire collection of all {{.kind.Plural}} across all clusters. -func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.PackageAlias}}.{{.kind.String}}List, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).{{.kind.Plural}}({{if .kind.IsNamespaced }}metav1.NamespaceAll{{end}}).List(ctx, opts) -} - -// Watch begins to watch all {{.kind.Plural}} across all clusters. -func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).{{.kind.Plural}}({{if .kind.IsNamespaced }}metav1.NamespaceAll{{end}}).Watch(ctx, opts) -} -{{ end -}} - -{{ if .kind.IsNamespaced -}} -// {{.kind.Plural}}Namespacer can scope to objects within a namespace, returning a {{.group.PackageAlias}}client.{{.kind.String}}Interface. -type {{.kind.Plural}}Namespacer interface { - Namespace(string) {{.group.PackageAlias}}client.{{.kind.String}}Interface -} - -type {{.kind.Plural | lowerFirst}}Namespacer struct { - clientCache kcpclient.Cache[*{{.group.PackageAlias}}client.{{.group.GroupGoName}}{{.group.Version}}Client] - clusterPath logicalcluster.Path -} - -func (n *{{.kind.Plural | lowerFirst}}Namespacer) Namespace(namespace string) {{.group.PackageAlias}}client.{{.kind.String}}Interface { - return n.clientCache.ClusterOrDie(n.clusterPath).{{.kind.Plural}}(namespace) -} -{{ end -}} -` diff --git a/pkg/internal/informergen/factory.go b/pkg/internal/informergen/factory.go deleted file mode 100644 index a8c2eb029..000000000 --- a/pkg/internal/informergen/factory.go +++ /dev/null @@ -1,485 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package informergen - -import ( - "io" - "text/template" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" -) - -type Factory struct { - // Groups are the groups in this informer factory. - Groups []parser.Group - - // PackagePath is the package under which these informers will be exposed. - // e.g. "github.com/kcp-dev/client-go/clients/informers" - // TODO(skuznets) we should be able to figure this out from the output dir, ideally - PackagePath string - - // ClientsetPackagePath is the package under which the cluster-aware client-set will be exposed. - // e.g. "github.com/kcp-dev/client-go/clients/clientset/versioned" - // TODO(skuznets) we should be able to figure this out from the output dir, ideally - ClientsetPackagePath string - - // SingleClusterClientPackagePath is the root directory under which single-cluster-aware clients exist. - // e.g. "k8s.io/client-go/kubernetes" - SingleClusterClientPackagePath string `marker:""` - - // SingleClusterInformerPackagePath is the package under which the cluster-unaware listers are exposed. - // e.g. "k8s.io/client-go/informers" - SingleClusterInformerPackagePath string -} - -func (f *Factory) WriteContent(w io.Writer) error { - templ, err := template.New("factory").Funcs(templateFuncs).Parse(sharedInformerFactoryStruct) - if err != nil { - return err - } - - m := map[string]interface{}{ - "groups": f.Groups, - "packagePath": f.PackagePath, - "clientsetPackagePath": f.ClientsetPackagePath, - "singleClusterClientPackagePath": f.SingleClusterClientPackagePath, - "singleClusterInformerPackagePath": f.SingleClusterInformerPackagePath, - "useUpstreamInterfaces": f.SingleClusterInformerPackagePath != "", - } - return templ.Execute(w, m) -} - -var sharedInformerFactoryStruct = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package informers - -import ( - "reflect" - "sync" - "time" - - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/tools/cache" - - clientset "{{.clientsetPackagePath}}" - {{if not .useUpstreamInterfaces -}} - scopedclientset "{{.singleClusterClientPackagePath}}" - {{end -}} - {{if .useUpstreamInterfaces -}} - upstreaminformers "{{.singleClusterInformerPackagePath}}" - {{end -}} - -{{range .groups}} {{.Group.PackageName}}informers "{{$.packagePath}}/{{.Group.PackageName}}" -{{end -}} - - "{{.packagePath}}/internalinterfaces" -) - -// SharedInformerOption defines the functional option type for SharedInformerFactory. -type SharedInformerOption func(*SharedInformerOptions) *SharedInformerOptions - -type SharedInformerOptions struct { - customResync map[reflect.Type]time.Duration - tweakListOptions internalinterfaces.TweakListOptionsFunc - {{if not .useUpstreamInterfaces -}} - namespace string - {{end -}} -} - -type sharedInformerFactory struct { - client clientset.ClusterInterface - tweakListOptions internalinterfaces.TweakListOptionsFunc - lock sync.Mutex - defaultResync time.Duration - customResync map[reflect.Type]time.Duration - - informers map[reflect.Type]kcpcache.ScopeableSharedIndexInformer - // startedInformers is used for tracking which informers have been started. - // This allows Start() to be called multiple times safely. - startedInformers map[reflect.Type]bool - // wg tracks how many goroutines were started. - wg sync.WaitGroup - // shuttingDown is true when Shutdown has been called. It may still be running - // because it needs to wait for goroutines. - shuttingDown bool -} - -// WithCustomResyncConfig sets a custom resync period for the specified informer types. -func WithCustomResyncConfig(resyncConfig map[metav1.Object]time.Duration) SharedInformerOption { - return func(opts *SharedInformerOptions) *SharedInformerOptions { - for k, v := range resyncConfig { - opts.customResync[reflect.TypeOf(k)] = v - } - return opts - } -} - -// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. -func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { - return func(opts *SharedInformerOptions) *SharedInformerOptions { - opts.tweakListOptions = tweakListOptions - return opts - } -} - -// NewSharedInformerFactory constructs a new instance of SharedInformerFactory for all namespaces. -func NewSharedInformerFactory(client clientset.ClusterInterface, defaultResync time.Duration) SharedInformerFactory { - return NewSharedInformerFactoryWithOptions(client, defaultResync) -} - -// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. -func NewSharedInformerFactoryWithOptions(client clientset.ClusterInterface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { - factory := &sharedInformerFactory{ - client: client, - defaultResync: defaultResync, - informers: make(map[reflect.Type]kcpcache.ScopeableSharedIndexInformer), - startedInformers: make(map[reflect.Type]bool), - customResync: make(map[reflect.Type]time.Duration), - } - - opts := &SharedInformerOptions{ - customResync: make(map[reflect.Type]time.Duration), - } - - // Apply all options - for _, opt := range options { - opts = opt(opts) - } - - // Forward options to the factory - factory.customResync = opts.customResync - factory.tweakListOptions = opts.tweakListOptions - - return factory -} - -// Start initializes all requested informers. -func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { - f.lock.Lock() - defer f.lock.Unlock() - - if f.shuttingDown { - return - } - - for informerType, informer := range f.informers { - if !f.startedInformers[informerType] { - f.wg.Add(1) - // We need a new variable in each loop iteration, - // otherwise the goroutine would use the loop variable - // and that keeps changing. - informer := informer - go func() { - defer f.wg.Done() - informer.Run(stopCh) - }() - f.startedInformers[informerType] = true - } - } -} - -func (f *sharedInformerFactory) Shutdown() { - f.lock.Lock() - f.shuttingDown = true - f.lock.Unlock() - - // Will return immediately if there is nothing to wait for. - f.wg.Wait() -} - -// WaitForCacheSync waits for all started informers' cache were synced. -func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { - informers := func()map[reflect.Type]kcpcache.ScopeableSharedIndexInformer{ - f.lock.Lock() - defer f.lock.Unlock() - - informers := map[reflect.Type]kcpcache.ScopeableSharedIndexInformer{} - for informerType, informer := range f.informers { - if f.startedInformers[informerType] { - informers[informerType] = informer - } - } - return informers - }() - - res := map[reflect.Type]bool{} - for informType, informer := range informers { - res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) - } - return res -} - -// InformerFor returns the SharedIndexInformer for obj. -func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer { - f.lock.Lock() - defer f.lock.Unlock() - - informerType := reflect.TypeOf(obj) - informer, exists := f.informers[informerType] - if exists { - return informer - } - - resyncPeriod, exists := f.customResync[informerType] - if !exists { - resyncPeriod = f.defaultResync - } - - informer = newFunc(f.client, resyncPeriod) - f.informers[informerType] = informer - - return informer -} - -type ScopedDynamicSharedInformerFactory interface { - // ForResource gives generic access to a shared informer of the matching type. - ForResource(resource schema.GroupVersionResource) ({{if .useUpstreamInterfaces}}upstreaminformers.{{end}}GenericInformer, error) - - // Start initializes all requested informers. They are handled in goroutines - // which run until the stop channel gets closed. - Start(stopCh <-chan struct{}) -} - -// SharedInformerFactory provides shared informers for resources in all known -// API group versions. -// -// It is typically used like this: -// -// ctx, cancel := context.Background() -// defer cancel() -// factory := NewSharedInformerFactoryWithOptions(client, resyncPeriod) -// defer factory.Shutdown() // Returns immediately if nothing was started. -// genericInformer := factory.ForResource(resource) -// typedInformer := factory.SomeAPIGroup().V1().SomeType() -// factory.Start(ctx.Done()) // Start processing these informers. -// synced := factory.WaitForCacheSync(ctx.Done()) -// for v, ok := range synced { -// if !ok { -// fmt.Fprintf(os.Stderr, "caches failed to sync: %v", v) -// return -// } -// } -// -// // Creating informers can also be created after Start, but then -// // Start must be called again: -// anotherGenericInformer := factory.ForResource(resource) -// factory.Start(ctx.Done()) -type SharedInformerFactory interface { - internalinterfaces.SharedInformerFactory - - Cluster(logicalcluster.Name) ScopedDynamicSharedInformerFactory - - // Start initializes all requested informers. They are handled in goroutines - // which run until the stop channel gets closed. - Start(stopCh <-chan struct{}) - - // Shutdown marks a factory as shutting down. At that point no new - // informers can be started anymore and Start will return without - // doing anything. - // - // In addition, Shutdown blocks until all goroutines have terminated. For that - // to happen, the close channel(s) that they were started with must be closed, - // either before Shutdown gets called or while it is waiting. - // - // Shutdown may be called multiple times, even concurrently. All such calls will - // block until all goroutines have terminated. - Shutdown() - - // ForResource gives generic access to a shared informer of the matching type. - ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) - - // WaitForCacheSync blocks until all started informers' caches were synced - // or the stop channel gets closed. - WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool - - // InformerFor returns the SharedIndexInformer for obj. - InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer - -{{range .groups}} {{.GoName}}() {{.Group.PackageName}}informers.ClusterInterface -{{end -}} -} - -{{range .groups}} -func (f *sharedInformerFactory) {{.GoName}}() {{.Group.PackageName}}informers.ClusterInterface { - return {{.Group.PackageName}}informers.New(f, f.tweakListOptions) -} -{{end}} - -func (f *sharedInformerFactory) Cluster(clusterName logicalcluster.Name) ScopedDynamicSharedInformerFactory { - return &scopedDynamicSharedInformerFactory{ - sharedInformerFactory: f, - clusterName: clusterName, - } -} - -type scopedDynamicSharedInformerFactory struct { - *sharedInformerFactory - clusterName logicalcluster.Name -} - -func (f *scopedDynamicSharedInformerFactory) ForResource(resource schema.GroupVersionResource) ({{if .useUpstreamInterfaces}}upstreaminformers.{{end}}GenericInformer, error) { - clusterInformer, err := f.sharedInformerFactory.ForResource(resource) - if err != nil { - return nil, err - } - return clusterInformer.Cluster(f.clusterName), nil -} - -func (f *scopedDynamicSharedInformerFactory) Start(stopCh <-chan struct{}) { - f.sharedInformerFactory.Start(stopCh) -} - -{{if not .useUpstreamInterfaces -}} -// WithNamespace limits the SharedInformerFactory to the specified namespace. -func WithNamespace(namespace string) SharedInformerOption { - return func(opts *SharedInformerOptions) *SharedInformerOptions { - opts.namespace = namespace - return opts - } -} - -type sharedScopedInformerFactory struct { - client scopedclientset.Interface - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc - lock sync.Mutex - defaultResync time.Duration - customResync map[reflect.Type]time.Duration - - informers map[reflect.Type]cache.SharedIndexInformer - // startedInformers is used for tracking which informers have been started. - // This allows Start() to be called multiple times safely. - startedInformers map[reflect.Type]bool -} - -// NewSharedScopedInformerFactory constructs a new instance of SharedInformerFactory for some or all namespaces. -func NewSharedScopedInformerFactory(client scopedclientset.Interface, defaultResync time.Duration, namespace string) SharedScopedInformerFactory { - return NewSharedScopedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace)) -} - -// NewSharedScopedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. -func NewSharedScopedInformerFactoryWithOptions(client scopedclientset.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedScopedInformerFactory { - factory := &sharedScopedInformerFactory{ - client: client, - defaultResync: defaultResync, - informers: make(map[reflect.Type]cache.SharedIndexInformer), - startedInformers: make(map[reflect.Type]bool), - customResync: make(map[reflect.Type]time.Duration), - } - - opts := &SharedInformerOptions{ - customResync: make(map[reflect.Type]time.Duration), - } - - // Apply all options - for _, opt := range options { - opts = opt(opts) - } - - // Forward options to the factory - factory.customResync = opts.customResync - factory.tweakListOptions = opts.tweakListOptions - factory.namespace = opts.namespace - - return factory -} - -// Start initializes all requested informers. -func (f *sharedScopedInformerFactory) Start(stopCh <-chan struct{}) { - f.lock.Lock() - defer f.lock.Unlock() - - for informerType, informer := range f.informers { - if !f.startedInformers[informerType] { - go informer.Run(stopCh) - f.startedInformers[informerType] = true - } - } -} - -// WaitForCacheSync waits for all started informers' cache were synced. -func (f *sharedScopedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { - informers := func()map[reflect.Type]cache.SharedIndexInformer{ - f.lock.Lock() - defer f.lock.Unlock() - - informers := map[reflect.Type]cache.SharedIndexInformer{} - for informerType, informer := range f.informers { - if f.startedInformers[informerType] { - informers[informerType] = informer - } - } - return informers - }() - - res := map[reflect.Type]bool{} - for informType, informer := range informers { - res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) - } - return res -} - -// InformerFor returns the SharedIndexInformer for obj. -func (f *sharedScopedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewScopedInformerFunc) cache.SharedIndexInformer { - f.lock.Lock() - defer f.lock.Unlock() - - informerType := reflect.TypeOf(obj) - informer, exists := f.informers[informerType] - if exists { - return informer - } - - resyncPeriod, exists := f.customResync[informerType] - if !exists { - resyncPeriod = f.defaultResync - } - - informer = newFunc(f.client, resyncPeriod) - f.informers[informerType] = informer - - return informer -} - -// SharedScopedInformerFactory provides shared informers for resources in all known -// API group versions, scoped to one workspace. -type SharedScopedInformerFactory interface { - internalinterfaces.SharedScopedInformerFactory - ForResource(resource schema.GroupVersionResource) (GenericInformer, error) - WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool - -{{range .groups}} {{.GoName}}() {{.Group.PackageName}}informers.Interface -{{end -}} -} - - -{{range .groups}} -func (f *sharedScopedInformerFactory) {{.GoName}}() {{.Group.PackageName}}informers.Interface { - return {{.Group.PackageName}}informers.NewScoped(f, f.namespace, f.tweakListOptions) -} -{{end}} -{{end}} -` diff --git a/pkg/internal/informergen/factoryinterface.go b/pkg/internal/informergen/factoryinterface.go deleted file mode 100644 index 77a415f34..000000000 --- a/pkg/internal/informergen/factoryinterface.go +++ /dev/null @@ -1,98 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package informergen - -import ( - "io" - "text/template" -) - -type FactoryInterface struct { - // ClientsetPackagePath is the package under which the cluster-aware client-set will be exposed. - // TODO(skuznets) we should be able to figure this out from the output dir, ideally - ClientsetPackagePath string - - // SingleClusterClientPackagePath is the root directory under which single-cluster-aware clients exist. - // e.g. "k8s.io/client-go/kubernetes" - SingleClusterClientPackagePath string `marker:""` - - // UseUpstreamInterfaces determines if we're generating against existing single-cluster informer interfaces or not. - UseUpstreamInterfaces bool -} - -func (f *FactoryInterface) WriteContent(w io.Writer) error { - templ, err := template.New("factoryInterface").Funcs(templateFuncs).Parse(externalSharedInformerFactoryInterface) - if err != nil { - return err - } - - m := map[string]interface{}{ - "clientsetPackagePath": f.ClientsetPackagePath, - "singleClusterClientPackagePath": f.SingleClusterClientPackagePath, - "useUpstreamInterfaces": f.UseUpstreamInterfaces, - } - return templ.Execute(w, m) -} - -var externalSharedInformerFactoryInterface = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package internalinterfaces - -import ( - time "time" - - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - {{if not .useUpstreamInterfaces -}} - "k8s.io/client-go/tools/cache" - {{end}} - - clientset "{{.clientsetPackagePath}}" - {{if not .useUpstreamInterfaces -}} - scopedclientset "{{.singleClusterClientPackagePath}}" - {{end}} -) - -// NewInformerFunc takes clientset.ClusterInterface and time.Duration to return a ScopeableSharedIndexInformer. -type NewInformerFunc func(clientset.ClusterInterface, time.Duration) kcpcache.ScopeableSharedIndexInformer - -// SharedInformerFactory a small interface to allow for adding an informer without an import cycle -type SharedInformerFactory interface { - Start(stopCh <-chan struct{}) - InformerFor(obj runtime.Object, newFunc NewInformerFunc) kcpcache.ScopeableSharedIndexInformer -} - -{{if not .useUpstreamInterfaces -}} -// NewScopedInformerFunc takes scopedclientset.Interface and time.Duration to return a SharedIndexInformer. -type NewScopedInformerFunc func(scopedclientset.Interface, time.Duration) cache.SharedIndexInformer - -// SharedScopedInformerFactory a small interface to allow for adding an informer without an import cycle -type SharedScopedInformerFactory interface { - Start(stopCh <-chan struct{}) - InformerFor(obj runtime.Object, newFunc NewScopedInformerFunc) cache.SharedIndexInformer -} -{{end}} - -// TweakListOptionsFunc is a function that transforms a metav1.ListOptions. -type TweakListOptionsFunc func(*metav1.ListOptions) -` diff --git a/pkg/internal/informergen/generic.go b/pkg/internal/informergen/generic.go deleted file mode 100644 index 18ce9b072..000000000 --- a/pkg/internal/informergen/generic.go +++ /dev/null @@ -1,166 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package informergen - -import ( - "io" - "text/template" - - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" -) - -type Generic struct { - // Groups are the groups in this informer factory. - Groups []types.GroupVersionInfo - - // GroupVersionKinds are all the kinds we need to support,indexed by group and version. - GroupVersionKinds map[types.Group]map[types.Version][]parser.Kind - - // APIPackagePath is the root directory under which API types exist. - // e.g. "k8s.io/api" - APIPackagePath string - - // SingleClusterInformerPackagePath is the package under which the cluster-unaware listers are exposed. - // e.g. "k8s.io/client-go/informers" - SingleClusterInformerPackagePath string -} - -func (g *Generic) WriteContent(w io.Writer) error { - templ, err := template.New("generic").Funcs(templateFuncs).Parse(genericInformer) - if err != nil { - return err - } - - m := map[string]interface{}{ - "groups": g.Groups, - "groupVersionKinds": g.GroupVersionKinds, - "apiPackagePath": g.APIPackagePath, - "singleClusterInformerPackagePath": g.SingleClusterInformerPackagePath, - "useUpstreamInterfaces": g.SingleClusterInformerPackagePath != "", - } - return templ.Execute(w, m) -} - -var genericInformer = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package informers - -import ( - "fmt" - - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/tools/cache" - - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" - - {{if .useUpstreamInterfaces -}} - upstreaminformers "{{.singleClusterInformerPackagePath}}" - {{end -}} - -{{range .groups}} {{.PackageAlias}} "{{$.apiPackagePath}}/{{.Group.PackageName}}/{{.Version.PackageName}}" -{{end -}} -) - -type GenericClusterInformer interface { - Cluster(logicalcluster.Name) {{if .useUpstreamInterfaces}}upstreaminformers.{{end}}GenericInformer - Informer() kcpcache.ScopeableSharedIndexInformer - Lister() kcpcache.GenericClusterLister -} - -{{ if not .useUpstreamInterfaces }} -type GenericInformer interface { - Informer() cache.SharedIndexInformer - Lister() cache.GenericLister -} -{{end }} - -type genericClusterInformer struct { - informer kcpcache.ScopeableSharedIndexInformer - resource schema.GroupResource -} - -// Informer returns the SharedIndexInformer. -func (f *genericClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.informer -} - -// Lister returns the GenericClusterLister. -func (f *genericClusterInformer) Lister() kcpcache.GenericClusterLister { - return kcpcache.NewGenericClusterLister(f.Informer().GetIndexer(), f.resource) -} - -// Cluster scopes to a GenericInformer. -func (f *genericClusterInformer) Cluster(clusterName logicalcluster.Name) {{if .useUpstreamInterfaces}}upstreaminformers.{{end}}GenericInformer { - return &genericInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().ByCluster(clusterName), - } -} - -type genericInformer struct { - informer cache.SharedIndexInformer - lister cache.GenericLister -} - -// Informer returns the SharedIndexInformer. -func (f *genericInformer) Informer() cache.SharedIndexInformer { - return f.informer -} - -// Lister returns the GenericLister. -func (f *genericInformer) Lister() cache.GenericLister { - return f.lister -} - -// ForResource gives generic access to a shared informer of the matching type -// TODO extend this to unknown resources with a client pool -func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) { - switch resource { -{{range $group := .groups}} // Group={{.Group.NonEmpty}}, Version={{.Version}} -{{range $kind := index (index $.groupVersionKinds .Group) .Version}} case {{$group.PackageAlias}}.SchemeGroupVersion.WithResource("{{$kind.Plural|toLower}}"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.{{$group.GroupGoName}}().{{$group.Version}}().{{$kind.Plural}}().Informer()}, nil -{{end -}} -{{end -}} - } - - return nil, fmt.Errorf("no informer found for %v", resource) -} - -{{if not .useUpstreamInterfaces -}} -// ForResource gives generic access to a shared informer of the matching type -// TODO extend this to unknown resources with a client pool -func (f *sharedScopedInformerFactory) ForResource(resource schema.GroupVersionResource) ({{if .useUpstreamInterfaces}}upstreaminformers.{{end}}GenericInformer, error) { - switch resource { -{{range $group := .groups}} // Group={{.Group.NonEmpty}}, Version={{.Version}} -{{range $kind := index (index $.groupVersionKinds .Group) .Version}} case {{$group.PackageAlias}}.SchemeGroupVersion.WithResource("{{$kind.Plural|toLower}}"): - informer := f.{{$group.GroupGoName}}().{{$group.Version}}().{{$kind.Plural}}().Informer() - return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil -{{end -}} -{{end -}} - } - - return nil, fmt.Errorf("no informer found for %v", resource) -} -{{end}} -` diff --git a/pkg/internal/informergen/groupinterface.go b/pkg/internal/informergen/groupinterface.go deleted file mode 100644 index 9848d4336..000000000 --- a/pkg/internal/informergen/groupinterface.go +++ /dev/null @@ -1,120 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package informergen - -import ( - "io" - "text/template" - - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" -) - -type GroupInterface struct { - // Group is the group for which we're generating interfaces - Group parser.Group - - // Versions are the versions of this group for which we're generating interfaces - Versions []types.Version - - // PackagePath is the package under which these informers will be exposed. - // e.g. "github.com/kcp-dev/client-go/clients/informers" - // TODO(skuznets) we should be able to figure this out from the output dir, ideally - PackagePath string - - // UseUpstreamInterfaces determines if we're generating against existing single-cluster informer interfaces or not. - UseUpstreamInterfaces bool -} - -func (g GroupInterface) WriteContent(w io.Writer) error { - templ, err := template.New("groupInterface").Funcs(templateFuncs).Parse(groupInterface) - if err != nil { - return err - } - - m := map[string]interface{}{ - "group": g.Group, - "packagePath": g.PackagePath, - "versions": g.Versions, - "useUpstreamInterfaces": g.UseUpstreamInterfaces, - } - return templ.Execute(w, m) -} - -var groupInterface = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package {{.group.Group.PackageName}} - -import ( -{{range .versions}} "{{$.packagePath}}/{{$.group.Group.PackageName}}/{{.PackageName}}" -{{end -}} - - "{{.packagePath}}/internalinterfaces" -) - -type ClusterInterface interface { -{{range .versions}} // {{.String}} provides access to the shared informers in {{.String}}. - {{.String}}() {{.PackageName}}.ClusterInterface -{{end -}} -} - -type group struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new ClusterInterface. -func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { - return &group{factory: f, tweakListOptions: tweakListOptions} -} - -{{range .versions}}// {{.String}} returns a new {{.PackageName}}.ClusterInterface. -func (g *group) {{.String}}() {{.PackageName}}.ClusterInterface { - return {{.PackageName}}.New(g.factory, g.tweakListOptions) -} -{{end -}} - -{{if not .useUpstreamInterfaces -}} -type Interface interface { -{{range .versions}} // {{.String}} provides access to the shared informers in {{.String}}. - {{.String}}() {{.PackageName}}.Interface -{{end -}} -} - -type scopedGroup struct { - factory internalinterfaces.SharedScopedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// New returns a new Interface. -func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &scopedGroup{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -{{range .versions}}// {{.String}} returns a new {{.PackageName}}.ClusterInterface. -func (g *scopedGroup) {{.String}}() {{.PackageName}}.Interface { - return {{.PackageName}}.NewScoped(g.factory, g.namespace, g.tweakListOptions) -} -{{end -}} -{{end}} -` diff --git a/pkg/internal/informergen/informer.go b/pkg/internal/informergen/informer.go deleted file mode 100644 index 91b2b35f8..000000000 --- a/pkg/internal/informergen/informer.go +++ /dev/null @@ -1,267 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package informergen - -import ( - "io" - "text/template" - - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" -) - -type Informer struct { - // Group is the group in this informer. - Group types.GroupVersionInfo - - // Kind is the kind in this file. - Kind parser.Kind - - // APIPackagePath is the root directory under which API types exist. - // e.g. "k8s.io/api" - APIPackagePath string - - // PackagePath is the package under which these informers will be exposed. - // e.g. "github.com/kcp-dev/client-go/clients/informers" - // TODO(skuznets) we should be able to figure this out from the output dir, ideally - PackagePath string - - // ClientsetPackagePath is the package under which the cluster-aware client-set will be exposed. - // e.g. "github.com/kcp-dev/client-go/kubernetes" - // TODO(skuznets) we should be able to figure this out from the output dir, ideally - ClientsetPackagePath string - - // ListerPackagePath is the package under which the cluster-aware listers will be exposed. - // e.g. "github.com/kcp-dev/client-go/clients/listers" - // TODO(skuznets) we should be able to figure this out from the output dir, ideally - ListerPackagePath string - - // SingleClusterClientPackagePath is the root directory under which single-cluster-aware clients exist. - // e.g. "k8s.io/client-go/kubernetes" - SingleClusterClientPackagePath string `marker:""` - - // SingleClusterInformerPackagePath is the package under which the cluster-unaware listers are exposed. - // e.g. "k8s.io/client-go/informers" - SingleClusterInformerPackagePath string - - // SingleClusterListerPackagePath is the fully qualified Go package name under which the (pre-existing) - // listers for single-cluster contexts are defined. Option. e.g. "k8s.io/client-go/listers" - SingleClusterListerPackagePath string -} - -func (i *Informer) WriteContent(w io.Writer) error { - templ, err := template.New("informer").Funcs(templateFuncs).Parse(informer) - if err != nil { - return err - } - m := map[string]interface{}{ - "group": i.Group, - "kind": &i.Kind, - "packagePath": i.PackagePath, - "clientsetPackagePath": i.ClientsetPackagePath, - "apiPackagePath": i.APIPackagePath, - "listerPackagePath": i.ListerPackagePath, - "singleClusterClientPackagePath": i.SingleClusterClientPackagePath, - "singleClusterInformerPackagePath": i.SingleClusterInformerPackagePath, - "singleClusterListerPackagePath": i.SingleClusterListerPackagePath, - "useUpstreamInterfaces": i.SingleClusterListerPackagePath != "" && i.SingleClusterInformerPackagePath != "", - } - return templ.Execute(w, m) -} - -var informer = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package {{.group.Version.PackageName}} - -import ( - "context" - "time" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - - {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - {{.group.PackageAlias}}listers "{{.listerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - {{if .useUpstreamInterfaces -}} - upstream{{.group.PackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - upstream{{.group.PackageAlias}}informers "{{.singleClusterInformerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - {{end -}} - - clientset "{{.clientsetPackagePath}}" - {{if not .useUpstreamInterfaces -}} - scopedclientset "{{.singleClusterClientPackagePath}}" - {{end -}} - - "{{.packagePath}}/internalinterfaces" -) - -// {{.kind}}ClusterInformer provides access to a shared informer and lister for -// {{.kind.Plural}}. -type {{.kind}}ClusterInformer interface { - Cluster(logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.PackageAlias}}informers.{{end}}{{.kind}}Informer - Informer() kcpcache.ScopeableSharedIndexInformer - Lister() {{.group.PackageAlias}}listers.{{.kind}}ClusterLister -} - -type {{.kind.String | lowerFirst}}ClusterInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New{{.kind}}ClusterInformer constructs a new informer for {{.kind.String}} type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func New{{.kind}}ClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { - return NewFiltered{{.kind}}ClusterInformer(client, resyncPeriod, indexers, nil) -} - -// NewFiltered{{.kind}}ClusterInformer constructs a new informer for {{.kind.String}} type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFiltered{{.kind}}ClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { - return kcpinformers.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.{{.group.GroupGoName}}{{.group.Version}}().{{.kind.Plural}}().List(context.TODO(), options) - }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.{{.group.GroupGoName}}{{.group.Version}}().{{.kind.Plural}}().Watch(context.TODO(), options) - }, - }, - &{{.group.PackageAlias}}.{{.kind.String}}{}, - resyncPeriod, - indexers, - ) -} - -func (f *{{.kind.String|lowerFirst}}ClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { - return NewFiltered{{.kind}}ClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - {{if .kind.IsNamespaced}}kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc,{{end -}} - }, - f.tweakListOptions, - ) -} - -func (f *{{.kind.String|lowerFirst}}ClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&{{.group.PackageAlias}}.{{.kind}}{}, f.defaultInformer) -} - -func (f *{{.kind.String|lowerFirst}}ClusterInformer) Lister() {{.group.PackageAlias}}listers.{{.kind.String}}ClusterLister { - return {{.group.PackageAlias}}listers.New{{.kind}}ClusterLister(f.Informer().GetIndexer()) -} - -{{ if not .useUpstreamInterfaces }} -// {{.kind}}Informer provides access to a shared informer and lister for -// {{.kind.Plural}}. -type {{.kind}}Informer interface { - Informer() cache.SharedIndexInformer - Lister() {{.group.PackageAlias}}listers.{{.kind}}Lister -} -{{end -}} - -func (f *{{.kind.String|lowerFirst}}ClusterInformer) Cluster(clusterName logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.PackageAlias}}informers.{{end}}{{.kind}}Informer { - return &{{.kind.String|lowerFirst}}Informer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), - } -} - -type {{.kind.String|lowerFirst}}Informer struct { - informer cache.SharedIndexInformer - lister {{if .useUpstreamInterfaces}}upstream{{end}}{{.group.PackageAlias}}listers.{{.kind.String}}Lister -} - -func (f *{{.kind.String|lowerFirst}}Informer) Informer() cache.SharedIndexInformer { - return f.informer -} - -func (f *{{.kind.String|lowerFirst}}Informer) Lister() {{if .useUpstreamInterfaces}}upstream{{end}}{{.group.PackageAlias}}listers.{{.kind.String}}Lister { - return f.lister -} - -{{if not .useUpstreamInterfaces -}} -type {{.kind.String | lowerFirst}}ScopedInformer struct { - factory internalinterfaces.SharedScopedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - {{if .kind.IsNamespaced}}namespace string{{end -}} -} - -func (f *{{.kind.String|lowerFirst}}ScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&{{.group.PackageAlias}}.{{.kind}}{}, f.defaultInformer) -} - -func (f *{{.kind.String|lowerFirst}}ScopedInformer) Lister() {{.group.PackageAlias}}listers.{{.kind.String}}Lister { - return {{.group.PackageAlias}}listers.New{{.kind}}Lister(f.Informer().GetIndexer()) -} - -// New{{.kind}}Informer constructs a new informer for {{.kind.String}} type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func New{{.kind}}Informer(client scopedclientset.Interface, resyncPeriod time.Duration,{{if .kind.IsNamespaced}} namespace string,{{end -}} indexers cache.Indexers) cache.SharedIndexInformer { - return NewFiltered{{.kind}}Informer(client, resyncPeriod, {{if .kind.IsNamespaced}} namespace,{{end -}}indexers, nil) -} - -// NewFiltered{{.kind}}Informer constructs a new informer for {{.kind.String}} type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFiltered{{.kind}}Informer(client scopedclientset.Interface, resyncPeriod time.Duration, {{if .kind.IsNamespaced}} namespace string,{{end -}}indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.{{.group.GroupGoName}}{{.group.Version}}().{{.kind.Plural}}({{if .kind.IsNamespaced}}namespace{{end -}}).List(context.TODO(), options) - }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.{{.group.GroupGoName}}{{.group.Version}}().{{.kind.Plural}}({{if .kind.IsNamespaced}}namespace{{end -}}).Watch(context.TODO(), options) - }, - }, - &{{.group.PackageAlias}}.{{.kind.String}}{}, - resyncPeriod, - indexers, - ) -} - -func (f *{{.kind.String|lowerFirst}}ScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFiltered{{.kind}}Informer(client, resyncPeriod,{{if .kind.IsNamespaced}} f.namespace,{{end -}} cache.Indexers{ {{if .kind.IsNamespaced}} - cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, - {{end}}}, f.tweakListOptions) -} -{{end}} -` diff --git a/pkg/internal/informergen/parser.go b/pkg/internal/informergen/parser.go deleted file mode 100644 index 585918920..000000000 --- a/pkg/internal/informergen/parser.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package informergen - -import ( - "sort" - "strings" - "text/template" - - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -var ( - templateFuncs = template.FuncMap{ - "upperFirst": util.UpperFirst, - "lowerFirst": util.LowerFirst, - "toLower": strings.ToLower, - "sortVersions": sortVersions, - } -) - -func sortVersions(versionKinds map[types.PackageVersion][]parser.Kind) []types.PackageVersion { - versions := []types.PackageVersion{} - for version := range versionKinds { - versions = append(versions, version) - } - sort.Slice(versions, func(i, j int) bool { - return versions[i].Version.String() < versions[j].Version.String() - }) - return versions -} diff --git a/pkg/internal/informergen/versioninterface.go b/pkg/internal/informergen/versioninterface.go deleted file mode 100644 index fb20d35ac..000000000 --- a/pkg/internal/informergen/versioninterface.go +++ /dev/null @@ -1,117 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package informergen - -import ( - "io" - "text/template" - - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" -) - -type VersionInterface struct { - // Version is the version of this group that the interface is generated for - Version types.Version - - // Kinds are the kinds for which this interface exposes informers - Kinds []parser.Kind - - // PackagePath is the package under which these informers will be exposed. - // e.g. "github.com/kcp-dev/client-go/clients/informers" - // TODO(skuznets) we should be able to figure this out from the output dir, ideally - PackagePath string - - // UseUpstreamInterfaces determines if we're generating against existing single-cluster informer interfaces or not. - UseUpstreamInterfaces bool -} - -func (v *VersionInterface) WriteContent(w io.Writer) error { - templ, err := template.New("versionInterface").Funcs(templateFuncs).Parse(versionInterfaceTemplate) - if err != nil { - return err - } - - m := map[string]interface{}{ - "version": v.Version, - "kinds": v.Kinds, - "packagePath": v.PackagePath, - "useUpstreamInterfaces": v.UseUpstreamInterfaces, - } - return templ.Execute(w, m) -} - -var versionInterfaceTemplate = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package {{.version.PackageName}} - -import ( - "{{.packagePath}}/internalinterfaces" -) - -type ClusterInterface interface { -{{range .kinds}}// {{.Plural}} returns a {{.String}}ClusterInformer - {{.Plural}}() {{.String}}ClusterInformer -{{end -}} -} - -type version struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new ClusterInterface. -func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { - return &version{factory: f, tweakListOptions: tweakListOptions} -} - -{{range .kinds}}// {{.Plural}} returns a {{.String}}ClusterInformer -func (v *version) {{.Plural}}() {{.String}}ClusterInformer { - return &{{.String|lowerFirst}}ClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} -{{end -}} - -{{if not .useUpstreamInterfaces -}} -type Interface interface { -{{range .kinds}}// {{.Plural}} returns a {{.String}}Informer - {{.Plural}}() {{.String}}Informer -{{end -}} -} - -type scopedVersion struct { - factory internalinterfaces.SharedScopedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// New returns a new ClusterInterface. -func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &scopedVersion{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -{{range .kinds}}// {{.Plural}} returns a {{.String}}Informer -func (v *scopedVersion) {{.Plural}}() {{.String}}Informer { - return &{{.String|lowerFirst}}ScopedInformer{factory: v.factory, {{if .IsNamespaced}}namespace: v.namespace, {{end}}tweakListOptions: v.tweakListOptions} -} -{{end -}} -{{end}} -` diff --git a/pkg/internal/listergen/expansions.go b/pkg/internal/listergen/expansions.go deleted file mode 100644 index 13edd29ab..000000000 --- a/pkg/internal/listergen/expansions.go +++ /dev/null @@ -1,57 +0,0 @@ -package listergen - -import ( - "io" - "text/template" - - clientgentypes "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" -) - -type Expansions struct { - // Group is: - // - the name of the API group, e.g. "authorization", - // - the version and package path of the API, e.g. "v1" and "k8s.io/api/rbac/v1" - Group clientgentypes.GroupVersionInfo - // Kind is the kind for which we are generating listers, e.g. "ClusterRole" - Kind parser.Kind - - // UseUpstreamInterfaces determines if we're generating against existing single-cluster lister interfaces or not. - UseUpstreamInterfaces bool -} - -func (l *Expansions) WriteContent(w io.Writer) error { - templ, err := template.New("expansions").Funcs(templateFuncs).Parse(expansions) - if err != nil { - return err - } - - m := map[string]interface{}{ - "group": l.Group, - "kind": &l.Kind, - "useUpstreamInterfaces": l.UseUpstreamInterfaces, - } - return templ.Execute(w, m) -} - -var expansions = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package {{.group.Version.PackageName}} - -// {{.kind.String}}ClusterListerExpansion allows custom methods to be added to {{.kind.String}}ClusterLister. -type {{.kind.String}}ClusterListerExpansion interface {} - -{{ if not .useUpstreamInterfaces -}} -// {{.kind.String}}ListerExpansion allows custom methods to be added to {{.kind.String}}Lister. -type {{.kind.String}}ListerExpansion interface {} -{{ if .kind.IsNamespaced -}} -// {{.kind.String}}NamespaceListerExpansion allows custom methods to be added to {{.kind.String}}NamespaceLister. -type {{.kind.String}}NamespaceListerExpansion interface {} -{{ end -}} -{{ end -}} -` diff --git a/pkg/internal/listergen/lister.go b/pkg/internal/listergen/lister.go deleted file mode 100644 index 48ff2416c..000000000 --- a/pkg/internal/listergen/lister.go +++ /dev/null @@ -1,300 +0,0 @@ -package listergen - -import ( - "io" - "text/template" - - clientgentypes "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" -) - -type Lister struct { - // Group is: - // - the name of the API group, e.g. "authorization", - // - the version and package path of the API, e.g. "v1" and "k8s.io/api/rbac/v1" - Group clientgentypes.GroupVersionInfo - // Kind is the kind for which we are generating listers, e.g. "ClusterRole" - Kind parser.Kind - - // APIPackagePath is the root directory under which API types exist. - // e.g. "k8s.io/api" - APIPackagePath string - - // SingleClusterListerPackagePath is the fully qualified Go package name under which the (pre-existing) - // listers for single-cluster contexts are defined. Option. e.g. "k8s.io/client-go/listers" - SingleClusterListerPackagePath string -} - -func (l *Lister) WriteContent(w io.Writer) error { - templ, err := template.New("lister").Funcs(templateFuncs).Parse(lister) - if err != nil { - return err - } - - m := map[string]interface{}{ - "group": l.Group, - "kind": &l.Kind, - "apiPackagePath": l.APIPackagePath, - "singleClusterListerPackagePath": l.SingleClusterListerPackagePath, - "useUpstreamInterfaces": l.SingleClusterListerPackagePath != "", - } - return templ.Execute(w, m) -} - -var lister = ` -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -// Code generated by kcp code-generator. DO NOT EDIT. - -package {{.group.Version.PackageName}} - -import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" - - "k8s.io/client-go/tools/cache" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/api/errors" - - {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - {{if .useUpstreamInterfaces -}} - {{.group.PackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - {{end -}} -) - -// {{.kind.String}}ClusterLister can list {{.kind.Plural}} across all workspaces, or scope down to a {{.kind.String}}Lister for one workspace. -// All objects returned here must be treated as read-only. -type {{.kind.String}}ClusterLister interface { - // List lists all {{.kind.Plural}} in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) - // Cluster returns a lister that can list and get {{.kind.Plural}} in one workspace. -{{if not .useUpstreamInterfaces -}} - Cluster(clusterName logicalcluster.Name) {{.kind.String}}Lister -{{else -}} - Cluster(clusterName logicalcluster.Name){{.group.PackageAlias}}listers.{{.kind.String}}Lister -{{end -}} - {{.kind.String}}ClusterListerExpansion -} - -type {{.kind.String | lowerFirst }}ClusterLister struct { - indexer cache.Indexer -} - -// New{{.kind.String}}ClusterLister returns a new {{.kind.String}}ClusterLister. -// We assume that the indexer: -// - is fed by a cross-workspace LIST+WATCH -// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function -// - has the kcpcache.ClusterIndex as an index -{{ if .kind.IsNamespaced -}} -// - has the kcpcache.ClusterAndNamespaceIndex as an index -{{end -}} -func New{{.kind.String}}ClusterLister(indexer cache.Indexer) *{{.kind.String | lowerFirst}}ClusterLister { - return &{{.kind.String | lowerFirst}}ClusterLister{indexer: indexer} -} - -// List lists all {{.kind.Plural}} in the indexer across all workspaces. -func (s *{{.kind.String | lowerFirst}}ClusterLister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*{{.group.PackageAlias}}.{{.kind.String}})) - }) - return ret, err -} - -// Cluster scopes the lister to one workspace, allowing users to list and get {{.kind.Plural}}. -{{if not .useUpstreamInterfaces -}} -func (s *{{.kind.String | lowerFirst}}ClusterLister) Cluster(clusterName logicalcluster.Name) {{.kind.String}}Lister { -{{else -}} -func (s *{{.kind.String | lowerFirst}}ClusterLister) Cluster(clusterName logicalcluster.Name){{.group.PackageAlias}}listers.{{.kind.String}}Lister { -{{end -}} - return &{{.kind.String | lowerFirst}}Lister{indexer: s.indexer, clusterName: clusterName} -} - -{{if not .useUpstreamInterfaces -}} -{{ if not .kind.IsNamespaced -}} -// {{.kind.String}}Lister can list all {{.kind.Plural}}, or get one in particular. -{{else -}} -// {{.kind.String}}Lister can list {{.kind.Plural}} across all namespaces, or scope down to a {{.kind.String}}NamespaceLister for one namespace. -{{end -}} -// All objects returned here must be treated as read-only. -type {{.kind.String}}Lister interface { - // List lists all {{.kind.Plural}} in the workspace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) -{{ if not .kind.IsNamespaced -}} - // Get retrieves the {{.kind.String}} from the indexer for a given workspace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) -{{else -}} - // {{.kind.Plural}} returns a lister that can list and get {{.kind.Plural}} in one workspace and namespace. - {{.kind.Plural}}(namespace string) {{.kind.String}}NamespaceLister -{{end -}} - {{.kind.String}}ListerExpansion -} -{{end -}} - -{{if not .useUpstreamInterfaces -}} -// {{.kind.String | lowerFirst}}Lister can list all {{.kind.Plural}} inside a workspace{{ if .kind.IsNamespaced }} or scope down to a {{.kind.String}}Lister for one namespace{{end}}. -{{else -}} -// {{.kind.String | lowerFirst}}Lister implements the {{.group.PackageAlias}}listers.{{.kind.String}}Lister interface. -{{end -}} -type {{.kind.String | lowerFirst}}Lister struct { - indexer cache.Indexer - clusterName logicalcluster.Name -} - -// List lists all {{.kind.Plural}} in the indexer for a workspace. -func (s *{{.kind.String | lowerFirst}}Lister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.PackageAlias}}.{{.kind.String}})) - }) - return ret, err -} - -{{ if not .kind.IsNamespaced -}} -// Get retrieves the {{.kind.String}} from the indexer for a given workspace and name. -func (s *{{.kind.String | lowerFirst}}Lister) Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound({{.group.PackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) - } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), nil -} -{{ else -}} -// {{.kind.Plural}} returns an object that can list and get {{.kind.Plural}} in one namespace. -{{if not .useUpstreamInterfaces -}} -func (s *{{.kind.String | lowerFirst}}Lister) {{.kind.Plural}}(namespace string) {{.kind.String}}NamespaceLister { -{{else -}} -func (s *{{.kind.String | lowerFirst}}Lister) {{.kind.Plural}}(namespace string) {{.group.PackageAlias}}listers.{{.kind.String}}NamespaceLister { -{{end -}} - return &{{.kind.String | lowerFirst}}NamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} -} - -{{if not .useUpstreamInterfaces -}} -// {{.kind.String | lowerFirst}}NamespaceLister helps list and get {{.kind.Plural}}. -// All objects returned here must be treated as read-only. -type {{.kind.String}}NamespaceLister interface { - // List lists all {{.kind.Plural}} in the workspace and namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) - // Get retrieves the {{.kind.String}} from the indexer for a given workspace, namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) - {{.kind.String}}NamespaceListerExpansion -} -{{end -}} - -{{ if not .useUpstreamInterfaces -}} -// {{.kind.String | lowerFirst}}NamespaceLister helps list and get {{.kind.Plural}}. -// All objects returned here must be treated as read-only. -{{ end -}} -{{ if .useUpstreamInterfaces -}} -// {{.kind.String | lowerFirst}}NamespaceLister implements the {{.group.PackageAlias}}listers.{{.kind.String}}NamespaceLister interface. -{{ end -}} -type {{.kind.String | lowerFirst}}NamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string -} - -// List lists all {{.kind.Plural}} in the indexer for a given workspace and namespace. -func (s *{{.kind.String | lowerFirst}}NamespaceLister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.PackageAlias}}.{{.kind.String}})) - }) - return ret, err -} - -// Get retrieves the {{.kind.String}} from the indexer for a given workspace, namespace and name. -func (s *{{.kind.String | lowerFirst}}NamespaceLister) Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound({{.group.PackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) - } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), nil -} -{{ end -}} - -{{if not .useUpstreamInterfaces -}} -// New{{.kind.String}}Lister returns a new {{.kind.String}}Lister. -// We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -{{ if .kind.IsNamespaced -}} -// - has the cache.NamespaceIndex as an index -{{end -}} -func New{{.kind.String}}Lister(indexer cache.Indexer) *{{.kind.String | lowerFirst}}ScopedLister { - return &{{.kind.String | lowerFirst}}ScopedLister{indexer: indexer} -} - -// {{.kind.String | lowerFirst}}ScopedLister can list all {{.kind.Plural}} inside a workspace{{ if .kind.IsNamespaced }} or scope down to a {{.kind.String}}Lister for one namespace{{end}}. -type {{.kind.String | lowerFirst}}ScopedLister struct { - indexer cache.Indexer -} - -// List lists all {{.kind.Plural}} in the indexer for a workspace. -func (s *{{.kind.String | lowerFirst}}ScopedLister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.PackageAlias}}.{{.kind.String}})) - }) - return ret, err -} - -{{ if not .kind.IsNamespaced -}} -// Get retrieves the {{.kind.String}} from the indexer for a given workspace and name. -func (s *{{.kind.String | lowerFirst}}ScopedLister) Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - key := name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound({{.group.PackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) - } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), nil -} -{{ else -}} -// {{.kind.Plural}} returns an object that can list and get {{.kind.Plural}} in one namespace. -func (s *{{.kind.String | lowerFirst}}ScopedLister) {{.kind.Plural}}(namespace string) {{.kind.String}}NamespaceLister { - return &{{.kind.String | lowerFirst}}ScopedNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// {{.kind.String | lowerFirst}}ScopedNamespaceLister helps list and get {{.kind.Plural}}. -type {{.kind.String | lowerFirst}}ScopedNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all {{.kind.Plural}} in the indexer for a given workspace and namespace. -func (s *{{.kind.String | lowerFirst}}ScopedNamespaceLister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.PackageAlias}}.{{.kind.String}})) - }) - return ret, err -} - -// Get retrieves the {{.kind.String}} from the indexer for a given workspace, namespace and name. -func (s *{{.kind.String | lowerFirst}}ScopedNamespaceLister) Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - key := s.namespace + "/" + name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound({{.group.PackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) - } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), nil -} -{{ end -}} -{{end -}} -` diff --git a/pkg/parser/extract.go b/pkg/parser/extract.go deleted file mode 100644 index d037dba7a..000000000 --- a/pkg/parser/extract.go +++ /dev/null @@ -1,161 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package parser - -import ( - "go/ast" - "strings" - - "golang.org/x/tools/go/ast/astutil" - - "k8s.io/apimachinery/pkg/util/errors" - "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/code-generator/cmd/client-gen/types" - "k8s.io/gengo/namer" - "k8s.io/klog/v2" - "sigs.k8s.io/controller-tools/pkg/genall" - "sigs.k8s.io/controller-tools/pkg/markers" -) - -// isForbiddenGroupVersion hacks around the k8s client-set, where types have +genclient but aren't meant to have -// generated clients ... ? -func isForbiddenGroupVersion(group types.Group, version types.Version) bool { - forbidden := map[string]sets.Set[string]{ - "abac.authorization.kubernetes.io": sets.New[string]("v0", "v1beta1"), - "componentconfig": sets.New[string]("v1alpha1"), - "imagepolicy.k8s.io": sets.New[string]("v1alpha1"), - "admission.k8s.io": sets.New[string]("v1", "v1beta1"), - } - versions, ok := forbidden[group.String()] - return ok && versions.Has(version.String()) -} - -// CollectKinds finds all groupVersionKinds for which the k8s client-generators are run and the set of -// verbs are supported. -// When we are looking at a package, we can determine the group and version by copying the upstream -// logic: -// https://github.com/kubernetes/kubernetes/blob/f046bdf24e69ac31d3e1ed56926d9a7c715f1cc8/staging/src/k8s.io/code-generator/cmd/lister-gen/generators/lister.go#L93-L106 -func CollectKinds(ctx *genall.GenerationContext, verbs ...string) (map[Group]map[types.PackageVersion][]Kind, error) { - groupVersionKinds := map[Group]map[types.PackageVersion][]Kind{} - for _, root := range ctx.Roots { - logger := klog.Background() - logger.V(4).Info("processing " + root.PkgPath) - parts := strings.Split(root.PkgPath, "/") - groupName := types.Group(parts[len(parts)-2]) - version := types.PackageVersion{ - Version: types.Version(parts[len(parts)-1]), - Package: root.PkgPath, - } - - packageMarkers, err := markers.PackageMarkers(ctx.Collector, root) - if err != nil { - return nil, err - } - - // look for a reference to runtime.APIVersionInternal to skip internal APIs - var isInternalAPI bool - for _, file := range root.Syntax { - astutil.Apply(file, nil, func(cursor *astutil.Cursor) bool { - switch node := cursor.Node().(type) { - case *ast.SelectorExpr: - pkg, ok := node.X.(*ast.Ident) - if !ok { - break - } - if pkg.Name == "runtime" && node.Sel.Name == "APIVersionInternal" { - isInternalAPI = true - return false - } - } - return true - }) - } - if isInternalAPI { - logger.WithValues("path", root.PkgPath).V(4).Info("skipping package for internal API") - continue - } - - groupNameRaw, ok := packageMarkers.Get(GroupNameMarker.Name).(markers.RawArguments) - if ok { - // If there's a comment of the form "// +groupName=somegroup" or - // "// +groupName=somegroup.foo.bar.io", use the first field (somegroup) as the name of the - // group when generating. [N.B.](skuznets): even though the generators do the indexing here, the group - // type does it for you, and handles the special case for "internal" - logger.WithValues("original", groupName, "override", string(groupNameRaw)).V(4).Info("found a group name override") - groupName = types.Group(groupNameRaw) - } - groupGoName := namer.IC(groupName.PackageName()) - // internal.apiserver.k8s.io needs to have a package name of apiserverinternal, but a Go name of internal ... - if parts := strings.Split(groupName.NonEmpty(), "."); parts[0] == "internal" && len(parts) > 1 { - groupGoName = namer.IC(parts[0]) - } - - groupGoNameRaw, ok := packageMarkers.Get(GroupGoNameMarker.Name).(markers.RawArguments) - if ok { - // If there's a comment of the form "// +groupGoName=SomeUniqueShortName", use that as - // the Go group identifier in CamelCase. - groupGoName = namer.IC(string(groupGoNameRaw)) - } - group := Group{Group: groupName, GoName: groupGoName} - - logger = logger.WithValues("group", group, "version", version, "goName", groupGoName) - if isForbiddenGroupVersion(group.Group, version.Version) { - logger.WithValues("package", root.PkgPath).V(4).Info("skipping forbidden package") - continue - } - logger.WithValues("package", root.PkgPath).V(4).Info("collecting kinds in package") - - // find types which have generated clients and support LIST + WATCH - var kinds []Kind - var typeErrors []error - if err := markers.EachType(ctx.Collector, root, func(info *markers.TypeInfo) { - logger = logger.WithValues("kind", info.Name) - if !ClientsGeneratedForType(info) { - logger.V(3).V(4).Info("skipping kind as it has no generated clients") - return - } - - supported, err := SupportedVerbs(info) - if err != nil { - typeErrors = append(typeErrors, err) - return - } - extensions := ClientExtensions(info) - if len(verbs) > 0 && !supported.HasAll(verbs...) { - logger.V(4).Info("skipping kind as it does not support the necessary verbs") - return - } - - logger.V(4).Info("will generate for kind") - kinds = append(kinds, NewKind(info.Name, IsNamespaced(info), supported, extensions)) - }); err != nil { - return nil, err - } - if len(typeErrors) > 0 { - return nil, errors.NewAggregate(typeErrors) - } - if len(kinds) == 0 { - logger.V(4).Info("skipping group/version as it has no kinds that have generated clients") - continue - } - if _, recorded := groupVersionKinds[group]; !recorded { - groupVersionKinds[group] = map[types.PackageVersion][]Kind{} - } - groupVersionKinds[group][version] = append(groupVersionKinds[group][version], kinds...) - } - return groupVersionKinds, nil -} diff --git a/pkg/parser/markers.go b/pkg/parser/markers.go deleted file mode 100644 index 19be38b88..000000000 --- a/pkg/parser/markers.go +++ /dev/null @@ -1,184 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package parser - -import ( - "fmt" - "strings" - - "k8s.io/apimachinery/pkg/util/sets" - genutil "k8s.io/code-generator/cmd/client-gen/generators/util" - "sigs.k8s.io/controller-tools/pkg/markers" -) - -var ( - // In controller-tool's terms marker's are defined in the following format: :=. These - // markers are not a part of genclient, since they do not accept any values. - GenclientMarker = markers.Must(markers.MakeDefinition("genclient", markers.DescribesType, extension{})) - NonNamespacedMarker = markers.Must(markers.MakeDefinition("genclient:nonNamespaced", markers.DescribesType, struct{}{})) - - // These markers, are not a part of "+genclient", and are defined separately because they accept a list which is comma separated. In - // controller-tools, comma indicates another argument, as multiple arguments need to provided with a semi-colon separator. - SkipVerbsMarker = markers.Must(markers.MakeDefinition("genclient:skipVerbs", markers.DescribesType, markers.RawArguments(""))) - OnlyVerbsMarker = markers.Must(markers.MakeDefinition("genclient:onlyVerbs", markers.DescribesType, markers.RawArguments(""))) - - GroupNameMarker = markers.Must(markers.MakeDefinition("groupName", markers.DescribesPackage, markers.RawArguments(""))) - GroupGoNameMarker = markers.Must(markers.MakeDefinition("groupGoName", markers.DescribesPackage, markers.RawArguments(""))) - - // In controller-tool's terms marker's are defined in the following format: :=. These - // markers are not a part of genclient, since they do not accept any values. - NoStatusMarker = markers.Must(markers.MakeDefinition("genclient:noStatus", markers.DescribesType, struct{}{})) - NoVerbsMarker = markers.Must(markers.MakeDefinition("genclient:noVerbs", markers.DescribesType, struct{}{})) - ReadOnlyMarker = markers.Must(markers.MakeDefinition("genclient:readonly", markers.DescribesType, struct{}{})) -) - -type extension struct { - Method *string - Verb *string - Subresource *string - Input *string - Result *string -} - -type Extension struct { - Method string - Verb string - Subresource string - InputPath string - InputType string - ResultPath string - ResultType string -} - -// InputType returns the input override package path and the type. -func (e *extension) InputType() (string, string) { - if e.Input == nil { - return "", "" - } - parts := strings.Split(*e.Input, ".") - return parts[len(parts)-1], strings.Join(parts[0:len(parts)-1], ".") -} - -// ResultType returns the result override package path and the type. -func (e *extension) ResultType() (string, string) { - if e.Result == nil { - return "", "" - } - parts := strings.Split(*e.Result, ".") - return parts[len(parts)-1], strings.Join(parts[0:len(parts)-1], ".") -} - -// ClientsGeneratedForType verifies if the genclient marker is enabled for -// this type or not. -func ClientsGeneratedForType(info *markers.TypeInfo) bool { - return info.Markers.Get(GenclientMarker.Name) != nil -} - -// IsClusterScoped verifies if the genclient marker for this -// type is namespaced or clusterscoped. -func IsClusterScoped(info *markers.TypeInfo) bool { - return info.Markers.Get(NonNamespacedMarker.Name) != nil -} - -// IsNamespaced verifies if the genclient marker for this -// type is namespaced. -func IsNamespaced(info *markers.TypeInfo) bool { - return !IsClusterScoped(info) -} - -// SupportedVerbs determines which verbs the type supports -func SupportedVerbs(info *markers.TypeInfo) (sets.Set[string], error) { - if info.Markers.Get(NoVerbsMarker.Name) != nil { - return sets.New[string](), nil - } - - extractVerbs := func(info *markers.TypeInfo, name string) ([]string, error) { - if items := info.Markers.Get(name); items != nil { - val, ok := items.(markers.RawArguments) - if !ok { - return nil, fmt.Errorf("marker defined in wrong format %q", OnlyVerbsMarker.Name) - } - return strings.Split(string(val), ","), nil - } - return nil, nil - } - - onlyVerbs, err := extractVerbs(info, OnlyVerbsMarker.Name) - if err != nil { - return sets.New[string](), err - } - if len(onlyVerbs) > 0 { - return sets.New[string](onlyVerbs...), nil - } - - baseVerbs := sets.New[string](genutil.SupportedVerbs...) - if info.Markers.Get(ReadOnlyMarker.Name) != nil { - baseVerbs = sets.New[string](genutil.ReadonlyVerbs...) - } - - if info.Markers.Get(NoStatusMarker.Name) != nil { - baseVerbs = baseVerbs.Difference(sets.New[string]("updateStatus", "applyStatus")) - } - - skipVerbs, err := extractVerbs(info, SkipVerbsMarker.Name) - if err != nil { - return sets.New[string](), err - } - return baseVerbs.Difference(sets.New[string](skipVerbs...)), nil -} - -func ClientExtensions(info *markers.TypeInfo) []Extension { - values, ok := info.Markers[GenclientMarker.Name] - if !ok || values == nil { - return nil - } - var extensions []Extension - for _, item := range values { - extension, ok := item.(extension) - if !ok { - continue // should not occur - } - if extension.Method == nil || *extension.Method == "" { - continue - } - transformed := Extension{ - Method: deref(extension.Method), - Verb: deref(extension.Verb), - Subresource: deref(extension.Subresource), - } - transformed.InputType, transformed.InputPath = extension.InputType() - transformed.ResultType, transformed.ResultPath = extension.ResultType() - extensions = append(extensions, transformed) - } - return extensions -} - -func deref(in *string) string { - if in == nil { - return "" - } - return *in -} - -// SupportsVerbs determines if the type supports all the verbs. -func SupportsVerbs(info *markers.TypeInfo, verbs ...string) (bool, error) { - supported, err := SupportedVerbs(info) - if err != nil { - return false, err - } - return supported.HasAll(verbs...), nil -} diff --git a/pkg/parser/types.go b/pkg/parser/types.go deleted file mode 100644 index cfcc7f798..000000000 --- a/pkg/parser/types.go +++ /dev/null @@ -1,74 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package parser - -import ( - "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/code-generator/cmd/client-gen/types" - - "github.com/kcp-dev/code-generator/v2/pkg/util" - "github.com/kcp-dev/code-generator/v2/third_party/namer" -) - -type Kind struct { - kind string - namespaced bool - SupportedVerbs sets.Set[string] - Extensions []Extension - namer namer.Namer -} - -type Group struct { - types.Group - GoName string -} - -func (k *Kind) Plural() string { - return k.namer.Name(k.kind) -} - -func (k *Kind) String() string { - return k.kind -} - -func (k *Kind) IsNamespaced() bool { - return k.namespaced -} - -func (k *Kind) SupportsListWatch() bool { - return k.SupportedVerbs.HasAll("list", "watch") -} - -// TODO(skuznets): -// add an e2e for a kind that has no verbs, but uses an extension for something -// then ensure we add in fake_type.go entries for the extension -// changes we've already made should enable clients to exist for it - -func NewKind(kind string, namespaced bool, supportedVerbs sets.Set[string], extensions []Extension) Kind { - return Kind{ - kind: kind, - namespaced: namespaced, - SupportedVerbs: supportedVerbs, - Extensions: extensions, - namer: namer.Namer{ - Finalize: util.UpperFirst, - Exceptions: map[string]string{ - "Endpoints": "Endpoints", - }, - }, - } -} diff --git a/pkg/util/plural_exceptions.go b/pkg/util/plural_exceptions.go new file mode 100644 index 000000000..e428af3fb --- /dev/null +++ b/pkg/util/plural_exceptions.go @@ -0,0 +1,38 @@ +/* +Copyright 2025 The Kubernetes Authors. +Modifications Copyright 2025 The KCP Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "fmt" + "strings" +) + +// PluralExceptionListToMapOrDie converts the list in "Type:PluralType" to map[string]string. +// This is used for pluralizer. +// If the format is wrong, this function will panic. +func PluralExceptionListToMapOrDie(pluralExceptions []string) map[string]string { + pluralExceptionMap := make(map[string]string, len(pluralExceptions)) + for i := range pluralExceptions { + parts := strings.Split(pluralExceptions[i], ":") + if len(parts) != 2 { + panic(fmt.Sprintf("invalid plural exception definition: %s", pluralExceptions[i])) + } + pluralExceptionMap[parts[0]] = parts[1] + } + return pluralExceptionMap +} diff --git a/pkg/util/util.go b/pkg/util/util.go deleted file mode 100644 index b93277eaa..000000000 --- a/pkg/util/util.go +++ /dev/null @@ -1,105 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package util - -import ( - "bytes" - "errors" - "fmt" - "io" - "os" - "path/filepath" - "strings" - - "k8s.io/klog/v2" - "sigs.k8s.io/controller-tools/pkg/genall" -) - -// LowerFirst sets the first alphabet to lowerCase. -func LowerFirst(s string) string { - return strings.ToLower(string(s[0])) + s[1:] -} - -// UpperFirst sets the first alphabet to upperCase/ -func UpperFirst(s string) string { - return strings.ToUpper(string(s[0])) + s[1:] -} - -type Generator interface { - WriteContent(w io.Writer) error -} - -// InitializeGeneratedCode ensures that intoPath exists; if the file is not yet present it is initialized with the output of the generator. -func InitializeGeneratedCode(ctx *genall.GenerationContext, header string, generator Generator, intoPath string) error { - return writeGeneratedCode(ctx, header, generator, intoPath, false) -} - -// WriteGeneratedCode ensures that intoPath contains only the output of the generator. -func WriteGeneratedCode(ctx *genall.GenerationContext, header string, generator Generator, intoPath string) error { - return writeGeneratedCode(ctx, header, generator, intoPath, true) -} - -func writeGeneratedCode(ctx *genall.GenerationContext, header string, generator Generator, intoPath string, overwrite bool) error { - data := &bytes.Buffer{} - if n, err := data.WriteString(header); err != nil { - return err - } else if n != len(header) { - return io.ErrShortWrite - } - - if err := generator.WriteContent(data); err != nil { - return err - } - - output, ok := ctx.OutputRule.(genall.OutputToDirectory) - if !ok { - return fmt.Errorf("+output:dir is required, not %T", ctx.OutputRule) - } - fullPath := filepath.Join(string(output), intoPath) - if err := os.MkdirAll(filepath.Dir(fullPath), os.ModePerm); err != nil { - return fmt.Errorf("couldn't create directory: %w", err) - } - - if _, err := os.Stat(fullPath); err == nil { - if !overwrite { - klog.Background().WithValues("path", intoPath).Info("not overwriting file") - return nil - } - } else if !errors.Is(err, os.ErrNotExist) { - return err - } - - outputFile, err := ctx.Open(nil, intoPath) - if err != nil { - return fmt.Errorf("failed to open: %w", err) - } - defer func() { - if err := outputFile.Close(); err != nil { - klog.Background().Error(err, "failed to close output file") - } - }() - dataBytes := data.Bytes() - n, err := outputFile.Write(dataBytes) - if err != nil { - return err - } - if n < len(dataBytes) { - return io.ErrShortWrite - } - - return nil -} diff --git a/third_party/namer/namer.go b/third_party/namer/namer.go deleted file mode 100644 index 73b7322cc..000000000 --- a/third_party/namer/namer.go +++ /dev/null @@ -1,105 +0,0 @@ -/* -Copyright 2015 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// This code has been taken from https://github.com/kubernetes/gengo/blob/master/namer/plural_namer.go -// with minor modifications. The changes are: -// 1. There is no concept of plublic/private namer here. There is generic namer struct which -// parses the input and gives us the required plural form. -// 2. The input argument to function `Name` is customized to accept a string instead of `types.Type`, -// since we directly modeify the API name in our code-gen. - -package namer - -var consonants = "bcdfghjklmnpqrstvwxyz" - -type Namer struct { - // use this to add any exceptions to look up - Exceptions map[string]string - // Use this to either convert everything to lowercase/upper case - // or anything else based on whether the parameter will be public - // or private. - Finalize func(string) string -} - -// Name gives out the final plural names which are -// to be scaffolded -func (n *Namer) Name(input string) string { - singular := input - var plural string - var ok bool - if plural, ok = n.Exceptions[singular]; ok { - return n.Finalize(plural) - } - if len(singular) < 2 { - return n.Finalize(singular) - } - - switch rune(singular[len(singular)-1]) { - case 's', 'x', 'z': - plural = esPlural(singular) - case 'y': - sl := rune(singular[len(singular)-2]) - if isConsonant(sl) { - plural = iesPlural(singular) - } else { - plural = sPlural(singular) - } - case 'h': - sl := rune(singular[len(singular)-2]) - if sl == 'c' || sl == 's' { - plural = esPlural(singular) - } else { - plural = sPlural(singular) - } - case 'e': - sl := rune(singular[len(singular)-2]) - if sl == 'f' { - plural = vesPlural(singular[:len(singular)-1]) - } else { - plural = sPlural(singular) - } - case 'f': - plural = vesPlural(singular) - default: - plural = sPlural(singular) - } - return n.Finalize(plural) -} - -func iesPlural(singular string) string { - return singular[:len(singular)-1] + "ies" -} - -func vesPlural(singular string) string { - return singular[:len(singular)-1] + "ves" -} - -func esPlural(singular string) string { - return singular + "es" -} - -func sPlural(singular string) string { - return singular + "s" -} - -func isConsonant(char rune) bool { - for _, c := range consonants { - if char == c { - return true - } - } - return false -} diff --git a/third_party/namer/namer_test.go b/third_party/namer/namer_test.go deleted file mode 100644 index bcd13af0f..000000000 --- a/third_party/namer/namer_test.go +++ /dev/null @@ -1,97 +0,0 @@ -/* -Copyright 2022 The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package namer - -import ( - "testing" - - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -func TestNamer(t *testing.T) { - namer := &Namer{ - Exceptions: map[string]string{ - "Blah": "Blah", - }, - Finalize: util.UpperFirst, - } - - cases := []struct { - typeName string - expected string - }{ - { - "Pod", - "Pods", - }, - { - "Entry", - "Entries", - }, - { - "Fizz", - "Fizzes", - }, - { - "Blah", - "Blah", - }, - { - "check", - "Checks", - }, - { - "Ingress", - "Ingresses", - }, - { - "ray", - "Rays", - }, - { - "Fox", - "Foxes", - }, - { - "City", - "Cities", - }, - { - "Leaf", - "Leaves", - }, - { - "Rich", - "Riches", - }, - { - "Life", - "Lives", - }, - { - "Myth", - "Myths", - }, - } - - for _, c := range cases { - output := namer.Name(c.typeName) - if output != c.expected { - t.Errorf("Unexpected result from namer. Expected %s, got %s", c.expected, output) - } - } -}