diff --git a/.gitignore b/.gitignore index b0314f483..80048efd4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ *.dll *.so *.dylib -/bin +/_build # Test binary, built with `go test -c` *.test @@ -14,17 +14,7 @@ # Dependency directories vendor/ +hack/tools/ # IDE files .idea - -hack/tools - -examples/bin/applyconfiguration-gen -examples/bin/client-gen -examples/bin/conversion-gen -examples/bin/deepcopy-gen -examples/bin/defaulter-gen -examples/bin/informer-gen -examples/bin/lister-gen -examples/bin/openapi-gen diff --git a/.golangci.yaml b/.golangci.yaml index a4af821fe..07281c01f 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -10,11 +10,11 @@ linters: - bidichk - bodyclose - containedctx + - copyloopvar - dupword - durationcheck - errcheck - errchkjson - - exportloopref - gocritic - godot - gofmt @@ -29,10 +29,17 @@ linters: - noctx - nolintlint - nosprintfhostport - - prealloc - revive - staticcheck - unconvert - unused - usestdlibvars - whitespace + +linters-settings: + revive: + rules: + # That is just how the Kubernetes code-generators are written. + # We'd rather stay closer to upstream than fixing this. + - name: unexported-return + disabled: true diff --git a/Makefile b/Makefile index 5decdf632..7e86fe448 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. @@ -15,38 +15,18 @@ SHELL := /usr/bin/env bash GO_INSTALL = ./hack/go-install.sh +BUILD_DEST ?= _build +BUILDFLAGS ?= +CMD ?= $(notdir $(wildcard ./cmd/*)) TOOLS_DIR=hack/tools GOBIN_DIR := $(abspath $(TOOLS_DIR)) TMPDIR := $(shell mktemp -d) -CONTROLLER_GEN_VER := v0.17.0 -CONTROLLER_GEN_BIN := controller-gen -CONTROLLER_GEN := $(GOBIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER) -export CONTROLLER_GEN - GOLANGCI_LINT_VER := v1.62.2 GOLANGCI_LINT_BIN := golangci-lint GOLANGCI_LINT := $(GOBIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER) -KUBE_CLIENT_GEN_VER := v0.32.3 -KUBE_CLIENT_GEN_BIN := client-gen -KUBE_LISTER_GEN_VER := v0.32.3 -KUBE_LISTER_GEN_BIN := lister-gen -KUBE_INFORMER_GEN_VER := v0.32.3 -KUBE_INFORMER_GEN_BIN := informer-gen -KUBE_APPLYCONFIGURATION_GEN_VER := v0.32.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 := c70783e636f2213cac683f6865d88c5edace3157 OPENSHIFT_GOIMPORTS_BIN := openshift-goimports OPENSHIFT_GOIMPORTS := $(TOOLS_DIR)/$(OPENSHIFT_GOIMPORTS_BIN)-$(OPENSHIFT_GOIMPORTS_VER) @@ -60,30 +40,26 @@ imports: $(OPENSHIFT_GOIMPORTS) $(OPENSHIFT_GOIMPORTS) --path ./examples -m acme.corp .PHONY: imports -$(CONTROLLER_GEN): - GOBIN=$(GOBIN_DIR) $(GO_INSTALL) sigs.k8s.io/controller-tools/cmd/$(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER) +.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 @@ -124,4 +100,5 @@ $(TOOLS_DIR)/verify_boilerplate.py: .PHONY: verify-boilerplate verify-boilerplate: $(TOOLS_DIR)/verify_boilerplate.py - $(TOOLS_DIR)/verify_boilerplate.py --boilerplate-dir=hack/boilerplate + $(TOOLS_DIR)/verify_boilerplate.py --boilerplate-dir=hack/boilerplate --skip examples + $(TOOLS_DIR)/verify_boilerplate.py --boilerplate-dir=hack/boilerplate/examples examples diff --git a/README.md b/README.md index c81291187..540b80074 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,77 @@ -## Code Generators for KCP-aware informers and listers +## Code Generators for KCP-aware clients, informers and listers -### Usage: +This repository contains code generation tools analogous to the Kubernetes +code-generator. It contains: -``` -code-generator [input-flags] -``` - -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..ead34bba8 --- /dev/null +++ b/cluster_codegen.sh @@ -0,0 +1,397 @@ +#!/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. +# +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 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 + ;; + *) + 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}")" + group_versions+=("${leaf2}/${leaf}") + 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..95f9d8b44 --- /dev/null +++ b/cmd/cluster-client-gen/args/args.go @@ -0,0 +1,128 @@ +/* +Copyright 2025 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. +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..5a6bac749 --- /dev/null +++ b/cmd/cluster-client-gen/args/gvpackages.go @@ -0,0 +1,178 @@ +/* +Copyright 2025 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. +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}, + } + } + } + + var groupNames []string + 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..eda2651c2 --- /dev/null +++ b/cmd/cluster-client-gen/args/gvpackages_test.go @@ -0,0 +1,117 @@ +/* +Copyright 2025 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. +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..7c128b3af --- /dev/null +++ b/cmd/cluster-client-gen/args/gvtype.go @@ -0,0 +1,111 @@ +/* +Copyright 2025 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. +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 { + 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..fd909b641 --- /dev/null +++ b/cmd/cluster-client-gen/generators/client_generator.go @@ -0,0 +1,442 @@ +/* +Copyright 2025 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. +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: "clientset", + 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 { + 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 { + 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)) + targetList = append(targetList, + 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..b19649def --- /dev/null +++ b/cmd/cluster-client-gen/generators/fake/fake_client_generator.go @@ -0,0 +1,137 @@ +/* +Copyright 2025 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. +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..616d21fad --- /dev/null +++ b/cmd/cluster-client-gen/generators/fake/generator_fake_for_clientset.go @@ -0,0 +1,256 @@ +/* +Copyright 2025 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. +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 \"%s\"", groupAlias, strings.ToLower(version.NonEmpty()), singleClusterGroupClientPackage)) + imports = append(imports, fmt.Sprintf("kcp%s%s \"%s\"", groupAlias, strings.ToLower(version.NonEmpty()), groupClientPackage)) + imports = append(imports, fmt.Sprintf("kcpfake%s%s \"%s\"", groupAlias, strings.ToLower(version.NonEmpty()), fakeGroupClientPackage)) + } + } + + // the package that has the clientset Interface + imports = append(imports, + fmt.Sprintf("clientset \"%s\"", g.singleClusterClientPackage), + fmt.Sprintf("kcpclientset \"%s\"", g.realClientsetPackage), + fmt.Sprintf("kcpclientscheme \"%s\"", path.Join(g.realClientsetPackage, "scheme")), + ) + + // imports for the code in commonTemplate + imports = append(imports, + "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..c1189cf1c --- /dev/null +++ b/cmd/cluster-client-gen/generators/fake/generator_fake_for_group.go @@ -0,0 +1,182 @@ +/* +Copyright 2025 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. +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 \"%s\"", groupVersionFromPackage(g.singleClusterClientPackage), g.singleClusterClientPackage), + fmt.Sprintf("kcp%s \"%s\"", 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..da103008e --- /dev/null +++ b/cmd/cluster-client-gen/generators/fake/generator_fake_for_type.go @@ -0,0 +1,681 @@ +/* +Copyright 2025 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. +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 "%s"`, gvAlias, g.typeToMatch.Name.Package), + fmt.Sprintf(`typedkcp%s "%s"`, gvAlias, g.realClientPackage), + fmt.Sprintf(`typed%s "%s"`, 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..388feecbe --- /dev/null +++ b/cmd/cluster-client-gen/generators/generator_for_clientset.go @@ -0,0 +1,239 @@ +/* +Copyright 2025 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. +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 \"%s\"", 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 \"%s\"", 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..7c78a484b --- /dev/null +++ b/cmd/cluster-client-gen/generators/generator_for_expansion.go @@ -0,0 +1,55 @@ +/* +Copyright 2025 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. +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..154786525 --- /dev/null +++ b/cmd/cluster-client-gen/generators/generator_for_group.go @@ -0,0 +1,249 @@ +/* +Copyright 2025 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. +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 { + 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..2896b00ee --- /dev/null +++ b/cmd/cluster-client-gen/generators/generator_for_type.go @@ -0,0 +1,257 @@ +/* +Copyright 2025 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. +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 { + sw.Do(clusterInterfaceVerbs, 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 clusterInterfaceVerbs = ` +// 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) +} + +// 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..177416ce4 --- /dev/null +++ b/cmd/cluster-client-gen/generators/scheme/generator_for_scheme.go @@ -0,0 +1,189 @@ +/* +Copyright 2025 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. +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 \"%s\"", groupAlias, packagePath)) + break + } + + imports = append(imports, fmt.Sprintf("%s%s \"%s\"", 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..eadee3fab --- /dev/null +++ b/cmd/cluster-client-gen/generators/util/gvpackages.go @@ -0,0 +1,42 @@ +/* +Copyright 2025 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. +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..ee481165b --- /dev/null +++ b/cmd/cluster-client-gen/generators/util/tags.go @@ -0,0 +1,345 @@ +/* +Copyright 2025 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. +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) + 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..3c793d8bc --- /dev/null +++ b/cmd/cluster-client-gen/generators/util/tags_test.go @@ -0,0 +1,149 @@ +/* +Copyright 2025 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. +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..5e4162402 --- /dev/null +++ b/cmd/cluster-client-gen/main.go @@ -0,0 +1,72 @@ +/* +Copyright 2025 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. +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..292439fa1 --- /dev/null +++ b/cmd/cluster-client-gen/types/helpers.go @@ -0,0 +1,122 @@ +/* +Copyright 2025 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. +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("^[0-9]+") + 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 { + var versionStrings []string + 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 { + var groupVersionPackages []GroupVersionInfo + 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 { + var groupInstallPackages []GroupInstallPackage + 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/v2/clustertesttype_expansion.go b/cmd/cluster-client-gen/types/helpers_test.go similarity index 52% rename from examples/pkg/kcp/clients/listers/example/v2/clustertesttype_expansion.go rename to cmd/cluster-client-gen/types/helpers_test.go index 2ce875217..aefd92f61 100644 --- a/examples/pkg/kcp/clients/listers/example/v2/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 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. @@ -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 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{} +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..9e341565e --- /dev/null +++ b/cmd/cluster-client-gen/types/types.go @@ -0,0 +1,110 @@ +/* +Copyright 2025 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. +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..03138bb16 --- /dev/null +++ b/cmd/cluster-informer-gen/args/args.go @@ -0,0 +1,91 @@ +/* +Copyright 2025 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. +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..27812de1b --- /dev/null +++ b/cmd/cluster-informer-gen/generators/factory.go @@ -0,0 +1,539 @@ +/* +Copyright 2025 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. +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..8f2f19056 --- /dev/null +++ b/cmd/cluster-informer-gen/generators/factoryinterface.go @@ -0,0 +1,109 @@ +/* +Copyright 2025 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. +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..d479a16c9 --- /dev/null +++ b/cmd/cluster-informer-gen/generators/generic.go @@ -0,0 +1,249 @@ +/* +Copyright 2025 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. +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), + "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}} + 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), + } +} +` + +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..eef4842d6 --- /dev/null +++ b/cmd/cluster-informer-gen/generators/groupinterface.go @@ -0,0 +1,157 @@ +/* +Copyright 2025 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. +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..45fb30b7e --- /dev/null +++ b/cmd/cluster-informer-gen/generators/informer.go @@ -0,0 +1,312 @@ +/* +Copyright 2025 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. +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), + "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$ + 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), + } +} +` + +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..6f569dc77 --- /dev/null +++ b/cmd/cluster-informer-gen/generators/targets.go @@ -0,0 +1,343 @@ +/* +Copyright 2025 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. +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 + + var targetList []generator.Target + 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 { + 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 { + 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, + }) + + generators = append(generators, &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..1dfd3c612 --- /dev/null +++ b/cmd/cluster-informer-gen/generators/types.go @@ -0,0 +1,51 @@ +/* +Copyright 2025 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. +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"} + 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..5069c5d89 --- /dev/null +++ b/cmd/cluster-informer-gen/generators/versioninterface.go @@ -0,0 +1,145 @@ +/* +Copyright 2025 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. +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..c11a1c0a3 --- /dev/null +++ b/cmd/cluster-informer-gen/main.go @@ -0,0 +1,62 @@ +/* +Copyright 2025 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. +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..8002738e5 --- /dev/null +++ b/cmd/cluster-lister-gen/args/args.go @@ -0,0 +1,68 @@ +/* +Copyright 2025 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. +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..d2c722757 --- /dev/null +++ b/cmd/cluster-lister-gen/generators/expansion.go @@ -0,0 +1,91 @@ +/* +Copyright 2025 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. +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..bcd947930 --- /dev/null +++ b/cmd/cluster-lister-gen/generators/lister.go @@ -0,0 +1,425 @@ +/* +Copyright 2025 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. +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) + } + + var targetList []generator.Target + 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 { + 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"`, + `"k8s.io/client-go/listers"`, + ) + 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(namespaceListerConstructor, 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$] + indexer cache.Indexer +} + +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|private$ClusterLister { + return &$.type|private$ClusterLister{ + kcplisters.NewCluster[*$.type|raw$](indexer, $.Resource|raw$("$.type|lowercaseSingular$")), + indexer, + } +} + +// 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{ + kcplisters.New[*$.type|raw$](l.indexer, clusterName, $.Resource|raw$("$.type|lowercaseSingular$")), + l.indexer, + 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$] + indexer cache.Indexer + clusterName logicalcluster.Name +} + +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 new$.type|public$NamespaceLister(l.ResourceIndexer, 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 namespaceListerConstructor = ` +// new$.type|public$NamespaceLister returns a new $.namespaceListerInterface|raw$. +func new$.type|public$NamespaceLister(indexer kcplisters.ResourceIndexer[*$.type|raw$], namespace string) $.namespaceListerInterface|raw$ { + return &$.type|private$NamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), + } +} +` + +var scopedLister = ` +// New$.type|public$Lister returns a new $.listerInterface|raw$. +// We assume that the indexer: +// - is fed by a workspace-scoped LIST+WATCH +// - uses cache.MetaNamespaceKeyFunc as the key function +$if .namespaced -$ +// - has the cache.NamespaceIndex as an index +$end -$ +func New$.type|public$Lister(indexer cache.Indexer) $.listerInterface|raw$ { + return &$.type|private$ScopedLister{ + listers.New[*$.type|raw$](indexer, $.Resource|raw$("$.type|lowercaseSingular$")), + indexer, + } +} + +// $.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 { + listers.ResourceIndexer[*$.type|raw$] + indexer cache.Indexer +} + +$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) $.namespaceListerInterface|raw$ { + return listers.NewNamespaced(l.ResourceIndexer, namespace) +} +$end -$ +` diff --git a/cmd/cluster-lister-gen/main.go b/cmd/cluster-lister-gen/main.go new file mode 100644 index 000000000..a4e820665 --- /dev/null +++ b/cmd/cluster-lister-gen/main.go @@ -0,0 +1,62 @@ +/* +Copyright 2025 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. +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 f4f478801..66edd67e6 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -2,39 +2,41 @@ module acme.corp go 1.23.0 +toolchain go1.23.7 + replace acme.corp/pkg => ./pkg require ( github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250425065633-635c2a0fbaba - github.com/kcp-dev/client-go v0.0.0-20230927101349-0416c830e3b1 + github.com/kcp-dev/client-go v0.0.0-20250512170835-5457a0f4bd98 github.com/kcp-dev/logicalcluster/v3 v3.0.5 k8s.io/apimachinery v0.32.3 k8s.io/client-go v0.32.3 - sigs.k8s.io/structured-merge-diff/v4 v4.4.2 + sigs.k8s.io/structured-merge-diff/v4 v4.5.0 ) require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/emicklei/go-restful/v3 v3.11.0 // indirect - github.com/evanphx/json-patch v5.6.0+incompatible // 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.20.2 // 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.4 // indirect - github.com/google/gnostic-models v0.6.8 // indirect + github.com/google/gnostic-models v0.6.9 // indirect github.com/google/go-cmp v0.7.0 // indirect github.com/google/gofuzz v1.2.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.7 // 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 + github.com/rogpeppe/go-internal v1.13.1 // indirect github.com/x448/float16 v0.8.4 // indirect golang.org/x/net v0.39.0 // indirect golang.org/x/oauth2 v0.29.0 // indirect @@ -42,14 +44,15 @@ require ( golang.org/x/term v0.31.0 // indirect golang.org/x/text v0.24.0 // indirect golang.org/x/time v0.11.0 // indirect - google.golang.org/protobuf v1.35.1 // indirect + golang.org/x/tools v0.29.0 // indirect + google.golang.org/protobuf v1.36.2 // indirect gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/api v0.32.3 // indirect k8s.io/klog/v2 v2.130.1 // indirect - k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect - k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect - sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect + k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect + k8s.io/utils v0.0.0-20241210054802-24370beab758 // indirect + sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) diff --git a/examples/go.sum b/examples/go.sum index 6de4bc8fe..dfccb81ea 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -1,22 +1,17 @@ -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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= -github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= -github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U= -github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +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.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= 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.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= -github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= -github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +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= @@ -25,8 +20,8 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= -github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= +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= @@ -43,21 +38,18 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250425065633-635c2a0fbaba h1:Ar/8wsCQWrZgRiBF2B5xCqCXEA/oiiuDI0yEsUtrxRs= github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250425065633-635c2a0fbaba/go.mod h1:pYqnaSG3NlF/pVwfnYCAdGvrA7FpALFmd5S9X4XXf1Q= -github.com/kcp-dev/client-go v0.0.0-20230927101349-0416c830e3b1 h1:cyRhjhVSmcUqsMg0wh+DB/DjlpV58nhRpJYxRgCjayA= -github.com/kcp-dev/client-go v0.0.0-20230927101349-0416c830e3b1/go.mod h1:XfQFbR0lb2SsNEiAcR0ktxzgjlcJQpiWLX+OHw3a5ac= +github.com/kcp-dev/client-go v0.0.0-20250512170835-5457a0f4bd98 h1:A1Hc2zVGd9LRSQqlGGqfzin+4skWJVcsNXw2+MjU6z4= +github.com/kcp-dev/client-go v0.0.0-20250512170835-5457a0f4bd98/go.mod h1:79pmlxmvE/hohqD/qvhKaaoXmNDF/uhKnnAO6Vf5hZk= 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.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -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/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= -github.com/mailru/easyjson v0.7.7/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= @@ -74,17 +66,12 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 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.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= -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/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.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 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= @@ -124,14 +111,14 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= -golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= +golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE= +golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588= 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 v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU= +google.golang.org/protobuf v1.36.2/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-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= @@ -139,7 +126,6 @@ gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSP 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.v3 v3.0.0-20200313102051-9f266ea9e77c/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= k8s.io/api v0.32.3 h1:Hw7KqxRusq+6QSplE3NYG4MBxZw1BZnq4aP4cJVINls= @@ -150,13 +136,13 @@ k8s.io/client-go v0.32.3 h1:RKPVltzopkSgHS7aS98QdscAgtgah/+zmpAogooIqVU= k8s.io/client-go v0.32.3/go.mod h1:3v0+3k4IcT9bXTc4V2rt+d2ZPPG700Xy6Oi0Gdl2PaY= 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-20241105132330-32ad38e42d3f h1:GA7//TjRY9yWGy1poLzYYJJ4JRdzg3+O6e8I+e+8T5Y= -k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f/go.mod h1:R/HEjbvWI0qdfb8viZUeVZm0X6IZnxAydC7YU42CMw4= -k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro= -k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8= -sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo= -sigs.k8s.io/structured-merge-diff/v4 v4.4.2 h1:MdmvkGuXi/8io6ixD5wud3vOLwc1rj0aNqRlpuvjmwA= -sigs.k8s.io/structured-merge-diff/v4 v4.4.2/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4= +k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg= +k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7/go.mod h1:GewRfANuJ70iYzvn+i4lezLDAFzvjxZYK1gn1lWcfas= +k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJJI8IUa1AmH/qa0= +k8s.io/utils v0.0.0-20241210054802-24370beab758/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/structured-merge-diff/v4 v4.5.0 h1:nbCitCK2hfnhyiKo6uf2HxUPTCodY6Qaf85SbDIaMBk= +sigs.k8s.io/structured-merge-diff/v4 v4.5.0/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4= 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/v1/zz_generated.deepcopy.go b/examples/pkg/apis/example/v1/zz_generated.deepcopy.go index 84c009c3a..e07544edb 100644 --- a/examples/pkg/apis/example/v1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/example/v1/zz_generated.deepcopy.go @@ -1,11 +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. @@ -14,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. @@ -46,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. @@ -69,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. @@ -86,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. @@ -118,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. @@ -148,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. @@ -180,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. @@ -205,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/zz_generated.deepcopy.go b/examples/pkg/apis/example/v1alpha1/zz_generated.deepcopy.go index d748afe8e..685ce1a3c 100644 --- a/examples/pkg/apis/example/v1alpha1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/example/v1alpha1/zz_generated.deepcopy.go @@ -1,11 +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. @@ -14,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. @@ -46,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. @@ -69,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. @@ -91,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. @@ -123,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/zz_generated.deepcopy.go b/examples/pkg/apis/example/v1beta1/zz_generated.deepcopy.go index 853fc9825..dd6744c7b 100644 --- a/examples/pkg/apis/example/v1beta1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/example/v1beta1/zz_generated.deepcopy.go @@ -1,11 +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. @@ -14,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. @@ -46,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. @@ -69,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. @@ -91,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. @@ -123,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/zz_generated.deepcopy.go b/examples/pkg/apis/example/v2/zz_generated.deepcopy.go index 8ed8afd35..bf1fbeb5e 100644 --- a/examples/pkg/apis/example/v2/zz_generated.deepcopy.go +++ b/examples/pkg/apis/example/v2/zz_generated.deepcopy.go @@ -1,11 +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. @@ -14,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. @@ -46,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. @@ -69,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. @@ -91,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. @@ -123,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 51d91f17c..58611b208 100644 --- a/examples/pkg/apis/example/zz_generated.deepcopy.go +++ b/examples/pkg/apis/example/zz_generated.deepcopy.go @@ -1,11 +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. @@ -14,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. @@ -46,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. @@ -69,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. @@ -86,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. @@ -118,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. @@ -148,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. @@ -180,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. @@ -205,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/v1/zz_generated.deepcopy.go b/examples/pkg/apis/example3/v1/zz_generated.deepcopy.go index 137615d31..2df6f53e5 100644 --- a/examples/pkg/apis/example3/v1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/example3/v1/zz_generated.deepcopy.go @@ -1,11 +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. @@ -14,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. @@ -46,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. @@ -69,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. @@ -91,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. @@ -123,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/v1/zz_generated.deepcopy.go b/examples/pkg/apis/exampledashed/v1/zz_generated.deepcopy.go index 137615d31..2df6f53e5 100644 --- a/examples/pkg/apis/exampledashed/v1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/exampledashed/v1/zz_generated.deepcopy.go @@ -1,11 +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. @@ -14,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. @@ -46,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. @@ -69,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. @@ -91,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. @@ -123,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/existinginterfaces/v1/zz_generated.deepcopy.go b/examples/pkg/apis/existinginterfaces/v1/zz_generated.deepcopy.go index 137615d31..2df6f53e5 100644 --- a/examples/pkg/apis/existinginterfaces/v1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/existinginterfaces/v1/zz_generated.deepcopy.go @@ -1,11 +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. @@ -14,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. @@ -46,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. @@ -69,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. @@ -91,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. @@ -123,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/zz_generated.deepcopy.go b/examples/pkg/apis/secondexample/v1/zz_generated.deepcopy.go index 137615d31..2df6f53e5 100644 --- a/examples/pkg/apis/secondexample/v1/zz_generated.deepcopy.go +++ b/examples/pkg/apis/secondexample/v1/zz_generated.deepcopy.go @@ -1,11 +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. @@ -14,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. @@ -46,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. @@ -69,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. @@ -91,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. @@ -123,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 d09b09c3c..ffc4f8774 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1/clustertesttype.go +++ b/examples/pkg/generated/applyconfigurations/example/v1/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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/example/v1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/example/v1/clustertesttypestatus.go index 617d11463..9e9d64b6d 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/example/v1/clustertesttypestatus.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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/example/v1/testtype.go b/examples/pkg/generated/applyconfigurations/example/v1/testtype.go index 2359dadf3..194cef1ef 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1/testtype.go +++ b/examples/pkg/generated/applyconfigurations/example/v1/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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/example/v1/withoutverbtype.go b/examples/pkg/generated/applyconfigurations/example/v1/withoutverbtype.go index b632d6c19..19bf83a8c 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1/withoutverbtype.go +++ b/examples/pkg/generated/applyconfigurations/example/v1/withoutverbtype.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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttype.go index 4a5fb60d2..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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1alpha1 diff --git a/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttypestatus.go index 215b4cffa..c1fb4e0af 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/example/v1alpha1/clustertesttypestatus.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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1alpha1 diff --git a/examples/pkg/generated/applyconfigurations/example/v1alpha1/testtype.go b/examples/pkg/generated/applyconfigurations/example/v1alpha1/testtype.go index 769990e0c..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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1alpha1 diff --git a/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttype.go index 26eca6f9f..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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1beta1 diff --git a/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttypestatus.go index 1ad47d870..dfb1b5601 100644 --- a/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/example/v1beta1/clustertesttypestatus.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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1beta1 diff --git a/examples/pkg/generated/applyconfigurations/example/v1beta1/testtype.go b/examples/pkg/generated/applyconfigurations/example/v1beta1/testtype.go index 415c6324b..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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1beta1 diff --git a/examples/pkg/generated/applyconfigurations/example/v2/clustertesttype.go b/examples/pkg/generated/applyconfigurations/example/v2/clustertesttype.go index 706848ba6..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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v2 diff --git a/examples/pkg/generated/applyconfigurations/example/v2/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/example/v2/clustertesttypestatus.go index 9b160febd..b3287ed0b 100644 --- a/examples/pkg/generated/applyconfigurations/example/v2/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/example/v2/clustertesttypestatus.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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v2 diff --git a/examples/pkg/generated/applyconfigurations/example/v2/testtype.go b/examples/pkg/generated/applyconfigurations/example/v2/testtype.go index 62998eaea..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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v2 diff --git a/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttype.go index d1060fb50..539af2118 100644 --- a/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttype.go +++ b/examples/pkg/generated/applyconfigurations/example3/v1/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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttypestatus.go index 617d11463..9e9d64b6d 100644 --- a/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/example3/v1/clustertesttypestatus.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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/example3/v1/testtype.go b/examples/pkg/generated/applyconfigurations/example3/v1/testtype.go index ea7fbdcf5..5330929f5 100644 --- a/examples/pkg/generated/applyconfigurations/example3/v1/testtype.go +++ b/examples/pkg/generated/applyconfigurations/example3/v1/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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttype.go index ba165e225..15fced8cf 100644 --- a/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/generated/applyconfigurations/exampledashed/v1/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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttypestatus.go index 617d11463..9e9d64b6d 100644 --- a/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttypestatus.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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/exampledashed/v1/testtype.go b/examples/pkg/generated/applyconfigurations/exampledashed/v1/testtype.go index 3bbc89e1f..78e62e25d 100644 --- a/examples/pkg/generated/applyconfigurations/exampledashed/v1/testtype.go +++ b/examples/pkg/generated/applyconfigurations/exampledashed/v1/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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttype.go index 2a04815fd..ee17dcc1a 100644 --- a/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttypestatus.go index 617d11463..9e9d64b6d 100644 --- a/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/clustertesttypestatus.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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/testtype.go b/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/testtype.go index a5b4b18f0..e4831aa56 100644 --- a/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/testtype.go +++ b/examples/pkg/generated/applyconfigurations/existinginterfaces/v1/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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/internal/internal.go b/examples/pkg/generated/applyconfigurations/internal/internal.go index f29d585da..86ad90aa9 100644 --- a/examples/pkg/generated/applyconfigurations/internal/internal.go +++ b/examples/pkg/generated/applyconfigurations/internal/internal.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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package internal diff --git a/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttype.go index 6c95010e0..c468e201b 100644 --- a/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttype.go +++ b/examples/pkg/generated/applyconfigurations/secondexample/v1/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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttypestatus.go index 617d11463..9e9d64b6d 100644 --- a/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttypestatus.go +++ b/examples/pkg/generated/applyconfigurations/secondexample/v1/clustertesttypestatus.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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/secondexample/v1/testtype.go b/examples/pkg/generated/applyconfigurations/secondexample/v1/testtype.go index 4d24b3426..82e1fddbe 100644 --- a/examples/pkg/generated/applyconfigurations/secondexample/v1/testtype.go +++ b/examples/pkg/generated/applyconfigurations/secondexample/v1/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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/applyconfigurations/utils.go b/examples/pkg/generated/applyconfigurations/utils.go index 1475c6953..d0a106f63 100644 --- a/examples/pkg/generated/applyconfigurations/utils.go +++ b/examples/pkg/generated/applyconfigurations/utils.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.32. DO NOT EDIT. +// Code generated by applyconfiguration-gen. DO NOT EDIT. package applyconfigurations diff --git a/examples/pkg/generated/clientset/versioned/clientset.go b/examples/pkg/generated/clientset/versioned/clientset.go index c603452dd..46b60547d 100644 --- a/examples/pkg/generated/clientset/versioned/clientset.go +++ b/examples/pkg/generated/clientset/versioned/clientset.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package versioned diff --git a/examples/pkg/generated/clientset/versioned/fake/clientset_generated.go b/examples/pkg/generated/clientset/versioned/fake/clientset_generated.go index 531b1d6bd..baf696bfb 100644 --- a/examples/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/examples/pkg/generated/clientset/versioned/fake/clientset_generated.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -25,6 +25,7 @@ import ( 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" @@ -93,6 +94,38 @@ 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) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + var ( _ clientset.Interface = &Clientset{} _ testing.FakeClient = &Clientset{} diff --git a/examples/pkg/generated/clientset/versioned/fake/doc.go b/examples/pkg/generated/clientset/versioned/fake/doc.go index b866f3981..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.32. 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 5197f7c1a..8af226960 100644 --- a/examples/pkg/generated/clientset/versioned/fake/register.go +++ b/examples/pkg/generated/clientset/versioned/fake/register.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake diff --git a/examples/pkg/generated/clientset/versioned/scheme/doc.go b/examples/pkg/generated/clientset/versioned/scheme/doc.go index 977048176..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.32. 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 8920da1ed..b1627ebff 100644 --- a/examples/pkg/generated/clientset/versioned/scheme/register.go +++ b/examples/pkg/generated/clientset/versioned/scheme/register.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package scheme 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 ed43df3ff..fd2a9021d 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" examplev1 "acme.corp/pkg/apis/example/v1" + applyconfigurationsexamplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -48,18 +49,21 @@ type ClusterTestTypeInterface interface { 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 *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 { - *gentype.ClientWithList[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList] + *gentype.ClientWithListAndApply[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList, *applyconfigurationsexamplev1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *ExampleV1Client) *clusterTestTypes { return &clusterTestTypes{ - gentype.NewClientWithList[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList]( + gentype.NewClientWithListAndApply[*examplev1.ClusterTestType, *examplev1.ClusterTestTypeList, *applyconfigurationsexamplev1.ClusterTestTypeApplyConfiguration]( "clustertesttypes", c.RESTClient(), scheme.ParameterCodec, 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 8f148c5b8..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.32. 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 cc1fc8cc8..91f387db7 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 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 f0986a890..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.32. 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 35e1385e6..7faf2fbd0 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v1 "acme.corp/pkg/apis/example/v1" - examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + examplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" ) // fakeClusterTestTypes implements ClusterTestTypeInterface type fakeClusterTestTypes struct { - *gentype.FakeClientWithList[*v1.ClusterTestType, *v1.ClusterTestTypeList] + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *examplev1.ClusterTestTypeApplyConfiguration] Fake *FakeExampleV1 } -func newFakeClusterTestTypes(fake *FakeExampleV1) examplev1.ClusterTestTypeInterface { +func newFakeClusterTestTypes(fake *FakeExampleV1) typedexamplev1.ClusterTestTypeInterface { return &fakeClusterTestTypes{ - gentype.NewFakeClientWithList[*v1.ClusterTestType, *v1.ClusterTestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *examplev1.ClusterTestTypeApplyConfiguration]( fake.Fake, "", v1.SchemeGroupVersion.WithResource("clustertesttypes"), 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 c6bdada54..bde4c56e6 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake 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 7900dc798..e5200d787 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -26,18 +26,19 @@ import ( testing "k8s.io/client-go/testing" v1 "acme.corp/pkg/apis/example/v1" - examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" + examplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" ) // fakeTestTypes implements TestTypeInterface type fakeTestTypes struct { - *gentype.FakeClientWithList[*v1.TestType, *v1.TestTypeList] + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *examplev1.TestTypeApplyConfiguration] Fake *FakeExampleV1 } -func newFakeTestTypes(fake *FakeExampleV1, namespace string) examplev1.TestTypeInterface { +func newFakeTestTypes(fake *FakeExampleV1, namespace string) typedexamplev1.TestTypeInterface { return &fakeTestTypes{ - gentype.NewFakeClientWithList[*v1.TestType, *v1.TestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *examplev1.TestTypeApplyConfiguration]( fake.Fake, namespace, v1.SchemeGroupVersion.WithResource("testtypes"), 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 d61df8d27..f82a07b84 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package 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 bb8ef7c9f..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.32. 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 9cf6b7617..c9b6dc7f3 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/testtype.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" examplev1 "acme.corp/pkg/apis/example/v1" + applyconfigurationsexamplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -46,6 +47,7 @@ type TestTypeInterface interface { 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 *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) @@ -55,13 +57,13 @@ type TestTypeInterface interface { // testTypes implements TestTypeInterface type testTypes struct { - *gentype.ClientWithList[*examplev1.TestType, *examplev1.TestTypeList] + *gentype.ClientWithListAndApply[*examplev1.TestType, *examplev1.TestTypeList, *applyconfigurationsexamplev1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *ExampleV1Client, namespace string) *testTypes { return &testTypes{ - gentype.NewClientWithList[*examplev1.TestType, *examplev1.TestTypeList]( + gentype.NewClientWithListAndApply[*examplev1.TestType, *examplev1.TestTypeList, *applyconfigurationsexamplev1.TestTypeApplyConfiguration]( "testtypes", c.RESTClient(), scheme.ParameterCodec, 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 2d838a63d..e8317cf6e 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1/withoutverbtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1/withoutverbtype.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 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 30e122584..ac8813a67 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/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 client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1alpha1 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + applyconfigurationsexamplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -48,18 +49,21 @@ type ClusterTestTypeInterface interface { 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 *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 { - *gentype.ClientWithList[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList] + *gentype.ClientWithListAndApply[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList, *applyconfigurationsexamplev1alpha1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *ExampleV1alpha1Client) *clusterTestTypes { return &clusterTestTypes{ - gentype.NewClientWithList[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList]( + gentype.NewClientWithListAndApply[*examplev1alpha1.ClusterTestType, *examplev1alpha1.ClusterTestTypeList, *applyconfigurationsexamplev1alpha1.ClusterTestTypeApplyConfiguration]( "clustertesttypes", c.RESTClient(), scheme.ParameterCodec, 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 8a0e7341c..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.32. 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 8ed8908e9..ccb6497db 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1alpha1 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 f0986a890..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.32. 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 a5db3c151..c816d1c1f 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" + typedexamplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" ) // fakeClusterTestTypes implements ClusterTestTypeInterface type fakeClusterTestTypes struct { - *gentype.FakeClientWithList[*v1alpha1.ClusterTestType, *v1alpha1.ClusterTestTypeList] + *gentype.FakeClientWithListAndApply[*v1alpha1.ClusterTestType, *v1alpha1.ClusterTestTypeList, *examplev1alpha1.ClusterTestTypeApplyConfiguration] Fake *FakeExampleV1alpha1 } -func newFakeClusterTestTypes(fake *FakeExampleV1alpha1) examplev1alpha1.ClusterTestTypeInterface { +func newFakeClusterTestTypes(fake *FakeExampleV1alpha1) typedexamplev1alpha1.ClusterTestTypeInterface { return &fakeClusterTestTypes{ - gentype.NewFakeClientWithList[*v1alpha1.ClusterTestType, *v1alpha1.ClusterTestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1alpha1.ClusterTestType, *v1alpha1.ClusterTestTypeList, *examplev1alpha1.ClusterTestTypeApplyConfiguration]( fake.Fake, "", v1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"), 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 d1dedcb31..d0684eef2 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake 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 4161994e8..e18bad8a1 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" + typedexamplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" ) // fakeTestTypes implements TestTypeInterface type fakeTestTypes struct { - *gentype.FakeClientWithList[*v1alpha1.TestType, *v1alpha1.TestTypeList] + *gentype.FakeClientWithListAndApply[*v1alpha1.TestType, *v1alpha1.TestTypeList, *examplev1alpha1.TestTypeApplyConfiguration] Fake *FakeExampleV1alpha1 } -func newFakeTestTypes(fake *FakeExampleV1alpha1, namespace string) examplev1alpha1.TestTypeInterface { +func newFakeTestTypes(fake *FakeExampleV1alpha1, namespace string) typedexamplev1alpha1.TestTypeInterface { return &fakeTestTypes{ - gentype.NewFakeClientWithList[*v1alpha1.TestType, *v1alpha1.TestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1alpha1.TestType, *v1alpha1.TestTypeList, *examplev1alpha1.TestTypeApplyConfiguration]( fake.Fake, namespace, v1alpha1.SchemeGroupVersion.WithResource("testtypes"), 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 5f5cb68f6..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.32. 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 dda43ca27..2425760a2 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1alpha1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/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 client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1alpha1 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + applyconfigurationsexamplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -46,18 +47,19 @@ type TestTypeInterface interface { 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 *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 { - *gentype.ClientWithList[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList] + *gentype.ClientWithListAndApply[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList, *applyconfigurationsexamplev1alpha1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *ExampleV1alpha1Client, namespace string) *testTypes { return &testTypes{ - gentype.NewClientWithList[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList]( + gentype.NewClientWithListAndApply[*examplev1alpha1.TestType, *examplev1alpha1.TestTypeList, *applyconfigurationsexamplev1alpha1.TestTypeApplyConfiguration]( "testtypes", c.RESTClient(), scheme.ParameterCodec, 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 02e7fc54e..b2a28fb71 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/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 client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1beta1 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + applyconfigurationsexamplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -48,18 +49,21 @@ type ClusterTestTypeInterface interface { 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 *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 { - *gentype.ClientWithList[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList] + *gentype.ClientWithListAndApply[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList, *applyconfigurationsexamplev1beta1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *ExampleV1beta1Client) *clusterTestTypes { return &clusterTestTypes{ - gentype.NewClientWithList[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList]( + gentype.NewClientWithListAndApply[*examplev1beta1.ClusterTestType, *examplev1beta1.ClusterTestTypeList, *applyconfigurationsexamplev1beta1.ClusterTestTypeApplyConfiguration]( "clustertesttypes", c.RESTClient(), scheme.ParameterCodec, 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 c0c0a5773..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.32. 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 5d1503fc7..6a6baf4fa 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1beta1 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 f0986a890..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.32. 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 372ff9ac8..ed25f0305 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v1beta1 "acme.corp/pkg/apis/example/v1beta1" - examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" + typedexamplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" ) // fakeClusterTestTypes implements ClusterTestTypeInterface type fakeClusterTestTypes struct { - *gentype.FakeClientWithList[*v1beta1.ClusterTestType, *v1beta1.ClusterTestTypeList] + *gentype.FakeClientWithListAndApply[*v1beta1.ClusterTestType, *v1beta1.ClusterTestTypeList, *examplev1beta1.ClusterTestTypeApplyConfiguration] Fake *FakeExampleV1beta1 } -func newFakeClusterTestTypes(fake *FakeExampleV1beta1) examplev1beta1.ClusterTestTypeInterface { +func newFakeClusterTestTypes(fake *FakeExampleV1beta1) typedexamplev1beta1.ClusterTestTypeInterface { return &fakeClusterTestTypes{ - gentype.NewFakeClientWithList[*v1beta1.ClusterTestType, *v1beta1.ClusterTestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1beta1.ClusterTestType, *v1beta1.ClusterTestTypeList, *examplev1beta1.ClusterTestTypeApplyConfiguration]( fake.Fake, "", v1beta1.SchemeGroupVersion.WithResource("clustertesttypes"), 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 0445b6caa..3da890bb7 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake 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 191cc957d..656f9fe9b 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v1beta1 "acme.corp/pkg/apis/example/v1beta1" - examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" + typedexamplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" ) // fakeTestTypes implements TestTypeInterface type fakeTestTypes struct { - *gentype.FakeClientWithList[*v1beta1.TestType, *v1beta1.TestTypeList] + *gentype.FakeClientWithListAndApply[*v1beta1.TestType, *v1beta1.TestTypeList, *examplev1beta1.TestTypeApplyConfiguration] Fake *FakeExampleV1beta1 } -func newFakeTestTypes(fake *FakeExampleV1beta1, namespace string) examplev1beta1.TestTypeInterface { +func newFakeTestTypes(fake *FakeExampleV1beta1, namespace string) typedexamplev1beta1.TestTypeInterface { return &fakeTestTypes{ - gentype.NewFakeClientWithList[*v1beta1.TestType, *v1beta1.TestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1beta1.TestType, *v1beta1.TestTypeList, *examplev1beta1.TestTypeApplyConfiguration]( fake.Fake, namespace, v1beta1.SchemeGroupVersion.WithResource("testtypes"), 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 472448d46..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.32. 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 1ef7a501d..0db68286c 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/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 client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1beta1 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + applyconfigurationsexamplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -46,18 +47,19 @@ type TestTypeInterface interface { 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 { - *gentype.ClientWithList[*examplev1beta1.TestType, *examplev1beta1.TestTypeList] + *gentype.ClientWithListAndApply[*examplev1beta1.TestType, *examplev1beta1.TestTypeList, *applyconfigurationsexamplev1beta1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *ExampleV1beta1Client, namespace string) *testTypes { return &testTypes{ - gentype.NewClientWithList[*examplev1beta1.TestType, *examplev1beta1.TestTypeList]( + gentype.NewClientWithListAndApply[*examplev1beta1.TestType, *examplev1beta1.TestTypeList, *applyconfigurationsexamplev1beta1.TestTypeApplyConfiguration]( "testtypes", c.RESTClient(), scheme.ParameterCodec, 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 fa9a3f4fb..1b291ec2e 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v2/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/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 client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v2 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" examplev2 "acme.corp/pkg/apis/example/v2" + applyconfigurationsexamplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -48,18 +49,21 @@ type ClusterTestTypeInterface interface { 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 *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 { - *gentype.ClientWithList[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList] + *gentype.ClientWithListAndApply[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList, *applyconfigurationsexamplev2.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *ExampleV2Client) *clusterTestTypes { return &clusterTestTypes{ - gentype.NewClientWithList[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList]( + gentype.NewClientWithListAndApply[*examplev2.ClusterTestType, *examplev2.ClusterTestTypeList, *applyconfigurationsexamplev2.ClusterTestTypeApplyConfiguration]( "clustertesttypes", c.RESTClient(), scheme.ParameterCodec, 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 3bf1d9b5c..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.32. 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 670ee9626..87f7c560d 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v2 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 f0986a890..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.32. 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 8f0503258..9194f0c5d 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v2 "acme.corp/pkg/apis/example/v2" - examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + examplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" + typedexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" ) // fakeClusterTestTypes implements ClusterTestTypeInterface type fakeClusterTestTypes struct { - *gentype.FakeClientWithList[*v2.ClusterTestType, *v2.ClusterTestTypeList] + *gentype.FakeClientWithListAndApply[*v2.ClusterTestType, *v2.ClusterTestTypeList, *examplev2.ClusterTestTypeApplyConfiguration] Fake *FakeExampleV2 } -func newFakeClusterTestTypes(fake *FakeExampleV2) examplev2.ClusterTestTypeInterface { +func newFakeClusterTestTypes(fake *FakeExampleV2) typedexamplev2.ClusterTestTypeInterface { return &fakeClusterTestTypes{ - gentype.NewFakeClientWithList[*v2.ClusterTestType, *v2.ClusterTestTypeList]( + gentype.NewFakeClientWithListAndApply[*v2.ClusterTestType, *v2.ClusterTestTypeList, *examplev2.ClusterTestTypeApplyConfiguration]( fake.Fake, "", v2.SchemeGroupVersion.WithResource("clustertesttypes"), 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 c03142641..8a41c7e00 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake 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 91937b5eb..102cc8f07 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v2 "acme.corp/pkg/apis/example/v2" - examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" + examplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" + typedexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" ) // fakeTestTypes implements TestTypeInterface type fakeTestTypes struct { - *gentype.FakeClientWithList[*v2.TestType, *v2.TestTypeList] + *gentype.FakeClientWithListAndApply[*v2.TestType, *v2.TestTypeList, *examplev2.TestTypeApplyConfiguration] Fake *FakeExampleV2 } -func newFakeTestTypes(fake *FakeExampleV2, namespace string) examplev2.TestTypeInterface { +func newFakeTestTypes(fake *FakeExampleV2, namespace string) typedexamplev2.TestTypeInterface { return &fakeTestTypes{ - gentype.NewFakeClientWithList[*v2.TestType, *v2.TestTypeList]( + gentype.NewFakeClientWithListAndApply[*v2.TestType, *v2.TestTypeList, *examplev2.TestTypeApplyConfiguration]( fake.Fake, namespace, v2.SchemeGroupVersion.WithResource("testtypes"), 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 9c04368c0..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.32. 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 db53d7696..17dab8605 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v2/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/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 client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v2 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" examplev2 "acme.corp/pkg/apis/example/v2" + applyconfigurationsexamplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -46,18 +47,19 @@ type TestTypeInterface interface { 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 *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 { - *gentype.ClientWithList[*examplev2.TestType, *examplev2.TestTypeList] + *gentype.ClientWithListAndApply[*examplev2.TestType, *examplev2.TestTypeList, *applyconfigurationsexamplev2.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *ExampleV2Client, namespace string) *testTypes { return &testTypes{ - gentype.NewClientWithList[*examplev2.TestType, *examplev2.TestTypeList]( + gentype.NewClientWithListAndApply[*examplev2.TestType, *examplev2.TestTypeList, *applyconfigurationsexamplev2.TestTypeApplyConfiguration]( "testtypes", c.RESTClient(), scheme.ParameterCodec, 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 84380c1a6..4a3ac8f83 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example3/v1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example3/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" example3v1 "acme.corp/pkg/apis/example3/v1" + applyconfigurationsexample3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -48,18 +49,21 @@ type ClusterTestTypeInterface interface { 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 *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 { - *gentype.ClientWithList[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList] + *gentype.ClientWithListAndApply[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList, *applyconfigurationsexample3v1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *Example3V1Client) *clusterTestTypes { return &clusterTestTypes{ - gentype.NewClientWithList[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList]( + gentype.NewClientWithListAndApply[*example3v1.ClusterTestType, *example3v1.ClusterTestTypeList, *applyconfigurationsexample3v1.ClusterTestTypeApplyConfiguration]( "clustertesttypes", c.RESTClient(), scheme.ParameterCodec, 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 8f148c5b8..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.32. 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 4e2b715c7..31a8e5f01 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 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 f0986a890..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.32. 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 c76a79191..c67d612ee 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v1 "acme.corp/pkg/apis/example3/v1" - example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + example3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" + typedexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" ) // fakeClusterTestTypes implements ClusterTestTypeInterface type fakeClusterTestTypes struct { - *gentype.FakeClientWithList[*v1.ClusterTestType, *v1.ClusterTestTypeList] + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *example3v1.ClusterTestTypeApplyConfiguration] Fake *FakeExample3V1 } -func newFakeClusterTestTypes(fake *FakeExample3V1) example3v1.ClusterTestTypeInterface { +func newFakeClusterTestTypes(fake *FakeExample3V1) typedexample3v1.ClusterTestTypeInterface { return &fakeClusterTestTypes{ - gentype.NewFakeClientWithList[*v1.ClusterTestType, *v1.ClusterTestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *example3v1.ClusterTestTypeApplyConfiguration]( fake.Fake, "", v1.SchemeGroupVersion.WithResource("clustertesttypes"), 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 6d71a72dd..ce769852e 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake 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 34497601b..b155f2d5c 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -27,18 +27,19 @@ import ( examplev1 "acme.corp/pkg/apis/example/v1" v1 "acme.corp/pkg/apis/example3/v1" - example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + example3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" + typedexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" ) // fakeTestTypes implements TestTypeInterface type fakeTestTypes struct { - *gentype.FakeClientWithList[*v1.TestType, *v1.TestTypeList] + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *example3v1.TestTypeApplyConfiguration] Fake *FakeExample3V1 } -func newFakeTestTypes(fake *FakeExample3V1, namespace string) example3v1.TestTypeInterface { +func newFakeTestTypes(fake *FakeExample3V1, namespace string) typedexample3v1.TestTypeInterface { return &fakeTestTypes{ - gentype.NewFakeClientWithList[*v1.TestType, *v1.TestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *example3v1.TestTypeApplyConfiguration]( fake.Fake, namespace, v1.SchemeGroupVersion.WithResource("testtypes"), 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 bb3aba146..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.32. 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 e274356ef..9be19097e 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example3/v1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example3/v1/testtype.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 @@ -28,6 +28,7 @@ import ( 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" ) @@ -47,6 +48,7 @@ type TestTypeInterface interface { 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 *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) @@ -56,13 +58,13 @@ type TestTypeInterface interface { // testTypes implements TestTypeInterface type testTypes struct { - *gentype.ClientWithList[*example3v1.TestType, *example3v1.TestTypeList] + *gentype.ClientWithListAndApply[*example3v1.TestType, *example3v1.TestTypeList, *applyconfigurationsexample3v1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *Example3V1Client, namespace string) *testTypes { return &testTypes{ - gentype.NewClientWithList[*example3v1.TestType, *example3v1.TestTypeList]( + gentype.NewClientWithListAndApply[*example3v1.TestType, *example3v1.TestTypeList, *applyconfigurationsexample3v1.TestTypeApplyConfiguration]( "testtypes", c.RESTClient(), scheme.ParameterCodec, diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/clustertesttype.go index 08757025c..310442fe8 100644 --- a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -48,18 +49,21 @@ type ClusterTestTypeInterface interface { 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.ClientWithList[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList] + *gentype.ClientWithListAndApply[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList, *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *ExampleDashedV1Client) *clusterTestTypes { return &clusterTestTypes{ - gentype.NewClientWithList[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList]( + gentype.NewClientWithListAndApply[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList, *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration]( "clustertesttypes", c.RESTClient(), scheme.ParameterCodec, diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/doc.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/doc.go index 8f148c5b8..278483ba7 100644 --- a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/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.32. 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/exampledashed/v1/exampledashed_client.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go index 75725dd0c..e777ee6c7 100644 --- a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/exampledashed_client.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 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 index f0986a890..e388f2918 100644 --- a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/doc.go +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/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.32. 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/exampledashed/v1/fake/fake_clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_clustertesttype.go index 4f129cb3e..132de6245 100644 --- 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 @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v1 "acme.corp/pkg/apis/exampledashed/v1" - exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + exampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + typedexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" ) // fakeClusterTestTypes implements ClusterTestTypeInterface type fakeClusterTestTypes struct { - *gentype.FakeClientWithList[*v1.ClusterTestType, *v1.ClusterTestTypeList] + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *exampledashedv1.ClusterTestTypeApplyConfiguration] Fake *FakeExampleDashedV1 } -func newFakeClusterTestTypes(fake *FakeExampleDashedV1) exampledashedv1.ClusterTestTypeInterface { +func newFakeClusterTestTypes(fake *FakeExampleDashedV1) typedexampledashedv1.ClusterTestTypeInterface { return &fakeClusterTestTypes{ - gentype.NewFakeClientWithList[*v1.ClusterTestType, *v1.ClusterTestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *exampledashedv1.ClusterTestTypeApplyConfiguration]( fake.Fake, "", v1.SchemeGroupVersion.WithResource("clustertesttypes"), 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 index 86a125754..237b4ba10 100644 --- 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 @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake 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 index 625bdab71..df07fef26 100644 --- 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 @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -27,18 +27,19 @@ import ( examplev1 "acme.corp/pkg/apis/example/v1" v1 "acme.corp/pkg/apis/exampledashed/v1" - exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + exampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + typedexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" ) // fakeTestTypes implements TestTypeInterface type fakeTestTypes struct { - *gentype.FakeClientWithList[*v1.TestType, *v1.TestTypeList] + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *exampledashedv1.TestTypeApplyConfiguration] Fake *FakeExampleDashedV1 } -func newFakeTestTypes(fake *FakeExampleDashedV1, namespace string) exampledashedv1.TestTypeInterface { +func newFakeTestTypes(fake *FakeExampleDashedV1, namespace string) typedexampledashedv1.TestTypeInterface { return &fakeTestTypes{ - gentype.NewFakeClientWithList[*v1.TestType, *v1.TestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *exampledashedv1.TestTypeApplyConfiguration]( fake.Fake, namespace, v1.SchemeGroupVersion.WithResource("testtypes"), diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/generated_expansion.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/generated_expansion.go index bb3aba146..2b821d5ff 100644 --- a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/generated_expansion.go +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/testtype.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/testtype.go index bdf9af896..f30d97012 100644 --- a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/testtype.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 @@ -28,6 +28,7 @@ import ( 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" ) @@ -47,6 +48,7 @@ type TestTypeInterface interface { 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) @@ -56,13 +58,13 @@ type TestTypeInterface interface { // testTypes implements TestTypeInterface type testTypes struct { - *gentype.ClientWithList[*exampledashedv1.TestType, *exampledashedv1.TestTypeList] + *gentype.ClientWithListAndApply[*exampledashedv1.TestType, *exampledashedv1.TestTypeList, *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *ExampleDashedV1Client, namespace string) *testTypes { return &testTypes{ - gentype.NewClientWithList[*exampledashedv1.TestType, *exampledashedv1.TestTypeList]( + gentype.NewClientWithListAndApply[*exampledashedv1.TestType, *exampledashedv1.TestTypeList, *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration]( "testtypes", c.RESTClient(), scheme.ParameterCodec, 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 50fe736a3..13d17c8bd 100644 --- a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + applyconfigurationsexistinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -48,18 +49,21 @@ type ClusterTestTypeInterface interface { 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 *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 { - *gentype.ClientWithList[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList] + *gentype.ClientWithListAndApply[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList, *applyconfigurationsexistinginterfacesv1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *ExistinginterfacesV1Client) *clusterTestTypes { return &clusterTestTypes{ - gentype.NewClientWithList[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList]( + gentype.NewClientWithListAndApply[*existinginterfacesv1.ClusterTestType, *existinginterfacesv1.ClusterTestTypeList, *applyconfigurationsexistinginterfacesv1.ClusterTestTypeApplyConfiguration]( "clustertesttypes", c.RESTClient(), scheme.ParameterCodec, 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 8f148c5b8..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.32. 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 06f561172..4e9cb9e3b 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 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 f0986a890..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.32. 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 d4385a5da..a6d14549e 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v1 "acme.corp/pkg/apis/existinginterfaces/v1" - existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" + typedexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" ) // fakeClusterTestTypes implements ClusterTestTypeInterface type fakeClusterTestTypes struct { - *gentype.FakeClientWithList[*v1.ClusterTestType, *v1.ClusterTestTypeList] + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *existinginterfacesv1.ClusterTestTypeApplyConfiguration] Fake *FakeExistinginterfacesV1 } -func newFakeClusterTestTypes(fake *FakeExistinginterfacesV1) existinginterfacesv1.ClusterTestTypeInterface { +func newFakeClusterTestTypes(fake *FakeExistinginterfacesV1) typedexistinginterfacesv1.ClusterTestTypeInterface { return &fakeClusterTestTypes{ - gentype.NewFakeClientWithList[*v1.ClusterTestType, *v1.ClusterTestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *existinginterfacesv1.ClusterTestTypeApplyConfiguration]( fake.Fake, "", v1.SchemeGroupVersion.WithResource("clustertesttypes"), 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 f15002c4a..7833c7068 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake 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 eb4a10fd0..6d238ec7f 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v1 "acme.corp/pkg/apis/existinginterfaces/v1" - existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" + typedexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" ) // fakeTestTypes implements TestTypeInterface type fakeTestTypes struct { - *gentype.FakeClientWithList[*v1.TestType, *v1.TestTypeList] + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *existinginterfacesv1.TestTypeApplyConfiguration] Fake *FakeExistinginterfacesV1 } -func newFakeTestTypes(fake *FakeExistinginterfacesV1, namespace string) existinginterfacesv1.TestTypeInterface { +func newFakeTestTypes(fake *FakeExistinginterfacesV1, namespace string) typedexistinginterfacesv1.TestTypeInterface { return &fakeTestTypes{ - gentype.NewFakeClientWithList[*v1.TestType, *v1.TestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *existinginterfacesv1.TestTypeApplyConfiguration]( fake.Fake, namespace, v1.SchemeGroupVersion.WithResource("testtypes"), 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 bb3aba146..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.32. 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 e304b20f0..26af81174 100644 --- a/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/testtype.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + applyconfigurationsexistinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -46,18 +47,19 @@ type TestTypeInterface interface { 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 *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 { - *gentype.ClientWithList[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList] + *gentype.ClientWithListAndApply[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList, *applyconfigurationsexistinginterfacesv1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *ExistinginterfacesV1Client, namespace string) *testTypes { return &testTypes{ - gentype.NewClientWithList[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList]( + gentype.NewClientWithListAndApply[*existinginterfacesv1.TestType, *existinginterfacesv1.TestTypeList, *applyconfigurationsexistinginterfacesv1.TestTypeApplyConfiguration]( "testtypes", c.RESTClient(), scheme.ParameterCodec, 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 ccdfbe8a5..913792c59 100644 --- a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/clustertesttype.go +++ b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + applyconfigurationssecondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -48,18 +49,21 @@ type ClusterTestTypeInterface interface { 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 *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 { - *gentype.ClientWithList[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList] + *gentype.ClientWithListAndApply[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList, *applyconfigurationssecondexamplev1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *SecondexampleV1Client) *clusterTestTypes { return &clusterTestTypes{ - gentype.NewClientWithList[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList]( + gentype.NewClientWithListAndApply[*secondexamplev1.ClusterTestType, *secondexamplev1.ClusterTestTypeList, *applyconfigurationssecondexamplev1.ClusterTestTypeApplyConfiguration]( "clustertesttypes", c.RESTClient(), scheme.ParameterCodec, 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 8f148c5b8..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.32. 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 f0986a890..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.32. 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 ddb1411e8..ac8f8c157 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v1 "acme.corp/pkg/apis/secondexample/v1" - secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" + typedsecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" ) // fakeClusterTestTypes implements ClusterTestTypeInterface type fakeClusterTestTypes struct { - *gentype.FakeClientWithList[*v1.ClusterTestType, *v1.ClusterTestTypeList] + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *secondexamplev1.ClusterTestTypeApplyConfiguration] Fake *FakeSecondexampleV1 } -func newFakeClusterTestTypes(fake *FakeSecondexampleV1) secondexamplev1.ClusterTestTypeInterface { +func newFakeClusterTestTypes(fake *FakeSecondexampleV1) typedsecondexamplev1.ClusterTestTypeInterface { return &fakeClusterTestTypes{ - gentype.NewFakeClientWithList[*v1.ClusterTestType, *v1.ClusterTestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *secondexamplev1.ClusterTestTypeApplyConfiguration]( fake.Fake, "", v1.SchemeGroupVersion.WithResource("clustertesttypes"), 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 fa287642c..218a87d2b 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake 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 b5ecbb072..0d70e2a6c 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package fake @@ -22,18 +22,19 @@ import ( gentype "k8s.io/client-go/gentype" v1 "acme.corp/pkg/apis/secondexample/v1" - secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" + typedsecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" ) // fakeTestTypes implements TestTypeInterface type fakeTestTypes struct { - *gentype.FakeClientWithList[*v1.TestType, *v1.TestTypeList] + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *secondexamplev1.TestTypeApplyConfiguration] Fake *FakeSecondexampleV1 } -func newFakeTestTypes(fake *FakeSecondexampleV1, namespace string) secondexamplev1.TestTypeInterface { +func newFakeTestTypes(fake *FakeSecondexampleV1, namespace string) typedsecondexamplev1.TestTypeInterface { return &fakeTestTypes{ - gentype.NewFakeClientWithList[*v1.TestType, *v1.TestTypeList]( + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *secondexamplev1.TestTypeApplyConfiguration]( fake.Fake, namespace, v1.SchemeGroupVersion.WithResource("testtypes"), 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 bb3aba146..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.32. 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 1b2307f0a..44cd09f0d 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,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by client-gen-v0.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 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 426dac0d9..d8e6cfea4 100644 --- a/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/secondexample/v1/testtype.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.32. DO NOT EDIT. +// Code generated by client-gen. DO NOT EDIT. package v1 @@ -27,6 +27,7 @@ import ( gentype "k8s.io/client-go/gentype" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + applyconfigurationssecondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" scheme "acme.corp/pkg/generated/clientset/versioned/scheme" ) @@ -46,18 +47,19 @@ type TestTypeInterface interface { 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 *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 { - *gentype.ClientWithList[*secondexamplev1.TestType, *secondexamplev1.TestTypeList] + *gentype.ClientWithListAndApply[*secondexamplev1.TestType, *secondexamplev1.TestTypeList, *applyconfigurationssecondexamplev1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *SecondexampleV1Client, namespace string) *testTypes { return &testTypes{ - gentype.NewClientWithList[*secondexamplev1.TestType, *secondexamplev1.TestTypeList]( + gentype.NewClientWithListAndApply[*secondexamplev1.TestType, *secondexamplev1.TestTypeList, *applyconfigurationssecondexamplev1.TestTypeApplyConfiguration]( "testtypes", c.RESTClient(), scheme.ParameterCodec, diff --git a/examples/pkg/generated/informers/externalversions/example/interface.go b/examples/pkg/generated/informers/externalversions/example/interface.go index a65045266..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.32. 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 a2eaf8f23..27c516b36 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/example/v1/interface.go b/examples/pkg/generated/informers/externalversions/example/v1/interface.go index 4ab82bea4..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.32. 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 55a1af242..95f40d5d4 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1/testtype.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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/example/v1alpha1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example/v1alpha1/clustertesttype.go index 1edd07d44..662290ea6 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/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 informer-gen-v0.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1alpha1 diff --git a/examples/pkg/generated/informers/externalversions/example/v1alpha1/interface.go b/examples/pkg/generated/informers/externalversions/example/v1alpha1/interface.go index 6f5fa9e4f..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.32. 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 99b8a9e67..cb68e59ae 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1alpha1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/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 informer-gen-v0.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1alpha1 diff --git a/examples/pkg/generated/informers/externalversions/example/v1beta1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example/v1beta1/clustertesttype.go index 8912a45f2..0a0268e3a 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1beta1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/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 informer-gen-v0.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1beta1 diff --git a/examples/pkg/generated/informers/externalversions/example/v1beta1/interface.go b/examples/pkg/generated/informers/externalversions/example/v1beta1/interface.go index a0ec3c8c0..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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1beta1 diff --git a/examples/pkg/generated/informers/externalversions/example/v1beta1/testtype.go b/examples/pkg/generated/informers/externalversions/example/v1beta1/testtype.go index 0f90538b9..1ae619b52 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1beta1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/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 informer-gen-v0.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1beta1 diff --git a/examples/pkg/generated/informers/externalversions/example/v2/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example/v2/clustertesttype.go index f32aca9af..e82f5b971 100644 --- a/examples/pkg/generated/informers/externalversions/example/v2/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/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 informer-gen-v0.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v2 diff --git a/examples/pkg/generated/informers/externalversions/example/v2/interface.go b/examples/pkg/generated/informers/externalversions/example/v2/interface.go index 971414889..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.32. 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 0295c65fa..3c74261d3 100644 --- a/examples/pkg/generated/informers/externalversions/example/v2/testtype.go +++ b/examples/pkg/generated/informers/externalversions/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 informer-gen-v0.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v2 diff --git a/examples/pkg/generated/informers/externalversions/example3/interface.go b/examples/pkg/generated/informers/externalversions/example3/interface.go index 888f6b55d..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.32. 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 75010f173..65b76d98d 100644 --- a/examples/pkg/generated/informers/externalversions/example3/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/example3/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/example3/v1/interface.go b/examples/pkg/generated/informers/externalversions/example3/v1/interface.go index 4ab82bea4..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.32. 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 ac72d728f..3e3cef93a 100644 --- a/examples/pkg/generated/informers/externalversions/example3/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/example3/v1/testtype.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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/exampledashed/interface.go b/examples/pkg/generated/informers/externalversions/exampledashed/interface.go index 9d4070faa..d794d48ae 100644 --- a/examples/pkg/generated/informers/externalversions/exampledashed/interface.go +++ b/examples/pkg/generated/informers/externalversions/exampledashed/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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package exampledashed diff --git a/examples/pkg/generated/informers/externalversions/exampledashed/v1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/exampledashed/v1/clustertesttype.go index bcfee5eae..04f52c61a 100644 --- a/examples/pkg/generated/informers/externalversions/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/exampledashed/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/exampledashed/v1/interface.go b/examples/pkg/generated/informers/externalversions/exampledashed/v1/interface.go index 4ab82bea4..4ba2de328 100644 --- a/examples/pkg/generated/informers/externalversions/exampledashed/v1/interface.go +++ b/examples/pkg/generated/informers/externalversions/exampledashed/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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/exampledashed/v1/testtype.go b/examples/pkg/generated/informers/externalversions/exampledashed/v1/testtype.go index 4d80f8b48..599fad46b 100644 --- a/examples/pkg/generated/informers/externalversions/exampledashed/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/exampledashed/v1/testtype.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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/existinginterfaces/interface.go b/examples/pkg/generated/informers/externalversions/existinginterfaces/interface.go index 3b40e6693..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.32. 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 0d3da17e0..97ee66945 100644 --- a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/interface.go b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/interface.go index 4ab82bea4..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.32. 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 3db89206d..e503c3632 100644 --- a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/testtype.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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/factory.go b/examples/pkg/generated/informers/externalversions/factory.go index f53b7bd88..4fde47a96 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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package externalversions diff --git a/examples/pkg/generated/informers/externalversions/generic.go b/examples/pkg/generated/informers/externalversions/generic.go index bebcffc6a..42fe637b8 100644 --- a/examples/pkg/generated/informers/externalversions/generic.go +++ b/examples/pkg/generated/informers/externalversions/generic.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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package externalversions diff --git a/examples/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go b/examples/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go index 9a6cf5d11..303e1166c 100644 --- a/examples/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/examples/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package internalinterfaces diff --git a/examples/pkg/generated/informers/externalversions/secondexample/interface.go b/examples/pkg/generated/informers/externalversions/secondexample/interface.go index ad7336600..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.32. 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 c7c9301ec..54c2eef88 100644 --- a/examples/pkg/generated/informers/externalversions/secondexample/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/secondexample/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/informers/externalversions/secondexample/v1/interface.go b/examples/pkg/generated/informers/externalversions/secondexample/v1/interface.go index 4ab82bea4..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.32. 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 5e88267b1..c7c3131c7 100644 --- a/examples/pkg/generated/informers/externalversions/secondexample/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/secondexample/v1/testtype.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.32. DO NOT EDIT. +// Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/example/v1/clustertesttype.go b/examples/pkg/generated/listers/example/v1/clustertesttype.go index 2f5145fe0..5775c071d 100644 --- a/examples/pkg/generated/listers/example/v1/clustertesttype.go +++ b/examples/pkg/generated/listers/example/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/example/v1/expansion_generated.go b/examples/pkg/generated/listers/example/v1/expansion_generated.go index 6272900fa..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.32. 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 96be33c8a..62ed10dd6 100644 --- a/examples/pkg/generated/listers/example/v1/testtype.go +++ b/examples/pkg/generated/listers/example/v1/testtype.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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/example/v1/withoutverbtype.go b/examples/pkg/generated/listers/example/v1/withoutverbtype.go index 830efb8d2..afe39a649 100644 --- a/examples/pkg/generated/listers/example/v1/withoutverbtype.go +++ b/examples/pkg/generated/listers/example/v1/withoutverbtype.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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/example/v1alpha1/clustertesttype.go b/examples/pkg/generated/listers/example/v1alpha1/clustertesttype.go index 9d9395789..91dd889b9 100644 --- a/examples/pkg/generated/listers/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/generated/listers/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 lister-gen-v0.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1alpha1 diff --git a/examples/pkg/generated/listers/example/v1alpha1/expansion_generated.go b/examples/pkg/generated/listers/example/v1alpha1/expansion_generated.go index 0869797e1..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.32. 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 55f5587df..03a099b05 100644 --- a/examples/pkg/generated/listers/example/v1alpha1/testtype.go +++ b/examples/pkg/generated/listers/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 lister-gen-v0.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1alpha1 diff --git a/examples/pkg/generated/listers/example/v1beta1/clustertesttype.go b/examples/pkg/generated/listers/example/v1beta1/clustertesttype.go index f2431ea04..8475fc81c 100644 --- a/examples/pkg/generated/listers/example/v1beta1/clustertesttype.go +++ b/examples/pkg/generated/listers/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 lister-gen-v0.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1beta1 diff --git a/examples/pkg/generated/listers/example/v1beta1/expansion_generated.go b/examples/pkg/generated/listers/example/v1beta1/expansion_generated.go index 2e3daf652..de94ad494 100644 --- a/examples/pkg/generated/listers/example/v1beta1/expansion_generated.go +++ b/examples/pkg/generated/listers/example/v1beta1/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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1beta1 diff --git a/examples/pkg/generated/listers/example/v1beta1/testtype.go b/examples/pkg/generated/listers/example/v1beta1/testtype.go index f26518493..0ecac7616 100644 --- a/examples/pkg/generated/listers/example/v1beta1/testtype.go +++ b/examples/pkg/generated/listers/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 lister-gen-v0.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1beta1 diff --git a/examples/pkg/generated/listers/example/v2/clustertesttype.go b/examples/pkg/generated/listers/example/v2/clustertesttype.go index 52748ff24..658dcf798 100644 --- a/examples/pkg/generated/listers/example/v2/clustertesttype.go +++ b/examples/pkg/generated/listers/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 lister-gen-v0.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v2 diff --git a/examples/pkg/generated/listers/example/v2/expansion_generated.go b/examples/pkg/generated/listers/example/v2/expansion_generated.go index 30b74f294..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.32. 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 abfd00984..b351e5286 100644 --- a/examples/pkg/generated/listers/example/v2/testtype.go +++ b/examples/pkg/generated/listers/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 lister-gen-v0.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v2 diff --git a/examples/pkg/generated/listers/example3/v1/clustertesttype.go b/examples/pkg/generated/listers/example3/v1/clustertesttype.go index 98a0ff9b3..9cb403a7c 100644 --- a/examples/pkg/generated/listers/example3/v1/clustertesttype.go +++ b/examples/pkg/generated/listers/example3/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/example3/v1/expansion_generated.go b/examples/pkg/generated/listers/example3/v1/expansion_generated.go index f82056382..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.32. 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 224242b70..66bf415a7 100644 --- a/examples/pkg/generated/listers/example3/v1/testtype.go +++ b/examples/pkg/generated/listers/example3/v1/testtype.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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/generated/listers/exampledashed/v1/clustertesttype.go index eb6d13bb8..57c69342e 100644 --- a/examples/pkg/generated/listers/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/generated/listers/exampledashed/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/exampledashed/v1/expansion_generated.go b/examples/pkg/generated/listers/exampledashed/v1/expansion_generated.go index f82056382..6080bffc0 100644 --- a/examples/pkg/generated/listers/exampledashed/v1/expansion_generated.go +++ b/examples/pkg/generated/listers/exampledashed/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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/exampledashed/v1/testtype.go b/examples/pkg/generated/listers/exampledashed/v1/testtype.go index bbe40773d..0e05b99cf 100644 --- a/examples/pkg/generated/listers/exampledashed/v1/testtype.go +++ b/examples/pkg/generated/listers/exampledashed/v1/testtype.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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/existinginterfaces/v1/clustertesttype.go b/examples/pkg/generated/listers/existinginterfaces/v1/clustertesttype.go index dbff40cb4..099964da7 100644 --- a/examples/pkg/generated/listers/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/generated/listers/existinginterfaces/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/existinginterfaces/v1/expansion_generated.go b/examples/pkg/generated/listers/existinginterfaces/v1/expansion_generated.go index f82056382..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.32. 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 6a2ba1c1a..819c40ecf 100644 --- a/examples/pkg/generated/listers/existinginterfaces/v1/testtype.go +++ b/examples/pkg/generated/listers/existinginterfaces/v1/testtype.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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/secondexample/v1/clustertesttype.go b/examples/pkg/generated/listers/secondexample/v1/clustertesttype.go index 025923f22..a8406e5e8 100644 --- a/examples/pkg/generated/listers/secondexample/v1/clustertesttype.go +++ b/examples/pkg/generated/listers/secondexample/v1/clustertesttype.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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/generated/listers/secondexample/v1/expansion_generated.go b/examples/pkg/generated/listers/secondexample/v1/expansion_generated.go index f82056382..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.32. 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 6382c34f5..e3ffe088f 100644 --- a/examples/pkg/generated/listers/secondexample/v1/testtype.go +++ b/examples/pkg/generated/listers/secondexample/v1/testtype.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.32. DO NOT EDIT. +// Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/examples/pkg/kcp/clients/clientset/versioned/clientset.go b/examples/pkg/kcp/clients/clientset/versioned/clientset.go index e4491fcd4..5330b2f5c 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/clientset.go +++ b/examples/pkg/kcp/clients/clientset/versioned/clientset.go @@ -14,20 +14,20 @@ 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 import ( - "fmt" - "net/http" + fmt "fmt" + http "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" + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" client "acme.corp/pkg/generated/clientset/versioned" examplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1" @@ -43,31 +43,31 @@ import ( type ClusterInterface interface { Cluster(logicalcluster.Path) client.Interface Discovery() discovery.DiscoveryInterface - ExampleDashedV1() exampledashedv1.ExampleDashedV1ClusterInterface - 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] - exampledashedV1 *exampledashedv1.ExampleDashedV1ClusterClient - 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,16 +75,6 @@ func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { return c.DiscoveryClient } -// ExampleDashedV1 retrieves the ExampleDashedV1ClusterClient. -func (c *ClusterClientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1ClusterInterface { - return c.exampledashedV1 -} - -// 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 @@ -105,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 @@ -167,27 +167,27 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli var cs ClusterClientset cs.clientCache = cache var err error - cs.exampledashedV1, err = exampledashedv1.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.exampleV1, err = examplev1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } - cs.example3V1, err = example3v1.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.exampleV1alpha1, err = examplev1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } - cs.exampleV1, err = examplev1.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.exampleV1beta1, err = examplev1beta1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } - cs.exampleV1alpha1, err = examplev1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.exampleV2, err = examplev2.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } - cs.exampleV1beta1, err = examplev1beta1.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.example3V1, err = example3v1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } - cs.exampleV2, err = examplev2.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.exampleDashedV1, err = exampledashedv1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } @@ -216,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 079018114..b8f557fa8 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go +++ b/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go @@ -14,7 +14,7 @@ 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 @@ -26,8 +26,8 @@ import ( "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" @@ -36,50 +36,55 @@ import ( 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" - fakeexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake" + 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" ) // 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,62 +94,62 @@ func (c *ClusterClientset) Tracker() kcptesting.ObjectTracker { return c.tracker } -// ExampleDashedV1 retrieves the ExampleDashedV1ClusterClient. -func (c *ClusterClientset) ExampleDashedV1() kcpexampledashedv1.ExampleDashedV1ClusterInterface { - return &fakeexampledashedv1.ExampleDashedV1ClusterClient{Fake: c.Fake} -} - -// 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 @@ -152,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 } @@ -161,42 +170,62 @@ func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { return c.tracker } -// ExampleDashedV1 retrieves the ExampleDashedV1Client. -func (c *Clientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1Interface { - return &fakeexampledashedv1.ExampleDashedV1Client{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...) -// Example3V1 retrieves the Example3V1Client. -func (c *Clientset) Example3V1() example3v1.Example3V1Interface { - return &fakeexample3v1.Example3V1Client{Fake: c.Fake, ClusterPath: c.clusterPath} + 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..c3dc5fe76 --- /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 ( + 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" +) + +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 aac661550..bd637672b 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go +++ b/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go @@ -14,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 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" + 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" @@ -39,12 +39,12 @@ var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - exampledashedv1.AddToScheme, - example3v1.AddToScheme, examplev1.AddToScheme, examplev1alpha1.AddToScheme, examplev1beta1.AddToScheme, examplev2.AddToScheme, + example3v1.AddToScheme, + exampledashedv1.AddToScheme, existinginterfacesv1.AddToScheme, secondexamplev1.AddToScheme, } @@ -66,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 3a96d500b..b042a2fca 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 @@ -14,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" 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" + apisexamplev1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 1e7e36fa4..0688ec1f6 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) type ExampleV1ClusterInterface interface { ExampleV1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter WithoutVerbTypesClusterGetter } @@ -40,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] } @@ -51,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} } @@ -67,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. @@ -83,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 } @@ -95,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 94baccdfa..2598f0592 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 @@ -14,186 +14,78 @@ 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" + 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" + 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" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example.dev", 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 +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, } - - 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 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 9a576de3b..a30d4e365 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 61d0d11ed..9fcd0d04f 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 @@ -14,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" + 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" - kcpexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/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" ) -var testTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example.dev", 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.") +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 &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) - } - } - return list, err +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexamplev1.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) 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 f2c158669..b860cabe6 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 @@ -14,47 +14,70 @@ 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" + 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" + 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" ) -var withoutVerbTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1", Resource: "withoutverbtypes"} -var withoutVerbTypesKind = schema.GroupVersionKind{Group: "example.dev", 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/example3/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/example3/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/example3/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 637798366..edd177a1c 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 @@ -14,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" 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" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -43,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. @@ -68,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 e937342af..24c84c018 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ import ( 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" + examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" ) // WithoutVerbTypesClusterGetter has a method to return a WithoutVerbTypeClusterInterface. @@ -34,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. @@ -49,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 41aa31422..9eb94dd6e 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 @@ -14,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" - 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" + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 b235912f4..55266843a 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) 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] } @@ -50,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. @@ -78,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 } @@ -90,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 fff689735..0600facf2 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 @@ -14,186 +14,78 @@ 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" + 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" + 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" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1alpha1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example.dev", 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 +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, } - - 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 } -// 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 ea9b3100b..d68bce28e 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 d891ec1ad..7ebc0937b 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 @@ -14,197 +14,87 @@ 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" + 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" + 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" ) -var testTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1alpha1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example.dev", Version: "v1alpha1", Kind: "TestType"} - -type testTypesClusterClient struct { - *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.") - } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1alpha1.TestType, *examplev1alpha1.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) (*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() +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, } - 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 } -// 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) typedkcpexamplev1alpha1.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) 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 97f8fae70..d57b00238 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 @@ -14,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" - 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" + typedexamplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -41,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. @@ -59,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 c76c30cb3..a28bd75de 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 @@ -14,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" - 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" + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 6b59d7eff..16f74f530 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) 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] } @@ -50,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. @@ -78,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 } @@ -90,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 bb282611b..48d43b212 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 @@ -14,186 +14,78 @@ 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" + 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" + 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" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1beta1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example.dev", 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 +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, } - - 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 } -// 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 9d8a00001..87bcf8f6c 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 56b1ad634..9df6d033b 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 @@ -14,197 +14,87 @@ 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" + 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" - kcpexamplev1beta1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/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" ) -var testTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1beta1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example.dev", Version: "v1beta1", Kind: "TestType"} - -type testTypesClusterClient struct { - *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.") - } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1beta1.TestType, *examplev1beta1.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) (*examplev1beta1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &examplev1beta1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() +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, } - list := &examplev1beta1.TestTypeList{ListMeta: obj.(*examplev1beta1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1beta1.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 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) typedkcpexamplev1beta1.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) examplev1beta1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexamplev1beta1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1beta1.TestType, *examplev1beta1.TestTypeList, *v1beta1.TestTypeApplyConfiguration] + Fake *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 -} - -// 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) (*examplev1beta1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &examplev1beta1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1beta1.TestTypeList{ListMeta: obj.(*examplev1beta1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1beta1.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) (*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 (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 -} - -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/listers/example/v1beta1/testtype_expansion.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/generated_expansion.go similarity index 68% rename from examples/pkg/kcpexisting/clients/listers/example/v1beta1/testtype_expansion.go rename to examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/generated_expansion.go index 29500b539..f6728dd2e 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/testtype_expansion.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/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 v1beta1 -// 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/v1beta1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/testtype.go index 05f7f02a1..e09ff9e1e 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 @@ -14,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" - 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" + typedexamplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -41,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) (*examplev1beta1.TestTypeList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + 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. @@ -59,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) (*examplev1beta1.TestTypeList, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).List(ctx, opts) +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 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 examplev1beta1client.TestTypeInterface. +// 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 5c4e06335..d989e5334 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 @@ -14,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" - 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" + apisexamplev2 "acme.corp/pkg/apis/example/v2" + examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 f6e4c4282..10c4e553f 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) 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] } @@ -50,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. @@ -78,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 } @@ -90,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 7e3cf4cb4..165c25d5e 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 @@ -14,186 +14,78 @@ 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" + 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" + 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" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v2", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example.dev", 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 +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, } - - 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 } -// 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 7972e2404..1a59451a7 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 270778c8d..91e6c3e9c 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 @@ -14,197 +14,83 @@ 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" + 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" + 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" ) -var testTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v2", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example.dev", Version: "v2", Kind: "TestType"} - -type testTypesClusterClient struct { - *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.") - } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev2.TestType, *examplev2.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) (*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() +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, } - 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 } -// 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) typedkcpexamplev2.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) 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 37a3eca68..c6af25a96 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 @@ -14,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" - 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" + typedexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -41,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. @@ -59,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 455302a58..8bc1aca5a 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 @@ -14,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" 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" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" + example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 a78e00fb2..58714d50c 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) 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] } @@ -50,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. @@ -78,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 } @@ -90,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 df053b400..d76631cdb 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 @@ -14,186 +14,78 @@ 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" + 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" + 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 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 +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, } - - 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 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 48e757947..f3663a736 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 9d1f58160..b31479141 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 @@ -14,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" + context "context" "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" 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" 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 +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*example3v1.TestType, *example3v1.TestTypeList] + Fake *kcptesting.Fake } -// 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.") +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 &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) (*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) - } - } - return list, err +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexample3v1.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) 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/example/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/example/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/example/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 839e05a87..68c63b02a 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 @@ -14,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" 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" + typedexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -43,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. @@ -68,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 index 0a3121c6d..c3a731a3c 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go @@ -14,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" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + apisexampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a exampledashedv1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a exampledashedv1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) exampledashedv1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) + 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[*exampledashedv1client.ExampleDashedV1Client] + clientCache kcpclient.Cache[*exampledashedv1.ExampleDashedV1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) exampledashedv1client.ClusterTestTypeInterface { +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.") } @@ -59,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) (*exampledashedv1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*apisexampledashedv1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(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 index 1ef27fd52..4bef98503 100644 --- 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) type ExampleDashedV1ClusterInterface interface { ExampleDashedV1ClusterScoper - TestTypesClusterGetter 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] } @@ -50,23 +53,25 @@ func (c *ExampleDashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) return c.clientCache.ClusterOrDie(clusterPath) } -func (c *ExampleDashedV1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - 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) { - 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 ExampleDashedV1ClusterClient for the given config and http client. @@ -78,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleDashedV1Clus if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &ExampleDashedV1ClusterClient{clientCache: cache}, nil } @@ -90,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *ExampleDashedV1ClusterClient { } 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 index e42c093b9..4923a3dad 100644 --- 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 @@ -14,186 +14,78 @@ 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" + 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" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" - exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/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" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example-dashed.some.corp", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example-dashed.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) exampledashedv1client.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[*exampledashedv1.ClusterTestType, *exampledashedv1.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) (*exampledashedv1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &exampledashedv1.ClusterTestTypeList{}) - if obj == nil { - return nil, err +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, } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &exampledashedv1.ClusterTestTypeList{ListMeta: obj.(*exampledashedv1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*exampledashedv1.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 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) typedexampledashedv1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.CreateOptions) (*exampledashedv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.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), &exampledashedv1.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, &exampledashedv1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.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) (*exampledashedv1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &exampledashedv1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &exampledashedv1.ClusterTestTypeList{ListMeta: obj.(*exampledashedv1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*exampledashedv1.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) (*exampledashedv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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"), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err +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, } - return obj.(*exampledashedv1.ClusterTestType), err } 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 index 36bb1822b..28c8ca3c4 100644 --- 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "k8s.io/client-go/rest" exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" @@ -41,30 +41,30 @@ func (c *ExampleDashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) return &ExampleDashedV1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *ExampleDashedV1ClusterClient) TestTypes() kcpexampledashedv1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *ExampleDashedV1ClusterClient) ClusterTestTypes() kcpexampledashedv1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ exampledashedv1.ExampleDashedV1Interface = (*ExampleDashedV1Client)(nil) +func (c *ExampleDashedV1ClusterClient) TestTypes() kcpexampledashedv1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type ExampleDashedV1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *ExampleDashedV1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *ExampleDashedV1Client) ClusterTestTypes() exampledashedv1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *ExampleDashedV1Client) TestTypes(namespace string) exampledashedv1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExampleDashedV1Client) ClusterTestTypes() exampledashedv1.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 *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 index a8e5415d9..0d914990a 100644 --- 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 @@ -14,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" + context "context" "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" 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" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" - exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" - kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/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" ) -var testTypesResource = schema.GroupVersionResource{Group: "example-dashed.some.corp", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example-dashed.some.corp", Version: "v1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*exampledashedv1.TestType, *exampledashedv1.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexampledashedv1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +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, } - - 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) (*exampledashedv1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &exampledashedv1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &exampledashedv1.TestTypeList{ListMeta: obj.(*exampledashedv1.TestTypeList).ListMeta} - for _, item := range obj.(*exampledashedv1.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) typedkcpexampledashedv1.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) exampledashedv1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexampledashedv1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*exampledashedv1.TestType, *exampledashedv1.TestTypeList, *v1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.CreateOptions) (*exampledashedv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.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), &exampledashedv1.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, &exampledashedv1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.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) (*exampledashedv1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &exampledashedv1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &exampledashedv1.TestTypeList{ListMeta: obj.(*exampledashedv1.TestTypeList).ListMeta} - for _, item := range obj.(*exampledashedv1.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) (*exampledashedv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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"), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.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) 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 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/exampledashed/v1/testtype_expansion.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/generated_expansion.go similarity index 68% rename from examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype_expansion.go rename to examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/generated_expansion.go index 835da85d6..21b9d4175 100644 --- a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype_expansion.go +++ b/examples/pkg/kcp/clients/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 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/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/testtype.go index ce4377c53..b44856e3b 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/testtype.go @@ -14,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" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + typedexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -43,10 +43,11 @@ 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[*exampledashedv1client.ExampleDashedV1Client] + clientCache kcpclient.Cache[*typedexampledashedv1.ExampleDashedV1Client] } // Cluster scopes the client down to a particular cluster. @@ -68,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 exampledashedv1client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexampledashedv1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) exampledashedv1client.TestTypeInterface + Namespace(string) typedexampledashedv1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*exampledashedv1client.ExampleDashedV1Client] + clientCache kcpclient.Cache[*typedexampledashedv1.ExampleDashedV1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) exampledashedv1client.TestTypeInterface { +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 d693778e2..244e5f76d 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 @@ -14,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" 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" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 c05661de5..0a9e167a7 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) 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] } @@ -50,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. @@ -78,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 } @@ -90,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 3c125cef7..7f1b2be76 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 @@ -14,186 +14,78 @@ 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" + 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" + 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" ) -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 +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, } - - 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 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 afa27e722..ac89dd8ef 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 d4531706c..58968ea3d 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 @@ -14,197 +14,87 @@ 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" + 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" + 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" ) -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 -} - -// 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.") - } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*existinginterfacesv1.TestType, *existinginterfacesv1.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) (*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() +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, } - 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 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) typedkcpexistinginterfacesv1.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) 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/listers/existinginterfaces/v1/testtype_expansion.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/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/existinginterfaces/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/existinginterfaces/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/existinginterfaces/v1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/testtype.go index fa8068bed..783b6b16a 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 @@ -14,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" 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" + typedexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -43,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. @@ -68,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 2f026b3fa..1f646905c 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 @@ -14,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" 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" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 eae881b2b..262d9ebb2 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 @@ -14,186 +14,78 @@ 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" + 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" + 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" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "secondexample.dev", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "secondexample.dev", 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 +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, } - - 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 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 a826e6760..779e2a318 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 ba0f59190..2a8d1d92c 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 @@ -14,197 +14,87 @@ 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" + 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" + 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" ) -var testTypesResource = schema.GroupVersionResource{Group: "secondexample.dev", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "secondexample.dev", Version: "v1", Kind: "TestType"} - -type testTypesClusterClient struct { - *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.") - } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*secondexamplev1.TestType, *secondexamplev1.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) (*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() +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, } - 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 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) typedkcpsecondexamplev1.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) 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 319025e2b..4faeed22b 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) 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] } @@ -50,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. @@ -78,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 } @@ -90,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 bffaaac14..f2bcb27b2 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 @@ -14,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" 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" + typedsecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -43,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. @@ -68,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 6182c4666..4d6b8d142 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/interface.go @@ -14,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 } @@ -67,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 } @@ -89,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 239d4b96b..bc237500f 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1/clustertesttype.go @@ -14,28 +14,28 @@ 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" + logicalcluster "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" - - 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1listers.ClusterTestTypeClusterLister + Lister() examplev1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 { @@ -131,46 +130,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 e692dccde..e632b7bcb 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1/interface.go @@ -14,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 { @@ -34,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 { @@ -62,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 f9582f25a..07e8c420e 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1/testtype.go @@ -14,28 +14,28 @@ 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" + logicalcluster "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" - - 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1listers.TestTypeClusterLister + Lister() examplev1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 { @@ -132,48 +131,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 e634ede95..2cdbc3d13 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/clustertesttype.go @@ -14,28 +14,28 @@ 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" 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" + + 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1alpha1listers.ClusterTestTypeClusterLister + Lister() examplev1alpha1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister examplev1alpha1listers.ClusterTestTypeLister + lister examplev1alpha1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() examplev1alpha1listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() examplev1alpha1.ClusterTestTypeLister { + return i.lister +} + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev1alpha1.ClusterTestTypeLister } type clusterTestTypeScopedInformer struct { @@ -131,46 +130,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 a39705887..e63e9ce82 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/interface.go @@ -14,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 { @@ -34,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 { @@ -62,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 82fc872af..57a1fb24a 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/testtype.go @@ -14,28 +14,28 @@ 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" 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" + + 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1alpha1listers.TestTypeClusterLister + Lister() examplev1alpha1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister examplev1alpha1listers.TestTypeLister + lister examplev1alpha1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() examplev1alpha1listers.TestTypeLister { - return f.lister +func (i *testTypeInformer) Lister() examplev1alpha1.TestTypeLister { + return i.lister +} + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev1alpha1.TestTypeLister } type testTypeScopedInformer struct { @@ -132,48 +131,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 ba4713aaf..cb03b8cda 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/clustertesttype.go @@ -14,28 +14,28 @@ 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" 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" + + 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1beta1listers.ClusterTestTypeClusterLister + Lister() examplev1beta1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister examplev1beta1listers.ClusterTestTypeLister + lister examplev1beta1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() examplev1beta1listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() examplev1beta1.ClusterTestTypeLister { + return i.lister +} + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev1beta1.ClusterTestTypeLister } type clusterTestTypeScopedInformer struct { @@ -131,46 +130,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 0693972f1..12cc5c282 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/interface.go @@ -14,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 v1beta1 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 { @@ -34,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 { @@ -62,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/v1beta1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/testtype.go index 08da08521..31c7e2ffa 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/testtype.go @@ -14,28 +14,28 @@ 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" 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" + + 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1beta1listers.TestTypeClusterLister + Lister() examplev1beta1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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.ExampleV1beta1().TestTypes().List(context.TODO(), options) + return client.ExampleV1beta1().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.ExampleV1beta1().TestTypes().Watch(context.TODO(), options) + return client.ExampleV1beta1().TestTypes().Watch(context.Background(), options) }, }, - &examplev1beta1.TestType{}, + &apisexamplev1beta1.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(&examplev1beta1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1beta1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Lister() examplev1beta1listers.TestTypeClusterLister { - return examplev1beta1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Lister() examplev1beta1.TestTypeClusterLister { + return examplev1beta1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -// TestTypeInformer provides access to a shared informer and lister for -// TestTypes. -type TestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() examplev1beta1listers.TestTypeLister -} - -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister examplev1beta1listers.TestTypeLister + lister examplev1beta1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() examplev1beta1listers.TestTypeLister { - return f.lister +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 { @@ -132,48 +131,48 @@ type testTypeScopedInformer struct { namespace string } -func (f *testTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1beta1.TestType{}, f.defaultInformer) -} - -func (f *testTypeScopedInformer) Lister() examplev1beta1listers.TestTypeLister { - return examplev1beta1listers.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.ExampleV1beta1().TestTypes(namespace).List(context.TODO(), options) + return client.ExampleV1beta1().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.ExampleV1beta1().TestTypes(namespace).Watch(context.TODO(), options) + return client.ExampleV1beta1().TestTypes(namespace).Watch(context.Background(), options) }, }, - &examplev1beta1.TestType{}, + &apisexamplev1beta1.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(&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, - }, f.tweakListOptions) + }, 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 2411f841e..e3274f366 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v2/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v2/clustertesttype.go @@ -14,28 +14,28 @@ 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" 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" + + 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev2listers.ClusterTestTypeClusterLister + Lister() examplev2.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister examplev2listers.ClusterTestTypeLister + lister examplev2.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() examplev2listers.ClusterTestTypeLister { - return f.lister +func (i *clusterTestTypeInformer) Lister() examplev2.ClusterTestTypeLister { + return i.lister +} + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev2.ClusterTestTypeLister } type clusterTestTypeScopedInformer struct { @@ -131,46 +130,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 1b0b3fa1f..b5089ba33 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v2/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v2/interface.go @@ -14,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 { @@ -34,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 { @@ -62,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 784880e2b..acad02ccc 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v2/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v2/testtype.go @@ -14,28 +14,28 @@ 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" 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" + + 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev2listers.TestTypeClusterLister + Lister() examplev2.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister examplev2listers.TestTypeLister + lister examplev2.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() examplev2listers.TestTypeLister { - return f.lister +func (i *testTypeInformer) Lister() examplev2.TestTypeLister { + return i.lister +} + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() examplev2.TestTypeLister } type testTypeScopedInformer struct { @@ -132,48 +131,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 3c5eb9990..2cade5d19 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example3/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example3/interface.go @@ -14,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 } @@ -43,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 } @@ -59,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 da7c49348..4d76e89e9 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/clustertesttype.go @@ -14,28 +14,28 @@ 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" + logicalcluster "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" - - 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() example3v1listers.ClusterTestTypeClusterLister + Lister() example3v1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 { @@ -131,46 +130,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 e692dccde..e632b7bcb 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/interface.go @@ -14,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 { @@ -34,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 { @@ -62,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 caf44c3f5..e491d0c0e 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/testtype.go @@ -14,28 +14,28 @@ 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" + logicalcluster "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" - - 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() example3v1listers.TestTypeClusterLister + Lister() example3v1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 { @@ -132,48 +131,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 index ca3a4a741..024d025d8 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/interface.go @@ -14,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 exampledashed import ( - "acme.corp/pkg/kcp/clients/informers/externalversions/exampledashed/v1" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + 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 the shared informers in V1. + // V1 provides access to shared informers for resources in V1. V1() v1.ClusterInterface } @@ -43,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 } @@ -59,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/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go index d12435046..b668e69b6 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go @@ -14,28 +14,28 @@ 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" + logicalcluster "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" - - exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - exampledashedv1listers "acme.corp/pkg/kcp/clients/listers/exampledashed/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() exampledashedv1listers.ClusterTestTypeClusterLister + Lister() exampledashedv1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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.ExampleDashedV1().ClusterTestTypes().List(context.TODO(), 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.TODO(), options) + return client.ExampleDashedV1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &exampledashedv1.ClusterTestType{}, + &apisexampledashedv1.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(&exampledashedv1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexampledashedv1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Lister() exampledashedv1listers.ClusterTestTypeClusterLister { - return exampledashedv1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Lister() exampledashedv1.ClusterTestTypeClusterLister { + return exampledashedv1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -// ClusterTestTypeInformer provides access to a shared informer and lister for -// ClusterTestTypes. -type ClusterTestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() exampledashedv1listers.ClusterTestTypeLister -} - -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister exampledashedv1listers.ClusterTestTypeLister + lister exampledashedv1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() exampledashedv1listers.ClusterTestTypeLister { - return f.lister +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 { @@ -131,46 +130,46 @@ type clusterTestTypeScopedInformer struct { tweakListOptions internalinterfaces.TweakListOptionsFunc } -func (f *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&exampledashedv1.ClusterTestType{}, f.defaultInformer) -} - -func (f *clusterTestTypeScopedInformer) Lister() exampledashedv1listers.ClusterTestTypeLister { - return exampledashedv1listers.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.ExampleDashedV1().ClusterTestTypes().List(context.TODO(), 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.TODO(), options) + return client.ExampleDashedV1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &exampledashedv1.ClusterTestType{}, + &apisexampledashedv1.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(&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 index e692dccde..e632b7bcb 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/interface.go @@ -14,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 { @@ -34,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 { @@ -62,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/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go index 179215651..4775c8585 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go @@ -14,28 +14,28 @@ 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" + logicalcluster "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" - - exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - scopedclientset "acme.corp/pkg/generated/clientset/versioned" - clientset "acme.corp/pkg/kcp/clients/clientset/versioned" - "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" - exampledashedv1listers "acme.corp/pkg/kcp/clients/listers/exampledashed/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() exampledashedv1listers.TestTypeClusterLister + Lister() exampledashedv1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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.ExampleDashedV1().TestTypes().List(context.TODO(), 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.TODO(), options) + return client.ExampleDashedV1().TestTypes().Watch(context.Background(), options) }, }, - &exampledashedv1.TestType{}, + &apisexampledashedv1.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(&exampledashedv1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexampledashedv1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Lister() exampledashedv1listers.TestTypeClusterLister { - return exampledashedv1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Lister() exampledashedv1.TestTypeClusterLister { + return exampledashedv1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -// TestTypeInformer provides access to a shared informer and lister for -// TestTypes. -type TestTypeInformer interface { - Informer() cache.SharedIndexInformer - Lister() exampledashedv1listers.TestTypeLister -} - -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister exampledashedv1listers.TestTypeLister + lister exampledashedv1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() exampledashedv1listers.TestTypeLister { - return f.lister +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 { @@ -132,48 +131,48 @@ type testTypeScopedInformer struct { namespace string } -func (f *testTypeScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&exampledashedv1.TestType{}, f.defaultInformer) -} - -func (f *testTypeScopedInformer) Lister() exampledashedv1listers.TestTypeLister { - return exampledashedv1listers.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.ExampleDashedV1().TestTypes(namespace).List(context.TODO(), 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.TODO(), options) + return client.ExampleDashedV1().TestTypes(namespace).Watch(context.Background(), options) }, }, - &exampledashedv1.TestType{}, + &apisexampledashedv1.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(&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, - }, f.tweakListOptions) + }, 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 513cb6037..f08874be4 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/interface.go @@ -14,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 } @@ -43,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 } @@ -59,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 14cc85b5c..198b0ddde 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go @@ -14,28 +14,28 @@ 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" + logicalcluster "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" - - 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() existinginterfacesv1listers.ClusterTestTypeClusterLister + Lister() existinginterfacesv1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 { @@ -131,46 +130,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 e692dccde..e632b7bcb 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/interface.go @@ -14,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 { @@ -34,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 { @@ -62,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 9382e7b21..072692396 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/testtype.go @@ -14,28 +14,28 @@ 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" + logicalcluster "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" - - 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() existinginterfacesv1listers.TestTypeClusterLister + Lister() existinginterfacesv1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 { @@ -132,48 +131,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 f9d0c4eed..a436e49fc 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/factory.go +++ b/examples/pkg/kcp/clients/informers/externalversions/factory.go @@ -14,31 +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" 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" - exampledashedinformers "acme.corp/pkg/kcp/clients/informers/externalversions/exampledashed" - 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" + + 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" + + 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" ) // SharedInformerOption defines the functional option type for SharedInformerFactory. @@ -52,7 +52,7 @@ type SharedInformerOptions struct { } type sharedInformerFactory struct { - client clientset.ClusterInterface + client versioned.ClusterInterface tweakListOptions internalinterfaces.TweakListOptionsFunc lock sync.Mutex defaultResync time.Duration @@ -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 @@ -96,13 +96,21 @@ func WithTransform(transform cache.TransformFunc) SharedInformerOption { } } -// NewSharedInformerFactory constructs a new instance of SharedInformerFactory for all namespaces. -func NewSharedInformerFactory(client clientset.ClusterInterface, defaultResync time.Duration) SharedInformerFactory { +// 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, @@ -128,7 +136,6 @@ func NewSharedInformerFactoryWithOptions(client clientset.ClusterInterface, defa return factory } -// Start initializes all requested informers. func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { f.lock.Lock() defer f.lock.Unlock() @@ -162,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() @@ -181,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() @@ -201,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 @@ -222,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 { @@ -246,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 @@ -260,41 +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 - ExampleDashed() exampledashedinformers.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) ExampleDashed() exampledashedinformers.ClusterInterface { - return exampledashedinformers.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 { @@ -330,13 +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. @@ -345,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, @@ -441,29 +451,29 @@ type SharedScopedInformerFactory interface { ForResource(resource schema.GroupVersionResource) (GenericInformer, error) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool - Example() exampleinformers.Interface - ExampleDashed() exampledashedinformers.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() exampleinformers.Interface { - return exampleinformers.NewScoped(f, f.namespace, f.tweakListOptions) +func (f *sharedScopedInformerFactory) Example() example.Interface { + return example.NewScoped(f, f.namespace, f.tweakListOptions) } -func (f *sharedScopedInformerFactory) ExampleDashed() exampledashedinformers.Interface { - return exampledashedinformers.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 eff79f47f..d206d0bd6 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcp/clients/informers/externalversions/generic.go @@ -14,25 +14,25 @@ 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" + fmt "fmt" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/tools/cache" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" 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" - exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + v1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" ) @@ -54,20 +54,20 @@ 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), } } @@ -77,59 +77,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=example-dashed.some.corp, Version=V1 - case exampledashedv1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().TestTypes().Informer()}, nil - case exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"): + // Group=example-dashed.some.corp, Version=v1 + case v1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().ClusterTestTypes().Informer()}, nil - // 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.dev, Version=V1 - case examplev1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1().TestTypes().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.dev, 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.dev, Version=V1beta1 - case examplev1beta1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().TestTypes().Informer()}, nil - 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.dev, 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.dev, 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) @@ -139,62 +147,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=example-dashed.some.corp, Version=V1 - case exampledashedv1.SchemeGroupVersion.WithResource("testtypes"): - informer := f.ExampleDashed().V1().TestTypes().Informer() - return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - case exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"): + // 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 - // Group=example3.some.corp, Version=V1 - case example3v1.SchemeGroupVersion.WithResource("testtypes"): - informer := f.Example3().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 - case example3v1.SchemeGroupVersion.WithResource("clustertesttypes"): - informer := f.Example3().V1().ClusterTestTypes().Informer() + + // 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.dev, Version=V1 case examplev1.SchemeGroupVersion.WithResource("testtypes"): informer := f.Example().V1().TestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - case examplev1.SchemeGroupVersion.WithResource("clustertesttypes"): - informer := f.Example().V1().ClusterTestTypes().Informer() + + // 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.dev, Version=V1alpha1 - case examplev1alpha1.SchemeGroupVersion.WithResource("testtypes"): + case v1alpha1.SchemeGroupVersion.WithResource("testtypes"): informer := f.Example().V1alpha1().TestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - case examplev1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"): - informer := f.Example().V1alpha1().ClusterTestTypes().Informer() + + // 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.dev, Version=V1beta1 - case examplev1beta1.SchemeGroupVersion.WithResource("testtypes"): + case v1beta1.SchemeGroupVersion.WithResource("testtypes"): informer := f.Example().V1beta1().TestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - case examplev1beta1.SchemeGroupVersion.WithResource("clustertesttypes"): - informer := f.Example().V1beta1().ClusterTestTypes().Informer() + + // 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=example.dev, Version=V2 - case examplev2.SchemeGroupVersion.WithResource("testtypes"): + case v2.SchemeGroupVersion.WithResource("testtypes"): informer := f.Example().V2().TestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - case examplev2.SchemeGroupVersion.WithResource("clustertesttypes"): - informer := f.Example().V2().ClusterTestTypes().Informer() + + // 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 - // Group=existinginterfaces.acme.corp, Version=V1 - case existinginterfacesv1.SchemeGroupVersion.WithResource("testtypes"): - informer := f.Existinginterfaces().V1().TestTypes().Informer() + 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.dev, 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 173e8bc66..905e2dece 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/examples/pkg/kcp/clients/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -14,7 +14,7 @@ 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 @@ -23,31 +23,31 @@ import ( kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - 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" + clientsetversioned "acme.corp/pkg/generated/clientset/versioned" + versioned "acme.corp/pkg/kcp/clients/clientset/versioned" ) -// 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 4415d70aa..51e38e1b6 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/secondexample/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/secondexample/interface.go @@ -14,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 } @@ -43,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 } @@ -59,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 0a06a6f90..4eba45012 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/clustertesttype.go @@ -14,28 +14,28 @@ 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" + logicalcluster "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" - - 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() secondexamplev1listers.ClusterTestTypeClusterLister + Lister() secondexamplev1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 { @@ -131,46 +130,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 e692dccde..e632b7bcb 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/interface.go @@ -14,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 { @@ -34,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 { @@ -62,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 e9cc42def..605a2eb8b 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/testtype.go @@ -14,28 +14,28 @@ 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" + logicalcluster "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" - - 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for @@ -43,7 +43,7 @@ import ( type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() secondexamplev1listers.TestTypeClusterLister + Lister() secondexamplev1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -54,76 +54,75 @@ 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 (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 { @@ -132,48 +131,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 fd4f5497e..5607173ee 100644 --- a/examples/pkg/kcp/clients/listers/example/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example/v1/clustertesttype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1 "acme.corp/pkg/apis/example/v1" ) -// 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. @@ -40,36 +41,49 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev1.ClusterTestType] indexer cache.Indexer } +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} + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*examplev1.ClusterTestType](l.indexer, clusterName, examplev1.Resource("clustertesttype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,63 +92,20 @@ 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} +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*examplev1.ClusterTestType] 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 -} 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 cb89ed68d..45e7849be 100644 --- a/examples/pkg/kcp/clients/listers/example/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/example/v1/testtype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1 "acme.corp/pkg/apis/example/v1" ) -// 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. @@ -40,10 +41,14 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -51,26 +56,35 @@ type testTypeClusterLister struct { // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev1.TestType](indexer, examplev1.Resource("testtype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*examplev1.TestType](l.indexer, clusterName, examplev1.Resource("testtype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,29 +92,23 @@ 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 newTestTypeNamespaceLister(l.ResourceIndexer, 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. @@ -109,33 +117,11 @@ 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) +// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1.TestType], namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - return obj.(*examplev1.TestType), nil } // NewTestTypeLister returns a new TestTypeLister. @@ -143,51 +129,21 @@ func (s *testTypeNamespaceLister) Get(name string) (*examplev1.TestType, error) // - 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} +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeScopedLister{ + listers.New[*examplev1.TestType](indexer, examplev1.Resource("testtype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*examplev1.TestType] 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 -} - // 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) - } - return obj.(*examplev1.TestType), nil +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } 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..363ee99a1 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/example/v1/withoutverbtype.go @@ -0,0 +1,149 @@ +/* +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 ( + "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/listers" + "k8s.io/client-go/tools/cache" + + examplev1 "acme.corp/pkg/apis/example/v1" +) + +// 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] + indexer cache.Indexer +} + +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")), + indexer, + } +} + +// Cluster scopes the lister to one workspace, allowing users to list and get WithoutVerbTypes. +func (l *withoutVerbTypeClusterLister) Cluster(clusterName logicalcluster.Name) WithoutVerbTypeLister { + return &withoutVerbTypeLister{ + kcplisters.New[*examplev1.WithoutVerbType](l.indexer, clusterName, examplev1.Resource("withoutverbtype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name +} + +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 newWithoutVerbTypeNamespaceLister(l.ResourceIndexer, 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 +} + +// newWithoutVerbTypeNamespaceLister returns a new WithoutVerbTypeNamespaceLister. +func newWithoutVerbTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1.WithoutVerbType], namespace string) WithoutVerbTypeNamespaceLister { + return &withoutVerbTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), + } +} + +// NewWithoutVerbTypeLister returns a new WithoutVerbTypeLister. +// 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 NewWithoutVerbTypeLister(indexer cache.Indexer) WithoutVerbTypeLister { + return &withoutVerbTypeScopedLister{ + listers.New[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype")), + indexer, + } +} + +// withoutVerbTypeScopedLister can list all WithoutVerbTypes inside a workspace +// or scope down to a WithoutVerbTypeNamespaceLister for one namespace. +type withoutVerbTypeScopedLister struct { + listers.ResourceIndexer[*examplev1.WithoutVerbType] + indexer cache.Indexer +} + +// WithoutVerbTypes returns an object that can list and get WithoutVerbTypes in one namespace. +func (l *withoutVerbTypeScopedLister) WithoutVerbTypes(namespace string) WithoutVerbTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) +} diff --git a/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype.go b/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype.go index 079543cc4..7cc18f8ff 100644 --- a/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example/v1alpha1/clustertesttype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" ) -// 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. @@ -40,36 +41,49 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev1alpha1.ClusterTestType] indexer cache.Indexer } +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} + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*examplev1alpha1.ClusterTestType](l.indexer, clusterName, examplev1alpha1.Resource("clustertesttype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,63 +92,20 @@ 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} +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*examplev1alpha1.ClusterTestType] 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 -} 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 f1583f7a8..c8bd69d4f 100644 --- a/examples/pkg/kcp/clients/listers/example/v1alpha1/testtype.go +++ b/examples/pkg/kcp/clients/listers/example/v1alpha1/testtype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" ) -// 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. @@ -40,10 +41,14 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev1alpha1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -51,26 +56,35 @@ type testTypeClusterLister struct { // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*examplev1alpha1.TestType](l.indexer, clusterName, examplev1alpha1.Resource("testtype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,29 +92,23 @@ 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 newTestTypeNamespaceLister(l.ResourceIndexer, 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. @@ -109,33 +117,11 @@ 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) +// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1alpha1.TestType], namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - return obj.(*examplev1alpha1.TestType), nil } // NewTestTypeLister returns a new TestTypeLister. @@ -143,51 +129,21 @@ func (s *testTypeNamespaceLister) Get(name string) (*examplev1alpha1.TestType, e // - 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} +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeScopedLister{ + listers.New[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*examplev1alpha1.TestType] 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 -} - // 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) - } - return obj.(*examplev1alpha1.TestType), nil +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype.go b/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype.go index eedd8df08..f3661e216 100644 --- a/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" ) -// 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. @@ -40,36 +41,49 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev1beta1.ClusterTestType] indexer cache.Indexer } +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} + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*examplev1beta1.ClusterTestType](l.indexer, clusterName, examplev1beta1.Resource("clustertesttype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,63 +92,20 @@ 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} +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*examplev1beta1.ClusterTestType] 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 -} diff --git a/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype_expansion.go b/examples/pkg/kcp/clients/listers/example/v1beta1/clustertesttype_expansion.go deleted file mode 100644 index 7a36a7444..000000000 --- a/examples/pkg/kcp/clients/listers/example/v1beta1/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 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{} diff --git a/examples/pkg/kcp/clients/listers/example/v1beta1/testtype_expansion.go b/examples/pkg/kcp/clients/listers/example/v1beta1/expansion_generated.go similarity index 62% rename from examples/pkg/kcp/clients/listers/example/v1beta1/testtype_expansion.go rename to examples/pkg/kcp/clients/listers/example/v1beta1/expansion_generated.go index bd1291c94..0b54ba7d4 100644 --- a/examples/pkg/kcp/clients/listers/example/v1beta1/testtype_expansion.go +++ b/examples/pkg/kcp/clients/listers/example/v1beta1/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 v1beta1 -// 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/v1beta1/testtype.go b/examples/pkg/kcp/clients/listers/example/v1beta1/testtype.go index 3ed76b8f1..8a0b34f79 100644 --- a/examples/pkg/kcp/clients/listers/example/v1beta1/testtype.go +++ b/examples/pkg/kcp/clients/listers/example/v1beta1/testtype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" ) -// 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. @@ -40,10 +41,14 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev1beta1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -51,26 +56,35 @@ type testTypeClusterLister struct { // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), + indexer, + } } -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*examplev1beta1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev1beta1.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{ + kcplisters.New[*examplev1beta1.TestType](l.indexer, clusterName, examplev1beta1.Resource("testtype")), + l.indexer, + 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[*examplev1beta1.TestType] + indexer cache.Indexer + clusterName logicalcluster.Name } +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 []*examplev1beta1.TestType, err error) // TestTypes returns a lister that can list and get TestTypes in one workspace and namespace. @@ -78,29 +92,23 @@ 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 newTestTypeNamespaceLister(l.ResourceIndexer, namespace) } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*examplev1beta1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1beta1.TestType)) - }) - return ret, err +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*examplev1beta1.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 []*examplev1beta1.TestType, err error) // Get retrieves the TestType from the indexer for a given workspace, namespace and name. @@ -109,33 +117,11 @@ 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 []*examplev1beta1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1beta1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*examplev1beta1.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(examplev1beta1.Resource("testtypes"), name) +// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1beta1.TestType], namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - return obj.(*examplev1beta1.TestType), nil } // NewTestTypeLister returns a new TestTypeLister. @@ -143,51 +129,21 @@ func (s *testTypeNamespaceLister) Get(name string) (*examplev1beta1.TestType, er // - 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} +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeScopedLister{ + listers.New[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*examplev1beta1.TestType] indexer cache.Indexer } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeScopedLister) List(selector labels.Selector) (ret []*examplev1beta1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1beta1.TestType)) - }) - return ret, err -} - // 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 []*examplev1beta1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1beta1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeScopedNamespaceLister) Get(name string) (*examplev1beta1.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(examplev1beta1.Resource("testtypes"), name) - } - return obj.(*examplev1beta1.TestType), nil +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcp/clients/listers/example/v2/clustertesttype.go b/examples/pkg/kcp/clients/listers/example/v2/clustertesttype.go index 1c63f1ea2..18bd5c0e0 100644 --- a/examples/pkg/kcp/clients/listers/example/v2/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example/v2/clustertesttype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev2 "acme.corp/pkg/apis/example/v2" ) -// 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. @@ -40,36 +41,49 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev2.ClusterTestType] indexer cache.Indexer } +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} + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*examplev2.ClusterTestType](l.indexer, clusterName, examplev2.Resource("clustertesttype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,63 +92,20 @@ 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} +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*examplev2.ClusterTestType] 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 -} 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 98dec3974..0090576e8 100644 --- a/examples/pkg/kcp/clients/listers/example/v2/testtype.go +++ b/examples/pkg/kcp/clients/listers/example/v2/testtype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev2 "acme.corp/pkg/apis/example/v2" ) -// 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. @@ -40,10 +41,14 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev2.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -51,26 +56,35 @@ type testTypeClusterLister struct { // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev2.TestType](indexer, examplev2.Resource("testtype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*examplev2.TestType](l.indexer, clusterName, examplev2.Resource("testtype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,29 +92,23 @@ 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 newTestTypeNamespaceLister(l.ResourceIndexer, 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. @@ -109,33 +117,11 @@ 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) +// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev2.TestType], namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - return obj.(*examplev2.TestType), nil } // NewTestTypeLister returns a new TestTypeLister. @@ -143,51 +129,21 @@ func (s *testTypeNamespaceLister) Get(name string) (*examplev2.TestType, error) // - 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} +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeScopedLister{ + listers.New[*examplev2.TestType](indexer, examplev2.Resource("testtype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*examplev2.TestType] 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 -} - // 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) - } - return obj.(*examplev2.TestType), nil +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype.go index 7cf8c8263..fc7cc37e4 100644 --- a/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/example3/v1/clustertesttype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" example3v1 "acme.corp/pkg/apis/example3/v1" ) -// 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. @@ -40,36 +41,49 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*example3v1.ClusterTestType] indexer cache.Indexer } +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} + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*example3v1.ClusterTestType](l.indexer, clusterName, example3v1.Resource("clustertesttype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,63 +92,20 @@ 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} +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*example3v1.ClusterTestType] 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 -} 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 ed843279d..feea7d6b9 100644 --- a/examples/pkg/kcp/clients/listers/example3/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/example3/v1/testtype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" example3v1 "acme.corp/pkg/apis/example3/v1" ) -// 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. @@ -40,10 +41,14 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*example3v1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -51,26 +56,35 @@ type testTypeClusterLister struct { // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} + return &testTypeClusterLister{ + kcplisters.NewCluster[*example3v1.TestType](indexer, example3v1.Resource("testtype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*example3v1.TestType](l.indexer, clusterName, example3v1.Resource("testtype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,29 +92,23 @@ 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 newTestTypeNamespaceLister(l.ResourceIndexer, 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. @@ -109,33 +117,11 @@ 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) +// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*example3v1.TestType], namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - return obj.(*example3v1.TestType), nil } // NewTestTypeLister returns a new TestTypeLister. @@ -143,51 +129,21 @@ func (s *testTypeNamespaceLister) Get(name string) (*example3v1.TestType, error) // - 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} +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeScopedLister{ + listers.New[*example3v1.TestType](indexer, example3v1.Resource("testtype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*example3v1.TestType] 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 -} - // 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) - } - return obj.(*example3v1.TestType), nil +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go index 070a00094..53dc35006 100644 --- a/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" ) -// 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. @@ -40,36 +41,49 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*exampledashedv1.ClusterTestType] indexer cache.Indexer } +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} + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), + indexer, + } } -// List lists all ClusterTestTypes in the indexer across all workspaces. -func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*exampledashedv1.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{ + kcplisters.New[*exampledashedv1.ClusterTestType](l.indexer, clusterName, exampledashedv1.Resource("clustertesttype")), + l.indexer, + 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[*exampledashedv1.ClusterTestType] + indexer cache.Indexer + clusterName logicalcluster.Name } +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 []*exampledashedv1.ClusterTestType, err error) // Get retrieves the ClusterTestType from the indexer for a given workspace and name. @@ -78,63 +92,20 @@ 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 []*exampledashedv1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*exampledashedv1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*exampledashedv1.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(exampledashedv1.Resource("clustertesttypes"), name) - } - return obj.(*exampledashedv1.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} +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*exampledashedv1.ClusterTestType] indexer cache.Indexer } - -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeScopedLister) List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*exampledashedv1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeScopedLister) Get(name string) (*exampledashedv1.ClusterTestType, error) { - key := name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(exampledashedv1.Resource("clustertesttypes"), name) - } - return obj.(*exampledashedv1.ClusterTestType), nil -} diff --git a/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype_expansion.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype_expansion.go deleted file mode 100644 index a85e878f1..000000000 --- a/examples/pkg/kcp/clients/listers/exampledashed/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/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 index 1d4234672..dbf9f9aba 100644 --- a/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" ) -// 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. @@ -40,10 +41,14 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*exampledashedv1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -51,26 +56,35 @@ type testTypeClusterLister struct { // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} + return &testTypeClusterLister{ + kcplisters.NewCluster[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), + indexer, + } } -// List lists all TestTypes in the indexer across all workspaces. -func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*exampledashedv1.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{ + kcplisters.New[*exampledashedv1.TestType](l.indexer, clusterName, exampledashedv1.Resource("testtype")), + l.indexer, + 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[*exampledashedv1.TestType] + indexer cache.Indexer + clusterName logicalcluster.Name } +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 []*exampledashedv1.TestType, err error) // TestTypes returns a lister that can list and get TestTypes in one workspace and namespace. @@ -78,29 +92,23 @@ 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 newTestTypeNamespaceLister(l.ResourceIndexer, namespace) } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*exampledashedv1.TestType)) - }) - return ret, err +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*exampledashedv1.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 []*exampledashedv1.TestType, err error) // Get retrieves the TestType from the indexer for a given workspace, namespace and name. @@ -109,33 +117,11 @@ 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 []*exampledashedv1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*exampledashedv1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*exampledashedv1.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(exampledashedv1.Resource("testtypes"), name) +// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*exampledashedv1.TestType], namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - return obj.(*exampledashedv1.TestType), nil } // NewTestTypeLister returns a new TestTypeLister. @@ -143,51 +129,21 @@ func (s *testTypeNamespaceLister) Get(name string) (*exampledashedv1.TestType, e // - 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} +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeScopedLister{ + listers.New[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*exampledashedv1.TestType] indexer cache.Indexer } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeScopedLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*exampledashedv1.TestType)) - }) - return ret, err -} - // 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 []*exampledashedv1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*exampledashedv1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeScopedNamespaceLister) Get(name string) (*exampledashedv1.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(exampledashedv1.Resource("testtypes"), name) - } - return obj.(*exampledashedv1.TestType), nil +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype.go index a473319bd..ee8028c28 100644 --- a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/clustertesttype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" ) -// 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. @@ -40,36 +41,49 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*existinginterfacesv1.ClusterTestType] indexer cache.Indexer } +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} + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*existinginterfacesv1.ClusterTestType](l.indexer, clusterName, existinginterfacesv1.Resource("clustertesttype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,63 +92,20 @@ 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} +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*existinginterfacesv1.ClusterTestType] 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 -} 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/exampledashed/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/exampledashed/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/exampledashed/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 db394a73d..649b76c00 100644 --- a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" ) -// 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. @@ -40,10 +41,14 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*existinginterfacesv1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -51,26 +56,35 @@ type testTypeClusterLister struct { // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} + return &testTypeClusterLister{ + kcplisters.NewCluster[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*existinginterfacesv1.TestType](l.indexer, clusterName, existinginterfacesv1.Resource("testtype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,29 +92,23 @@ 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 newTestTypeNamespaceLister(l.ResourceIndexer, 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. @@ -109,33 +117,11 @@ 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) +// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*existinginterfacesv1.TestType], namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - return obj.(*existinginterfacesv1.TestType), nil } // NewTestTypeLister returns a new TestTypeLister. @@ -143,51 +129,21 @@ func (s *testTypeNamespaceLister) Get(name string) (*existinginterfacesv1.TestTy // - 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} +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeScopedLister{ + listers.New[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*existinginterfacesv1.TestType] 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 -} - // 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) - } - return obj.(*existinginterfacesv1.TestType), nil +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype.go index eb4837a0b..1afb0c966 100644 --- a/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/listers/secondexample/v1/clustertesttype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" ) -// 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. @@ -40,36 +41,49 @@ type ClusterTestTypeClusterLister interface { ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*secondexamplev1.ClusterTestType] indexer cache.Indexer } +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} + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*secondexamplev1.ClusterTestType](l.indexer, clusterName, secondexamplev1.Resource("clustertesttype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,63 +92,20 @@ 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} +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*secondexamplev1.ClusterTestType] 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 -} 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/existinginterfaces/v1/testtype_expansion.go b/examples/pkg/kcp/clients/listers/secondexample/v1/expansion_generated.go similarity index 61% rename from examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype_expansion.go rename to examples/pkg/kcp/clients/listers/secondexample/v1/expansion_generated.go index 3f50c325f..1ef10b740 100644 --- a/examples/pkg/kcp/clients/listers/existinginterfaces/v1/testtype_expansion.go +++ b/examples/pkg/kcp/clients/listers/secondexample/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/secondexample/v1/testtype.go b/examples/pkg/kcp/clients/listers/secondexample/v1/testtype.go index 9798efac4..314413538 100644 --- a/examples/pkg/kcp/clients/listers/secondexample/v1/testtype.go +++ b/examples/pkg/kcp/clients/listers/secondexample/v1/testtype.go @@ -14,22 +14,23 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" ) -// 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. @@ -40,10 +41,14 @@ type TestTypeClusterLister interface { TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*secondexamplev1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -51,26 +56,35 @@ type testTypeClusterLister struct { // - has the kcpcache.ClusterIndex as an index // - has the kcpcache.ClusterAndNamespaceIndex as an index func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { - return &testTypeClusterLister{indexer: indexer} + return &testTypeClusterLister{ + kcplisters.NewCluster[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), + 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 +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{ + kcplisters.New[*secondexamplev1.TestType](l.indexer, clusterName, secondexamplev1.Resource("testtype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name } +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. @@ -78,29 +92,23 @@ 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 newTestTypeNamespaceLister(l.ResourceIndexer, 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. @@ -109,33 +117,11 @@ 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) +// newTestTypeNamespaceLister returns a new TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*secondexamplev1.TestType], namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - return obj.(*secondexamplev1.TestType), nil } // NewTestTypeLister returns a new TestTypeLister. @@ -143,51 +129,21 @@ func (s *testTypeNamespaceLister) Get(name string) (*secondexamplev1.TestType, e // - 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} +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeScopedLister{ + listers.New[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), + indexer, + } } -// 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 { + listers.ResourceIndexer[*secondexamplev1.TestType] 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 -} - // 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) - } - return obj.(*secondexamplev1.TestType), nil +func (l *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcp/clients/listers/secondexample/v1/testtype_expansion.go b/examples/pkg/kcp/clients/listers/secondexample/v1/testtype_expansion.go deleted file mode 100644 index 3f50c325f..000000000 --- a/examples/pkg/kcp/clients/listers/secondexample/v1/testtype_expansion.go +++ /dev/null @@ -1,31 +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{} - -// 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/kcpexisting/clients/clientset/versioned/clientset.go b/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go index b561b4175..3f9b2cc27 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go @@ -14,20 +14,20 @@ 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 import ( - "fmt" - "net/http" + fmt "fmt" + http "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" + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" client "acme.corp/pkg/generated/clientset/versioned" examplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1" @@ -43,31 +43,31 @@ import ( type ClusterInterface interface { Cluster(logicalcluster.Path) client.Interface Discovery() discovery.DiscoveryInterface - ExampleDashedV1() exampledashedv1.ExampleDashedV1ClusterInterface - 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] - exampledashedV1 *exampledashedv1.ExampleDashedV1ClusterClient - 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,16 +75,6 @@ func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { return c.DiscoveryClient } -// ExampleDashedV1 retrieves the ExampleDashedV1ClusterClient. -func (c *ClusterClientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1ClusterInterface { - return c.exampledashedV1 -} - -// 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 @@ -105,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 @@ -167,27 +167,27 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli var cs ClusterClientset cs.clientCache = cache var err error - cs.exampledashedV1, err = exampledashedv1.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.exampleV1, err = examplev1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } - cs.example3V1, err = example3v1.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.exampleV1alpha1, err = examplev1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } - cs.exampleV1, err = examplev1.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.exampleV1beta1, err = examplev1beta1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } - cs.exampleV1alpha1, err = examplev1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.exampleV2, err = examplev2.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } - cs.exampleV1beta1, err = examplev1beta1.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.example3V1, err = example3v1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } - cs.exampleV2, err = examplev2.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.exampleDashedV1, err = exampledashedv1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } @@ -216,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 43311c533..a6e7c2374 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go @@ -14,7 +14,7 @@ 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 @@ -26,8 +26,8 @@ import ( "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" @@ -36,50 +36,55 @@ import ( 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" - fakeexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake" + 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" ) // 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,62 +94,62 @@ func (c *ClusterClientset) Tracker() kcptesting.ObjectTracker { return c.tracker } -// ExampleDashedV1 retrieves the ExampleDashedV1ClusterClient. -func (c *ClusterClientset) ExampleDashedV1() kcpexampledashedv1.ExampleDashedV1ClusterInterface { - return &fakeexampledashedv1.ExampleDashedV1ClusterClient{Fake: c.Fake} -} - -// 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 @@ -152,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 } @@ -161,42 +170,62 @@ func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { return c.tracker } -// ExampleDashedV1 retrieves the ExampleDashedV1Client. -func (c *Clientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1Interface { - return &fakeexampledashedv1.ExampleDashedV1Client{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...) -// Example3V1 retrieves the Example3V1Client. -func (c *Clientset) Example3V1() example3v1.Example3V1Interface { - return &fakeexample3v1.Example3V1Client{Fake: c.Fake, ClusterPath: c.clusterPath} + 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..c3dc5fe76 --- /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 ( + 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" +) + +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 aac661550..bd637672b 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go @@ -14,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 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" + 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" @@ -39,12 +39,12 @@ var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - exampledashedv1.AddToScheme, - example3v1.AddToScheme, examplev1.AddToScheme, examplev1alpha1.AddToScheme, examplev1beta1.AddToScheme, examplev2.AddToScheme, + example3v1.AddToScheme, + exampledashedv1.AddToScheme, existinginterfacesv1.AddToScheme, secondexamplev1.AddToScheme, } @@ -66,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 3a96d500b..b042a2fca 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 @@ -14,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" 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" + apisexamplev1 "acme.corp/pkg/apis/example/v1" + examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 1e7e36fa4..d788ec76e 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) type ExampleV1ClusterInterface interface { ExampleV1ClusterScoper - TestTypesClusterGetter ClusterTestTypesClusterGetter + TestTypesClusterGetter WithoutVerbTypesClusterGetter } @@ -40,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] } @@ -51,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} } @@ -67,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. @@ -83,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 } @@ -95,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 94baccdfa..152e40e03 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 @@ -14,186 +14,78 @@ 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" + 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" + 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" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example.dev", 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 +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, } - - 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 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 5de53ccde..064b1f1bb 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 283e2a973..de5055848 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 @@ -14,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" + 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" - kcpexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/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" ) -var testTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example.dev", 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.") +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 &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) - } - } - return list, err +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexamplev1.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) 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 6f93450d7..3bb0c392c 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 @@ -14,47 +14,70 @@ 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" + 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" + 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" ) -var withoutVerbTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1", Resource: "withoutverbtypes"} -var withoutVerbTypesKind = schema.GroupVersionKind{Group: "example.dev", 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 637798366..edd177a1c 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 @@ -14,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" 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" + typedexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -43,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. @@ -68,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 e937342af..24c84c018 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ import ( 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" + examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" ) // WithoutVerbTypesClusterGetter has a method to return a WithoutVerbTypeClusterInterface. @@ -34,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. @@ -49,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 41aa31422..9eb94dd6e 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 @@ -14,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" - 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" + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 b235912f4..2531a3256 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) 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] } @@ -50,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. @@ -78,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 } @@ -90,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 fff689735..9c329613d 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 @@ -14,186 +14,78 @@ 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" + 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" + 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" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1alpha1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example.dev", 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 +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, } - - 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 } -// 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 54fb3f6de..eab9b0bef 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 582a0ff3f..6aa3d1350 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 @@ -14,197 +14,87 @@ 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" + 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" + 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" ) -var testTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1alpha1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example.dev", Version: "v1alpha1", Kind: "TestType"} - -type testTypesClusterClient struct { - *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.") - } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1alpha1.TestType, *examplev1alpha1.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) (*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() +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, } - 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 } -// 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) typedkcpexamplev1alpha1.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) 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 97f8fae70..d57b00238 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 @@ -14,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" - 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" + typedexamplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -41,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. @@ -59,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 c76c30cb3..a28bd75de 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 @@ -14,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" - 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" + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 6b59d7eff..7c1080794 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) 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] } @@ -50,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. @@ -78,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 } @@ -90,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 bb282611b..d200c66d5 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 @@ -14,186 +14,78 @@ 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" + 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" + 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" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1beta1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example.dev", 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 +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, } - - 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 } -// 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 659a5b853..8617f4a8e 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 af86c5554..0cf43b950 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 @@ -14,197 +14,87 @@ 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" + 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" - kcpexamplev1beta1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/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" ) -var testTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v1beta1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example.dev", Version: "v1beta1", Kind: "TestType"} - -type testTypesClusterClient struct { - *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.") - } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev1beta1.TestType, *examplev1beta1.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) (*examplev1beta1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &examplev1beta1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() +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, } - list := &examplev1beta1.TestTypeList{ListMeta: obj.(*examplev1beta1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1beta1.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 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) typedkcpexamplev1beta1.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) examplev1beta1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexamplev1beta1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*examplev1beta1.TestType, *examplev1beta1.TestTypeList, *v1beta1.TestTypeApplyConfiguration] + Fake *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 -} - -// 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) (*examplev1beta1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &examplev1beta1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &examplev1beta1.TestTypeList{ListMeta: obj.(*examplev1beta1.TestTypeList).ListMeta} - for _, item := range obj.(*examplev1beta1.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) (*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 (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 -} - -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 05f7f02a1..e09ff9e1e 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 @@ -14,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" - 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" + typedexamplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -41,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) (*examplev1beta1.TestTypeList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + 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. @@ -59,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) (*examplev1beta1.TestTypeList, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).List(ctx, opts) +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 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 examplev1beta1client.TestTypeInterface. +// 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 5c4e06335..d989e5334 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 @@ -14,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" - 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" + apisexamplev2 "acme.corp/pkg/apis/example/v2" + examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 f6e4c4282..3941e4486 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) 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] } @@ -50,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. @@ -78,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 } @@ -90,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 7e3cf4cb4..144507f6c 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 @@ -14,186 +14,78 @@ 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" + 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" + 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" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v2", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example.dev", 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 +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, } - - 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 } -// 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 f71b23156..8a7a17a06 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 73b2333a1..40346e4ca 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 @@ -14,197 +14,83 @@ 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" + 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" + 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" ) -var testTypesResource = schema.GroupVersionResource{Group: "example.dev", Version: "v2", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example.dev", Version: "v2", Kind: "TestType"} - -type testTypesClusterClient struct { - *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.") - } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*examplev2.TestType, *examplev2.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) (*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() +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, } - 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 } -// 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) typedkcpexamplev2.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) 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 37a3eca68..c6af25a96 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 @@ -14,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" - 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" + typedexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -41,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. @@ -59,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 455302a58..8bc1aca5a 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 @@ -14,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" 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" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" + example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 a78e00fb2..6d271a4c4 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) 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] } @@ -50,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. @@ -78,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 } @@ -90,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 df053b400..efd6be85f 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 @@ -14,186 +14,78 @@ 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" + 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" + 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 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 +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, } - - 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 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 3d9ad3b01..8fc8d96e0 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 172633fd5..ac7094780 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 @@ -14,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" + context "context" "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" 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" 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 +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*example3v1.TestType, *example3v1.TestTypeList] + Fake *kcptesting.Fake } -// 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.") +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 &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) (*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) - } - } - return list, err +func (c *testTypeClusterClient) Cluster(cluster logicalcluster.Path) typedkcpexample3v1.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) 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 839e05a87..68c63b02a 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 @@ -14,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" 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" + typedexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -43,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. @@ -68,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 index 0a3121c6d..c3a731a3c 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go @@ -14,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" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" - exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + apisexampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,19 +38,20 @@ type ClusterTestTypesClusterGetter interface { } // ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, -// or scope down to one cluster and return a exampledashedv1client.ClusterTestTypeInterface. +// or scope down to one cluster and return a exampledashedv1.ClusterTestTypeInterface. type ClusterTestTypeClusterInterface interface { - Cluster(logicalcluster.Path) exampledashedv1client.ClusterTestTypeInterface - List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) + 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[*exampledashedv1client.ExampleDashedV1Client] + clientCache kcpclient.Cache[*exampledashedv1.ExampleDashedV1Client] } // Cluster scopes the client down to a particular cluster. -func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) exampledashedv1client.ClusterTestTypeInterface { +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.") } @@ -59,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) (*exampledashedv1.ClusterTestTypeList, error) { +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*apisexampledashedv1.ClusterTestTypeList, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(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 index 1ef27fd52..2f122b261 100644 --- 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) type ExampleDashedV1ClusterInterface interface { ExampleDashedV1ClusterScoper - TestTypesClusterGetter 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] } @@ -50,23 +53,25 @@ func (c *ExampleDashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) return c.clientCache.ClusterOrDie(clusterPath) } -func (c *ExampleDashedV1ClusterClient) TestTypes() TestTypeClusterInterface { - return &testTypesClusterInterface{clientCache: c.clientCache} -} - 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) { - 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 ExampleDashedV1ClusterClient for the given config and http client. @@ -78,6 +83,7 @@ func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleDashedV1Clus if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err } + return &ExampleDashedV1ClusterClient{clientCache: cache}, nil } @@ -90,3 +96,14 @@ func NewForConfigOrDie(c *rest.Config) *ExampleDashedV1ClusterClient { } 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 index e42c093b9..a90b149f0 100644 --- 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 @@ -14,186 +14,78 @@ 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" + 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" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" - exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/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" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example-dashed.some.corp", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example-dashed.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) exampledashedv1client.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[*exampledashedv1.ClusterTestType, *exampledashedv1.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) (*exampledashedv1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &exampledashedv1.ClusterTestTypeList{}) - if obj == nil { - return nil, err +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, } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &exampledashedv1.ClusterTestTypeList{ListMeta: obj.(*exampledashedv1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*exampledashedv1.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 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) typedexampledashedv1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, cluster) } -type clusterTestTypesClient struct { - *kcptesting.Fake +// clusterTestTypeScopedClient implements ClusterTestTypeInterface +type clusterTestTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*exampledashedv1.ClusterTestType, *exampledashedv1.ClusterTestTypeList, *v1.ClusterTestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.CreateOptions) (*exampledashedv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.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), &exampledashedv1.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, &exampledashedv1.ClusterTestTypeList{}) - return err -} - -func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.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) (*exampledashedv1.ClusterTestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &exampledashedv1.ClusterTestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &exampledashedv1.ClusterTestTypeList{ListMeta: obj.(*exampledashedv1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*exampledashedv1.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) (*exampledashedv1.ClusterTestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.ClusterTestType), err -} - -func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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"), &exampledashedv1.ClusterTestType{}) - if obj == nil { - return nil, err +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, } - return obj.(*exampledashedv1.ClusterTestType), err } 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 index 955c35e55..8d4f2387a 100644 --- 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "k8s.io/client-go/rest" exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" @@ -41,30 +41,30 @@ func (c *ExampleDashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) return &ExampleDashedV1Client{Fake: c.Fake, ClusterPath: clusterPath} } -func (c *ExampleDashedV1ClusterClient) TestTypes() kcpexampledashedv1.TestTypeClusterInterface { - return &testTypesClusterClient{Fake: c.Fake} -} - func (c *ExampleDashedV1ClusterClient) ClusterTestTypes() kcpexampledashedv1.ClusterTestTypeClusterInterface { - return &clusterTestTypesClusterClient{Fake: c.Fake} + return newFakeClusterTestTypeClusterClient(c) } -var _ exampledashedv1.ExampleDashedV1Interface = (*ExampleDashedV1Client)(nil) +func (c *ExampleDashedV1ClusterClient) TestTypes() kcpexampledashedv1.TestTypeClusterInterface { + return newFakeTestTypeClusterClient(c) +} type ExampleDashedV1Client struct { *kcptesting.Fake ClusterPath logicalcluster.Path } -func (c *ExampleDashedV1Client) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret +func (c *ExampleDashedV1Client) ClusterTestTypes() exampledashedv1.ClusterTestTypeInterface { + return newFakeClusterTestTypeClient(c.Fake, c.ClusterPath) } func (c *ExampleDashedV1Client) TestTypes(namespace string) exampledashedv1.TestTypeInterface { - return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} + return newFakeTestTypeClient(c.Fake, namespace, c.ClusterPath) } -func (c *ExampleDashedV1Client) ClusterTestTypes() exampledashedv1.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 *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 index 098e1afff..62a58b498 100644 --- 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 @@ -14,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" + context "context" "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" 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" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" - exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" - kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/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" ) -var testTypesResource = schema.GroupVersionResource{Group: "example-dashed.some.corp", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example-dashed.some.corp", Version: "v1", Kind: "TestType"} - -type testTypesClusterClient struct { - *kcptesting.Fake +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*exampledashedv1.TestType, *exampledashedv1.TestTypeList] + Fake *kcptesting.Fake } -// Cluster scopes the client down to a particular cluster. -func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexampledashedv1.TestTypesNamespacer { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") +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, } - - 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) (*exampledashedv1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &exampledashedv1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &exampledashedv1.TestTypeList{ListMeta: obj.(*exampledashedv1.TestTypeList).ListMeta} - for _, item := range obj.(*exampledashedv1.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) typedkcpexampledashedv1.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) exampledashedv1client.TestTypeInterface { - return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +func (n *testTypeNamespacer) Namespace(namespace string) typedexampledashedv1.TestTypeInterface { + return newFakeTestTypeClient(n.Fake, namespace, n.ClusterPath) } -type testTypesClient struct { - *kcptesting.Fake +// testTypeScopedClient implements TestTypeInterface +type testTypeScopedClient struct { + *kcpgentype.FakeClientWithListAndApply[*exampledashedv1.TestType, *exampledashedv1.TestTypeList, *v1.TestTypeApplyConfiguration] + Fake *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string -} - -func (c *testTypesClient) Create(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.CreateOptions) (*exampledashedv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.TestType), err -} - -func (c *testTypesClient) Update(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.TestType), err -} - -func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.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), &exampledashedv1.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, &exampledashedv1.TestTypeList{}) - return err -} - -func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.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) (*exampledashedv1.TestTypeList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &exampledashedv1.TestTypeList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &exampledashedv1.TestTypeList{ListMeta: obj.(*exampledashedv1.TestTypeList).ListMeta} - for _, item := range obj.(*exampledashedv1.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) (*exampledashedv1.TestType, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.TestType), err -} - -func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.TestType), err -} - -func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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"), &exampledashedv1.TestType{}) - if obj == nil { - return nil, err - } - return obj.(*exampledashedv1.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) 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 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/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 index ce4377c53..b44856e3b 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/testtype.go @@ -14,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" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" + watch "k8s.io/apimachinery/pkg/watch" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + typedexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -43,10 +43,11 @@ 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[*exampledashedv1client.ExampleDashedV1Client] + clientCache kcpclient.Cache[*typedexampledashedv1.ExampleDashedV1Client] } // Cluster scopes the client down to a particular cluster. @@ -68,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 exampledashedv1client.TestTypeInterface. +// TestTypesNamespacer can scope to objects within a namespace, returning a typedexampledashedv1.TestTypeInterface. type TestTypesNamespacer interface { - Namespace(string) exampledashedv1client.TestTypeInterface + Namespace(string) typedexampledashedv1.TestTypeInterface } type testTypesNamespacer struct { - clientCache kcpclient.Cache[*exampledashedv1client.ExampleDashedV1Client] + clientCache kcpclient.Cache[*typedexampledashedv1.ExampleDashedV1Client] clusterPath logicalcluster.Path } -func (n *testTypesNamespacer) Namespace(namespace string) exampledashedv1client.TestTypeInterface { +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 d693778e2..244e5f76d 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 @@ -14,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" 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" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 c05661de5..0e598bb4f 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) 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] } @@ -50,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. @@ -78,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 } @@ -90,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 3c125cef7..04757db3a 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 @@ -14,186 +14,78 @@ 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" + 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" + 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" ) -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 +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, } - - 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 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 5f529c058..664873184 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 369220e2b..849d09593 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 @@ -14,197 +14,87 @@ 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" + 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" + 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" ) -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 -} - -// 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.") - } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*existinginterfacesv1.TestType, *existinginterfacesv1.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) (*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() +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, } - 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 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) typedkcpexistinginterfacesv1.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) 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 fa8068bed..783b6b16a 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 @@ -14,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" 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" + typedexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -43,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. @@ -68,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 2f026b3fa..1f646905c 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 @@ -14,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" 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" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" ) // ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. @@ -38,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.") } @@ -59,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 eae881b2b..a49a9548f 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 @@ -14,186 +14,78 @@ 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" + 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" + 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" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "secondexample.dev", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "secondexample.dev", 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 +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, } - - 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 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 c6621b5e6..459b46868 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 @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ 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" + rest "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" @@ -41,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 57a0f8f63..97616242a 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 @@ -14,197 +14,87 @@ 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" + 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" + 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" ) -var testTypesResource = schema.GroupVersionResource{Group: "secondexample.dev", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "secondexample.dev", Version: "v1", Kind: "TestType"} - -type testTypesClusterClient struct { - *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.") - } - - return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +// testTypeClusterClient implements TestTypeClusterInterface +type testTypeClusterClient struct { + *kcpgentype.FakeClusterClientWithList[*secondexamplev1.TestType, *secondexamplev1.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) (*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() +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, } - 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 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) typedkcpsecondexamplev1.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) 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 319025e2b..58dcc70ac 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 @@ -14,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" - "k8s.io/client-go/rest" + rest "k8s.io/client-go/rest" + 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" ) 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] } @@ -50,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. @@ -78,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 } @@ -90,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 bffaaac14..f2bcb27b2 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 @@ -14,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" 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" + typedsecondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" ) // TestTypesClusterGetter has a method to return a TestTypeClusterInterface. @@ -43,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. @@ -68,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 78fc12331..13992241e 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/interface.go @@ -14,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 dab7403ea..2e3a76ed3 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/clustertesttype.go @@ -14,37 +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" + logicalcluster "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" - - 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) examplev1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1listers.ClusterTestTypeClusterLister + Lister() listersexamplev1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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() listersexamplev1.ClusterTestTypeClusterLister { + return listersexamplev1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 aaa482a25..04919a1d7 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/interface.go @@ -14,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 { @@ -34,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 d48722d28..a1e52d7e0 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/testtype.go @@ -14,37 +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" + logicalcluster "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" - - 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev1informers.TestTypeInformer + Cluster(logicalcluster.Name) examplev1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1listers.TestTypeClusterLister + Lister() listersexamplev1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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() listersexamplev1.TestTypeClusterLister { + return listersexamplev1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev1informers.TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev1.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 6b2d21aa2..dd3cd4f2f 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/clustertesttype.go @@ -14,37 +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" 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" + + 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev1alpha1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) examplev1alpha1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1alpha1listers.ClusterTestTypeClusterLister + Lister() listersexamplev1alpha1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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 (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev1alpha1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev1alpha1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 3cd93a453..cd3b12485 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/interface.go @@ -14,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 { @@ -34,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 f543be7c3..ed03573f6 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/testtype.go @@ -14,37 +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" 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" + + 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev1alpha1informers.TestTypeInformer + Cluster(logicalcluster.Name) examplev1alpha1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1alpha1listers.TestTypeClusterLister + Lister() listersexamplev1alpha1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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 (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev1alpha1informers.TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev1alpha1.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 965f28056..9c33c1fd4 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/clustertesttype.go @@ -14,37 +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" 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" + + 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev1beta1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) examplev1beta1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1beta1listers.ClusterTestTypeClusterLister + Lister() listersexamplev1beta1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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 (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev1beta1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev1beta1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 5bdbd4034..cedc3e64d 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/interface.go @@ -14,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 v1beta1 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 { @@ -34,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/v1beta1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/testtype.go index f0e926c49..d39f50354 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/testtype.go @@ -14,37 +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" 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" + + 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev1beta1informers.TestTypeInformer + Cluster(logicalcluster.Name) examplev1beta1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev1beta1listers.TestTypeClusterLister + Lister() listersexamplev1beta1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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.ExampleV1beta1().TestTypes().List(context.TODO(), options) + return client.ExampleV1beta1().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.ExampleV1beta1().TestTypes().Watch(context.TODO(), options) + return client.ExampleV1beta1().TestTypes().Watch(context.Background(), options) }, }, - &examplev1beta1.TestType{}, + &apisexamplev1beta1.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(&examplev1beta1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexamplev1beta1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Lister() examplev1beta1listers.TestTypeClusterLister { - return examplev1beta1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Lister() listersexamplev1beta1.TestTypeClusterLister { + return listersexamplev1beta1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev1beta1informers.TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev1beta1.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexamplev1beta1listers.TestTypeLister + lister generatedlistersexamplev1beta1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() upstreamexamplev1beta1listers.TestTypeLister { - return f.lister +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 481393bca..46f2016ab 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/clustertesttype.go @@ -14,37 +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" 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" + + 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev2informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) examplev2.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev2listers.ClusterTestTypeClusterLister + Lister() listersexamplev2.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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 (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev2informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev2.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 a167ca714..055242bc3 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/interface.go @@ -14,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 { @@ -34,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 3d26b6d83..355b2c5f9 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/testtype.go @@ -14,37 +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" 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" + + 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexamplev2informers.TestTypeInformer + Cluster(logicalcluster.Name) examplev2.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() examplev2listers.TestTypeClusterLister + Lister() listersexamplev2.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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 (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexamplev2informers.TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examplev2.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 188984b3f..d6ccc6e2d 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/interface.go @@ -14,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 2b3bb7411..45d070210 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/clustertesttype.go @@ -14,37 +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" + logicalcluster "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" - - 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexample3v1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) example3v1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() example3v1listers.ClusterTestTypeClusterLister + Lister() listersexample3v1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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() listersexample3v1.ClusterTestTypeClusterLister { + return listersexample3v1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexample3v1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) example3v1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 aaa482a25..04919a1d7 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/interface.go @@ -14,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 { @@ -34,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 fd4da045a..b9ef93341 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/testtype.go @@ -14,37 +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" + logicalcluster "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" - - 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexample3v1informers.TestTypeInformer + Cluster(logicalcluster.Name) example3v1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() example3v1listers.TestTypeClusterLister + Lister() listersexample3v1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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() listersexample3v1.TestTypeClusterLister { + return listersexample3v1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexample3v1informers.TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) example3v1.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 index 8de0750b1..6f8a69981 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/interface.go @@ -14,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 exampledashed import ( - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + 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 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/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go index f1145ffb7..6de4b8ae0 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go @@ -14,37 +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" + logicalcluster "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" - - exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - upstreamexampledashedv1informers "acme.corp/pkg/generated/informers/externalversions/exampledashed/v1" - upstreamexampledashedv1listers "acme.corp/pkg/generated/listers/exampledashed/v1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - exampledashedv1listers "acme.corp/pkg/kcpexisting/clients/listers/exampledashed/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexampledashedv1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) exampledashedv1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() exampledashedv1listers.ClusterTestTypeClusterLister + Lister() listersexampledashedv1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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.ExampleDashedV1().ClusterTestTypes().List(context.TODO(), 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.TODO(), options) + return client.ExampleDashedV1().ClusterTestTypes().Watch(context.Background(), options) }, }, - &exampledashedv1.ClusterTestType{}, + &apisexampledashedv1.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(&exampledashedv1.ClusterTestType{}, f.defaultInformer) +func (i *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexampledashedv1.ClusterTestType{}, i.defaultInformer) } -func (f *clusterTestTypeClusterInformer) Lister() exampledashedv1listers.ClusterTestTypeClusterLister { - return exampledashedv1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *clusterTestTypeClusterInformer) Lister() listersexampledashedv1.ClusterTestTypeClusterLister { + return listersexampledashedv1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexampledashedv1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) exampledashedv1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), } } type clusterTestTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexampledashedv1listers.ClusterTestTypeLister + lister generatedlistersexampledashedv1.ClusterTestTypeLister } -func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *clusterTestTypeInformer) Lister() upstreamexampledashedv1listers.ClusterTestTypeLister { - return f.lister +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 index aaa482a25..04919a1d7 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/interface.go @@ -14,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 { @@ -34,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/exampledashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go index aec1b8aee..38bc83054 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go @@ -14,37 +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" + logicalcluster "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" - - exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - upstreamexampledashedv1informers "acme.corp/pkg/generated/informers/externalversions/exampledashed/v1" - upstreamexampledashedv1listers "acme.corp/pkg/generated/listers/exampledashed/v1" - clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" - "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" - exampledashedv1listers "acme.corp/pkg/kcpexisting/clients/listers/exampledashed/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexampledashedv1informers.TestTypeInformer + Cluster(logicalcluster.Name) exampledashedv1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() exampledashedv1listers.TestTypeClusterLister + Lister() listersexampledashedv1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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.ExampleDashedV1().TestTypes().List(context.TODO(), 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.TODO(), options) + return client.ExampleDashedV1().TestTypes().Watch(context.Background(), options) }, }, - &exampledashedv1.TestType{}, + &apisexampledashedv1.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(&exampledashedv1.TestType{}, f.defaultInformer) +func (i *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return i.factory.InformerFor(&apisexampledashedv1.TestType{}, i.defaultInformer) } -func (f *testTypeClusterInformer) Lister() exampledashedv1listers.TestTypeClusterLister { - return exampledashedv1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +func (i *testTypeClusterInformer) Lister() listersexampledashedv1.TestTypeClusterLister { + return listersexampledashedv1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexampledashedv1informers.TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) exampledashedv1.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().Cluster(clusterName), } } type testTypeInformer struct { informer cache.SharedIndexInformer - lister upstreamexampledashedv1listers.TestTypeLister + lister generatedlistersexampledashedv1.TestTypeLister } -func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.informer +func (i *testTypeInformer) Informer() cache.SharedIndexInformer { + return i.informer } -func (f *testTypeInformer) Lister() upstreamexampledashedv1listers.TestTypeLister { - return f.lister +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 7cde0bd8c..47a8e729a 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/interface.go @@ -14,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 f5d1b148d..9c5059609 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go @@ -14,37 +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" + logicalcluster "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" - - 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexistinginterfacesv1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) existinginterfacesv1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() existinginterfacesv1listers.ClusterTestTypeClusterLister + Lister() listersexistinginterfacesv1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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() listersexistinginterfacesv1.ClusterTestTypeClusterLister { + return listersexistinginterfacesv1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexistinginterfacesv1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) existinginterfacesv1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 aaa482a25..04919a1d7 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/interface.go @@ -14,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 { @@ -34,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 d19fc2bcb..4e5717c6a 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/testtype.go @@ -14,37 +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" + logicalcluster "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" - - 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamexistinginterfacesv1informers.TestTypeInformer + Cluster(logicalcluster.Name) existinginterfacesv1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() existinginterfacesv1listers.TestTypeClusterLister + Lister() listersexistinginterfacesv1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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() listersexistinginterfacesv1.TestTypeClusterLister { + return listersexistinginterfacesv1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexistinginterfacesv1informers.TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) existinginterfacesv1.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 70025f626..d9705e655 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go @@ -14,31 +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" 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" - exampledashedinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/exampledashed" - 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" + + 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" + + 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" ) // SharedInformerOption defines the functional option type for SharedInformerFactory. @@ -48,10 +48,11 @@ 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 @@ -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 @@ -95,13 +96,21 @@ func WithTransform(transform cache.TransformFunc) SharedInformerOption { } } -// NewSharedInformerFactory constructs a new instance of SharedInformerFactory for all namespaces. -func NewSharedInformerFactory(client clientset.ClusterInterface, defaultResync time.Duration) SharedInformerFactory { +// 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, @@ -127,7 +136,6 @@ func NewSharedInformerFactoryWithOptions(client clientset.ClusterInterface, defa return factory } -// Start initializes all requested informers. func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { f.lock.Lock() defer f.lock.Unlock() @@ -161,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() @@ -180,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() @@ -200,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 @@ -207,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. @@ -221,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 { @@ -245,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 @@ -259,41 +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 - ExampleDashed() exampledashedinformers.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) ExampleDashed() exampledashedinformers.ClusterInterface { - return exampledashedinformers.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 { @@ -308,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 18fcd2e98..79f7f8499 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go @@ -14,32 +14,32 @@ 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" + fmt "fmt" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" + logicalcluster "github.com/kcp-dev/logicalcluster/v3" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/tools/cache" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" 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" - exampledashedv1 "acme.corp/pkg/apis/exampledashed/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" ) type GenericClusterInformer interface { - Cluster(logicalcluster.Name) upstreaminformers.GenericInformer + Cluster(logicalcluster.Name) informersexternalversions.GenericInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() kcpcache.GenericClusterLister } @@ -50,20 +50,20 @@ 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: f.Informer().Cluster(clusterName), - lister: f.Lister().ByCluster(clusterName), + informer: i.Informer().Cluster(clusterName), + lister: i.Lister().ByCluster(clusterName), } } @@ -73,59 +73,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=example-dashed.some.corp, Version=V1 - case exampledashedv1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().TestTypes().Informer()}, nil - case exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"): + // Group=example-dashed.some.corp, Version=v1 + case v1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().ClusterTestTypes().Informer()}, nil - // 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.dev, Version=V1 - case examplev1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1().TestTypes().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.dev, 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.dev, Version=V1beta1 - case examplev1beta1.SchemeGroupVersion.WithResource("testtypes"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().TestTypes().Informer()}, nil - 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.dev, 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.dev, 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 4c2d99732..7a34096ee 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -14,7 +14,7 @@ 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 @@ -23,20 +23,20 @@ import ( kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - 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" + versioned "acme.corp/pkg/kcpexisting/clients/clientset/versioned" ) -// 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 448e8271f..81dbe752b 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/interface.go @@ -14,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 b491026cd..3512edd6e 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/clustertesttype.go @@ -14,37 +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" + logicalcluster "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" - - 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" + + 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" ) // ClusterTestTypeClusterInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamsecondexamplev1informers.ClusterTestTypeInformer + Cluster(logicalcluster.Name) secondexamplev1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() secondexamplev1listers.ClusterTestTypeClusterLister + Lister() listerssecondexamplev1.ClusterTestTypeClusterLister } type clusterTestTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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() listerssecondexamplev1.ClusterTestTypeClusterLister { + return listerssecondexamplev1.NewClusterTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamsecondexamplev1informers.ClusterTestTypeInformer { +func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) secondexamplev1.ClusterTestTypeInformer { return &clusterTestTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 aaa482a25..04919a1d7 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/interface.go @@ -14,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 { @@ -34,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 c286f92a6..2989de319 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/testtype.go @@ -14,37 +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" + logicalcluster "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" - - 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" + + 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" ) // TestTypeClusterInformer provides access to a shared informer and lister for // TestTypes. type TestTypeClusterInformer interface { - Cluster(logicalcluster.Name) upstreamsecondexamplev1informers.TestTypeInformer + Cluster(logicalcluster.Name) secondexamplev1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() secondexamplev1listers.TestTypeClusterLister + Lister() listerssecondexamplev1.TestTypeClusterLister } type testTypeClusterInformer struct { @@ -55,67 +55,66 @@ 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() listerssecondexamplev1.TestTypeClusterLister { + return listerssecondexamplev1.NewTestTypeClusterLister(i.Informer().GetIndexer()) } -func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamsecondexamplev1informers.TestTypeInformer { +func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) secondexamplev1.TestTypeInformer { return &testTypeInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), + informer: i.Informer().Cluster(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 c5e427c8b..3ef772d52 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1/clustertesttype.go @@ -14,82 +14,87 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1 "acme.corp/pkg/apis/example/v1" - examplev1listers "acme.corp/pkg/generated/listers/example/v1" + listersexamplev1 "acme.corp/pkg/generated/listers/example/v1" ) -// 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 { + kcplisters.ResourceClusterIndexer[*examplev1.ClusterTestType] indexer cache.Indexer } +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 + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), + indexer, + } } // 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{ + kcplisters.New[*examplev1.ClusterTestType](l.indexer, clusterName, examplev1.Resource("clustertesttype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*examplev1.ClusterTestType] 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 -} +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 listersexamplev1.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) listersexamplev1.ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*examplev1.ClusterTestType](indexer, examplev1.Resource("clustertesttype")), + indexer, } - return obj.(*examplev1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexamplev1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + listers.ResourceIndexer[*examplev1.ClusterTestType] + indexer cache.Indexer } 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 b659ca391..627ae4e81 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1/testtype.go @@ -14,37 +14,42 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1 "acme.corp/pkg/apis/example/v1" - examplev1listers "acme.corp/pkg/generated/listers/example/v1" + listersexamplev1 "acme.corp/pkg/generated/listers/example/v1" ) -// 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 { + kcplisters.ResourceClusterIndexer[*examplev1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -52,65 +57,71 @@ type testTypeClusterLister struct { // - 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 + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev1.TestType](indexer, examplev1.Resource("testtype")), + indexer, + } } // 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{ + kcplisters.New[*examplev1.TestType](l.indexer, clusterName, examplev1.Resource("testtype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*examplev1.TestType] indexer cache.Indexer clusterName logicalcluster.Name } -// 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 newTestTypeNamespaceLister(l.ResourceIndexer, 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 +// newTestTypeNamespaceLister returns a new listersexamplev1.TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1.TestType], namespace string) listersexamplev1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - if !exists { - return nil, errors.NewNotFound(examplev1.Resource("testtypes"), name) +} + +// NewTestTypeLister returns a new listersexamplev1.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) listersexamplev1.TestTypeLister { + return &testTypeScopedLister{ + listers.New[*examplev1.TestType](indexer, examplev1.Resource("testtype")), + indexer, } - return obj.(*examplev1.TestType), nil +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexamplev1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + listers.ResourceIndexer[*examplev1.TestType] + indexer cache.Indexer +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev1.TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } 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..afe42f2d7 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/example/v1/withoutverbtype.go @@ -0,0 +1,127 @@ +/* +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 ( + "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/listers" + "k8s.io/client-go/tools/cache" + + examplev1 "acme.corp/pkg/apis/example/v1" + listersexamplev1 "acme.corp/pkg/generated/listers/example/v1" +) + +// 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] + indexer cache.Indexer +} + +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")), + indexer, + } +} + +// 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{ + kcplisters.New[*examplev1.WithoutVerbType](l.indexer, clusterName, examplev1.Resource("withoutverbtype")), + l.indexer, + 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] + indexer cache.Indexer + clusterName logicalcluster.Name +} + +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 newWithoutVerbTypeNamespaceLister(l.ResourceIndexer, namespace) +} + +// withoutVerbTypeNamespaceLister implements the listersexamplev1.WithoutVerbTypeNamespaceLister +// interface. +type withoutVerbTypeNamespaceLister struct { + kcplisters.ResourceIndexer[*examplev1.WithoutVerbType] +} + +var _ listersexamplev1.WithoutVerbTypeNamespaceLister = new(withoutVerbTypeNamespaceLister) + +// newWithoutVerbTypeNamespaceLister returns a new listersexamplev1.WithoutVerbTypeNamespaceLister. +func newWithoutVerbTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1.WithoutVerbType], namespace string) listersexamplev1.WithoutVerbTypeNamespaceLister { + return &withoutVerbTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), + } +} + +// NewWithoutVerbTypeLister returns a new listersexamplev1.WithoutVerbTypeLister. +// 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 NewWithoutVerbTypeLister(indexer cache.Indexer) listersexamplev1.WithoutVerbTypeLister { + return &withoutVerbTypeScopedLister{ + listers.New[*examplev1.WithoutVerbType](indexer, examplev1.Resource("withoutverbtype")), + indexer, + } +} + +// withoutVerbTypeScopedLister can list all WithoutVerbTypes inside a workspace +// or scope down to a listersexamplev1.WithoutVerbTypeNamespaceLister for one namespace. +type withoutVerbTypeScopedLister struct { + listers.ResourceIndexer[*examplev1.WithoutVerbType] + indexer cache.Indexer +} + +// WithoutVerbTypes returns an object that can list and get WithoutVerbTypes in one namespace. +func (l *withoutVerbTypeScopedLister) WithoutVerbTypes(namespace string) listersexamplev1.WithoutVerbTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) +} diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype.go index 2bc0b82aa..5e31da5f8 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/clustertesttype.go @@ -14,82 +14,87 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - examplev1alpha1listers "acme.corp/pkg/generated/listers/example/v1alpha1" + listersexamplev1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" ) -// 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 { + kcplisters.ResourceClusterIndexer[*examplev1alpha1.ClusterTestType] indexer cache.Indexer } +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 + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), + indexer, + } } // 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{ + kcplisters.New[*examplev1alpha1.ClusterTestType](l.indexer, clusterName, examplev1alpha1.Resource("clustertesttype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*examplev1alpha1.ClusterTestType] 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 -} +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 listersexamplev1alpha1.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) listersexamplev1alpha1.ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*examplev1alpha1.ClusterTestType](indexer, examplev1alpha1.Resource("clustertesttype")), + indexer, } - return obj.(*examplev1alpha1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexamplev1alpha1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + listers.ResourceIndexer[*examplev1alpha1.ClusterTestType] + indexer cache.Indexer } 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 beb2e24f1..aa56bac94 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1alpha1/testtype.go @@ -14,37 +14,42 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" - examplev1alpha1listers "acme.corp/pkg/generated/listers/example/v1alpha1" + listersexamplev1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" ) -// 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 { + kcplisters.ResourceClusterIndexer[*examplev1alpha1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -52,65 +57,71 @@ type testTypeClusterLister struct { // - 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 + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), + indexer, + } } // 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{ + kcplisters.New[*examplev1alpha1.TestType](l.indexer, clusterName, examplev1alpha1.Resource("testtype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*examplev1alpha1.TestType] indexer cache.Indexer clusterName logicalcluster.Name } -// 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 newTestTypeNamespaceLister(l.ResourceIndexer, 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 +// newTestTypeNamespaceLister returns a new listersexamplev1alpha1.TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1alpha1.TestType], namespace string) listersexamplev1alpha1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - if !exists { - return nil, errors.NewNotFound(examplev1alpha1.Resource("testtypes"), name) +} + +// NewTestTypeLister returns a new listersexamplev1alpha1.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) listersexamplev1alpha1.TestTypeLister { + return &testTypeScopedLister{ + listers.New[*examplev1alpha1.TestType](indexer, examplev1alpha1.Resource("testtype")), + indexer, } - return obj.(*examplev1alpha1.TestType), nil +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexamplev1alpha1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + listers.ResourceIndexer[*examplev1alpha1.TestType] + indexer cache.Indexer +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev1alpha1.TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype.go index 8d7c55241..49b5dcf96 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/clustertesttype.go @@ -14,82 +14,87 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - examplev1beta1listers "acme.corp/pkg/generated/listers/example/v1beta1" + listersexamplev1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" ) -// 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 { + kcplisters.ResourceClusterIndexer[*examplev1beta1.ClusterTestType] indexer cache.Indexer } +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 + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), + indexer, + } } // 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{ + kcplisters.New[*examplev1beta1.ClusterTestType](l.indexer, clusterName, examplev1beta1.Resource("clustertesttype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*examplev1beta1.ClusterTestType] 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 -} +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 listersexamplev1beta1.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) listersexamplev1beta1.ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*examplev1beta1.ClusterTestType](indexer, examplev1beta1.Resource("clustertesttype")), + indexer, } - return obj.(*examplev1beta1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexamplev1beta1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + listers.ResourceIndexer[*examplev1beta1.ClusterTestType] + indexer cache.Indexer } 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 index 3974cfd9a..f093c0657 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v1beta1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v1beta1/testtype.go @@ -14,37 +14,42 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" - examplev1beta1listers "acme.corp/pkg/generated/listers/example/v1beta1" + listersexamplev1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" ) -// 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 []*examplev1beta1.TestType, err error) // Cluster returns a lister that can list and get TestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) examplev1beta1listers.TestTypeLister + Cluster(clusterName logicalcluster.Name) listersexamplev1beta1.TestTypeLister TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*examplev1beta1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -52,65 +57,71 @@ type testTypeClusterLister struct { // - 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 []*examplev1beta1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*examplev1beta1.TestType)) - }) - return ret, err + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), + indexer, + } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) examplev1beta1listers.TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexamplev1beta1.TestTypeLister { + return &testTypeLister{ + kcplisters.New[*examplev1beta1.TestType](l.indexer, clusterName, examplev1beta1.Resource("testtype")), + l.indexer, + clusterName, + } } -// testTypeLister implements the examplev1beta1listers.TestTypeLister interface. +// 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] indexer cache.Indexer clusterName logicalcluster.Name } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*examplev1beta1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1beta1.TestType)) - }) - return ret, err -} +var _ listersexamplev1beta1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) examplev1beta1listers.TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +func (l *testTypeLister) TestTypes(namespace string) listersexamplev1beta1.TestTypeNamespaceLister { + return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) } -// testTypeNamespaceLister implements the examplev1beta1listers.TestTypeNamespaceLister interface. +// testTypeNamespaceLister implements the listersexamplev1beta1.TestTypeNamespaceLister +// interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string + kcplisters.ResourceIndexer[*examplev1beta1.TestType] } -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*examplev1beta1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*examplev1beta1.TestType)) - }) - return ret, err -} +var _ listersexamplev1beta1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*examplev1beta1.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err +// newTestTypeNamespaceLister returns a new listersexamplev1beta1.TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev1beta1.TestType], namespace string) listersexamplev1beta1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - if !exists { - return nil, errors.NewNotFound(examplev1beta1.Resource("testtypes"), name) +} + +// NewTestTypeLister returns a new listersexamplev1beta1.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) listersexamplev1beta1.TestTypeLister { + return &testTypeScopedLister{ + listers.New[*examplev1beta1.TestType](indexer, examplev1beta1.Resource("testtype")), + indexer, } - return obj.(*examplev1beta1.TestType), nil +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexamplev1beta1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + listers.ResourceIndexer[*examplev1beta1.TestType] + indexer cache.Indexer +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev1beta1.TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype.go index 9ca7aaa60..ae29ff4fb 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v2/clustertesttype.go @@ -14,82 +14,87 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev2 "acme.corp/pkg/apis/example/v2" - examplev2listers "acme.corp/pkg/generated/listers/example/v2" + listersexamplev2 "acme.corp/pkg/generated/listers/example/v2" ) -// 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 { + kcplisters.ResourceClusterIndexer[*examplev2.ClusterTestType] indexer cache.Indexer } +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 + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), + indexer, + } } // 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{ + kcplisters.New[*examplev2.ClusterTestType](l.indexer, clusterName, examplev2.Resource("clustertesttype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*examplev2.ClusterTestType] 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 -} +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 listersexamplev2.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) listersexamplev2.ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*examplev2.ClusterTestType](indexer, examplev2.Resource("clustertesttype")), + indexer, } - return obj.(*examplev2.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexamplev2.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + listers.ResourceIndexer[*examplev2.ClusterTestType] + indexer cache.Indexer } 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 f2b4c1d99..d88372750 100644 --- a/examples/pkg/kcpexisting/clients/listers/example/v2/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example/v2/testtype.go @@ -14,37 +14,42 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" examplev2 "acme.corp/pkg/apis/example/v2" - examplev2listers "acme.corp/pkg/generated/listers/example/v2" + listersexamplev2 "acme.corp/pkg/generated/listers/example/v2" ) -// 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 { + kcplisters.ResourceClusterIndexer[*examplev2.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -52,65 +57,71 @@ type testTypeClusterLister struct { // - 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 + return &testTypeClusterLister{ + kcplisters.NewCluster[*examplev2.TestType](indexer, examplev2.Resource("testtype")), + indexer, + } } // 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{ + kcplisters.New[*examplev2.TestType](l.indexer, clusterName, examplev2.Resource("testtype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*examplev2.TestType] indexer cache.Indexer clusterName logicalcluster.Name } -// 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 newTestTypeNamespaceLister(l.ResourceIndexer, 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 +// newTestTypeNamespaceLister returns a new listersexamplev2.TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*examplev2.TestType], namespace string) listersexamplev2.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - if !exists { - return nil, errors.NewNotFound(examplev2.Resource("testtypes"), name) +} + +// NewTestTypeLister returns a new listersexamplev2.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) listersexamplev2.TestTypeLister { + return &testTypeScopedLister{ + listers.New[*examplev2.TestType](indexer, examplev2.Resource("testtype")), + indexer, } - return obj.(*examplev2.TestType), nil +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexamplev2.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + listers.ResourceIndexer[*examplev2.TestType] + indexer cache.Indexer +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexamplev2.TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype.go index 1177c2500..a0abc34ec 100644 --- a/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/example3/v1/clustertesttype.go @@ -14,82 +14,87 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" example3v1 "acme.corp/pkg/apis/example3/v1" - example3v1listers "acme.corp/pkg/generated/listers/example3/v1" + listersexample3v1 "acme.corp/pkg/generated/listers/example3/v1" ) -// 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 { + kcplisters.ResourceClusterIndexer[*example3v1.ClusterTestType] indexer cache.Indexer } +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 + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), + indexer, + } } // 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{ + kcplisters.New[*example3v1.ClusterTestType](l.indexer, clusterName, example3v1.Resource("clustertesttype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*example3v1.ClusterTestType] 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 -} +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 listersexample3v1.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) listersexample3v1.ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*example3v1.ClusterTestType](indexer, example3v1.Resource("clustertesttype")), + indexer, } - return obj.(*example3v1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexample3v1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + listers.ResourceIndexer[*example3v1.ClusterTestType] + indexer cache.Indexer } 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 ce0c87f6f..efe7f81ac 100644 --- a/examples/pkg/kcpexisting/clients/listers/example3/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/example3/v1/testtype.go @@ -14,37 +14,42 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" example3v1 "acme.corp/pkg/apis/example3/v1" - example3v1listers "acme.corp/pkg/generated/listers/example3/v1" + listersexample3v1 "acme.corp/pkg/generated/listers/example3/v1" ) -// 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 { + kcplisters.ResourceClusterIndexer[*example3v1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -52,65 +57,71 @@ type testTypeClusterLister struct { // - 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 + return &testTypeClusterLister{ + kcplisters.NewCluster[*example3v1.TestType](indexer, example3v1.Resource("testtype")), + indexer, + } } // 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{ + kcplisters.New[*example3v1.TestType](l.indexer, clusterName, example3v1.Resource("testtype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*example3v1.TestType] indexer cache.Indexer clusterName logicalcluster.Name } -// 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 newTestTypeNamespaceLister(l.ResourceIndexer, 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 +// newTestTypeNamespaceLister returns a new listersexample3v1.TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*example3v1.TestType], namespace string) listersexample3v1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - if !exists { - return nil, errors.NewNotFound(example3v1.Resource("testtypes"), name) +} + +// NewTestTypeLister returns a new listersexample3v1.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) listersexample3v1.TestTypeLister { + return &testTypeScopedLister{ + listers.New[*example3v1.TestType](indexer, example3v1.Resource("testtype")), + indexer, } - return obj.(*example3v1.TestType), nil +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexample3v1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + listers.ResourceIndexer[*example3v1.TestType] + indexer cache.Indexer +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexample3v1.TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go index 0d672b27c..d046ed953 100644 --- a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go @@ -14,82 +14,87 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - exampledashedv1listers "acme.corp/pkg/generated/listers/exampledashed/v1" + listersexampledashedv1 "acme.corp/pkg/generated/listers/exampledashed/v1" ) -// 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 []*exampledashedv1.ClusterTestType, err error) // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) exampledashedv1listers.ClusterTestTypeLister + Cluster(clusterName logicalcluster.Name) listersexampledashedv1.ClusterTestTypeLister ClusterTestTypeClusterListerExpansion } +// clusterTestTypeClusterLister implements the ClusterTestTypeClusterLister interface. type clusterTestTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*exampledashedv1.ClusterTestType] indexer cache.Indexer } +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 []*exampledashedv1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*exampledashedv1.ClusterTestType)) - }) - return ret, err + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), + indexer, + } } // Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. -func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) exampledashedv1listers.ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexampledashedv1.ClusterTestTypeLister { + return &clusterTestTypeLister{ + kcplisters.New[*exampledashedv1.ClusterTestType](l.indexer, clusterName, exampledashedv1.Resource("clustertesttype")), + l.indexer, + clusterName, + } } -// clusterTestTypeLister implements the exampledashedv1listers.ClusterTestTypeLister interface. +// 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] indexer cache.Indexer clusterName logicalcluster.Name } -// List lists all ClusterTestTypes in the indexer for a workspace. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*exampledashedv1.ClusterTestType)) - }) - return ret, err -} +var _ listersexampledashedv1.ClusterTestTypeLister = new(clusterTestTypeLister) -// Get retrieves the ClusterTestType from the indexer for a given workspace and name. -func (s *clusterTestTypeLister) Get(name string) (*exampledashedv1.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(exampledashedv1.Resource("clustertesttypes"), name) +// NewClusterTestTypeLister returns a new listersexampledashedv1.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) listersexampledashedv1.ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*exampledashedv1.ClusterTestType](indexer, exampledashedv1.Resource("clustertesttype")), + indexer, } - return obj.(*exampledashedv1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexampledashedv1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + listers.ResourceIndexer[*exampledashedv1.ClusterTestType] + indexer cache.Indexer } diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/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/exampledashed/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/exampledashed/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 index 780638988..ce12b9eb9 100644 --- a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go @@ -14,37 +14,42 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" - exampledashedv1listers "acme.corp/pkg/generated/listers/exampledashed/v1" + listersexampledashedv1 "acme.corp/pkg/generated/listers/exampledashed/v1" ) -// 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 []*exampledashedv1.TestType, err error) // Cluster returns a lister that can list and get TestTypes in one workspace. - Cluster(clusterName logicalcluster.Name) exampledashedv1listers.TestTypeLister + Cluster(clusterName logicalcluster.Name) listersexampledashedv1.TestTypeLister TestTypeClusterListerExpansion } +// testTypeClusterLister implements the TestTypeClusterLister interface. type testTypeClusterLister struct { + kcplisters.ResourceClusterIndexer[*exampledashedv1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -52,65 +57,71 @@ type testTypeClusterLister struct { // - 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 []*exampledashedv1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*exampledashedv1.TestType)) - }) - return ret, err + return &testTypeClusterLister{ + kcplisters.NewCluster[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), + indexer, + } } // Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. -func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) exampledashedv1listers.TestTypeLister { - return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +func (l *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) listersexampledashedv1.TestTypeLister { + return &testTypeLister{ + kcplisters.New[*exampledashedv1.TestType](l.indexer, clusterName, exampledashedv1.Resource("testtype")), + l.indexer, + clusterName, + } } -// testTypeLister implements the exampledashedv1listers.TestTypeLister interface. +// 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] indexer cache.Indexer clusterName logicalcluster.Name } -// List lists all TestTypes in the indexer for a workspace. -func (s *testTypeLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*exampledashedv1.TestType)) - }) - return ret, err -} +var _ listersexampledashedv1.TestTypeLister = new(testTypeLister) // TestTypes returns an object that can list and get TestTypes in one namespace. -func (s *testTypeLister) TestTypes(namespace string) exampledashedv1listers.TestTypeNamespaceLister { - return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +func (l *testTypeLister) TestTypes(namespace string) listersexampledashedv1.TestTypeNamespaceLister { + return newTestTypeNamespaceLister(l.ResourceIndexer, namespace) } -// testTypeNamespaceLister implements the exampledashedv1listers.TestTypeNamespaceLister interface. +// testTypeNamespaceLister implements the listersexampledashedv1.TestTypeNamespaceLister +// interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string + kcplisters.ResourceIndexer[*exampledashedv1.TestType] } -// List lists all TestTypes in the indexer for a given workspace and namespace. -func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*exampledashedv1.TestType)) - }) - return ret, err -} +var _ listersexampledashedv1.TestTypeNamespaceLister = new(testTypeNamespaceLister) -// Get retrieves the TestType from the indexer for a given workspace, namespace and name. -func (s *testTypeNamespaceLister) Get(name string) (*exampledashedv1.TestType, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err +// newTestTypeNamespaceLister returns a new listersexampledashedv1.TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*exampledashedv1.TestType], namespace string) listersexampledashedv1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - if !exists { - return nil, errors.NewNotFound(exampledashedv1.Resource("testtypes"), name) +} + +// NewTestTypeLister returns a new listersexampledashedv1.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) listersexampledashedv1.TestTypeLister { + return &testTypeScopedLister{ + listers.New[*exampledashedv1.TestType](indexer, exampledashedv1.Resource("testtype")), + indexer, } - return obj.(*exampledashedv1.TestType), nil +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexampledashedv1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + listers.ResourceIndexer[*exampledashedv1.TestType] + indexer cache.Indexer +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexampledashedv1.TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype.go index 8537a1130..41ed57257 100644 --- a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/clustertesttype.go @@ -14,82 +14,87 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - existinginterfacesv1listers "acme.corp/pkg/generated/listers/existinginterfaces/v1" + listersexistinginterfacesv1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" ) -// 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 { + kcplisters.ResourceClusterIndexer[*existinginterfacesv1.ClusterTestType] indexer cache.Indexer } +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 + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), + indexer, + } } // 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{ + kcplisters.New[*existinginterfacesv1.ClusterTestType](l.indexer, clusterName, existinginterfacesv1.Resource("clustertesttype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*existinginterfacesv1.ClusterTestType] 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 -} +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 listersexistinginterfacesv1.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) listersexistinginterfacesv1.ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*existinginterfacesv1.ClusterTestType](indexer, existinginterfacesv1.Resource("clustertesttype")), + indexer, } - return obj.(*existinginterfacesv1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listersexistinginterfacesv1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + listers.ResourceIndexer[*existinginterfacesv1.ClusterTestType] + indexer cache.Indexer } 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 b5543523f..08a3f5159 100644 --- a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/existinginterfaces/v1/testtype.go @@ -14,37 +14,42 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" - existinginterfacesv1listers "acme.corp/pkg/generated/listers/existinginterfaces/v1" + listersexistinginterfacesv1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" ) -// 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 { + kcplisters.ResourceClusterIndexer[*existinginterfacesv1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -52,65 +57,71 @@ type testTypeClusterLister struct { // - 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 + return &testTypeClusterLister{ + kcplisters.NewCluster[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), + indexer, + } } // 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{ + kcplisters.New[*existinginterfacesv1.TestType](l.indexer, clusterName, existinginterfacesv1.Resource("testtype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*existinginterfacesv1.TestType] indexer cache.Indexer clusterName logicalcluster.Name } -// 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 newTestTypeNamespaceLister(l.ResourceIndexer, 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 +// newTestTypeNamespaceLister returns a new listersexistinginterfacesv1.TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*existinginterfacesv1.TestType], namespace string) listersexistinginterfacesv1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - if !exists { - return nil, errors.NewNotFound(existinginterfacesv1.Resource("testtypes"), name) +} + +// NewTestTypeLister returns a new listersexistinginterfacesv1.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) listersexistinginterfacesv1.TestTypeLister { + return &testTypeScopedLister{ + listers.New[*existinginterfacesv1.TestType](indexer, existinginterfacesv1.Resource("testtype")), + indexer, } - return obj.(*existinginterfacesv1.TestType), nil +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listersexistinginterfacesv1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + listers.ResourceIndexer[*existinginterfacesv1.TestType] + indexer cache.Indexer +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listersexistinginterfacesv1.TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } diff --git a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype.go index 4fea9fb4d..a6c02aa73 100644 --- a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype.go @@ -14,82 +14,87 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - secondexamplev1listers "acme.corp/pkg/generated/listers/secondexample/v1" + listerssecondexamplev1 "acme.corp/pkg/generated/listers/secondexample/v1" ) -// 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 { + kcplisters.ResourceClusterIndexer[*secondexamplev1.ClusterTestType] indexer cache.Indexer } +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 + return &clusterTestTypeClusterLister{ + kcplisters.NewCluster[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), + indexer, + } } // 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{ + kcplisters.New[*secondexamplev1.ClusterTestType](l.indexer, clusterName, secondexamplev1.Resource("clustertesttype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*secondexamplev1.ClusterTestType] 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 -} +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 listerssecondexamplev1.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) listerssecondexamplev1.ClusterTestTypeLister { + return &clusterTestTypeScopedLister{ + listers.New[*secondexamplev1.ClusterTestType](indexer, secondexamplev1.Resource("clustertesttype")), + indexer, } - return obj.(*secondexamplev1.ClusterTestType), nil +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace +// or scope down to a listerssecondexamplev1.ClusterTestTypeNamespaceLister. +type clusterTestTypeScopedLister struct { + listers.ResourceIndexer[*secondexamplev1.ClusterTestType] + indexer cache.Indexer } diff --git a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype_expansion.go deleted file mode 100644 index 08fb95b1c..000000000 --- a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/clustertesttype_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 - -// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. -type ClusterTestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/existinginterfaces/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/existinginterfaces/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/existinginterfaces/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 2f60b5aa3..4947cd4e4 100644 --- a/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/listers/secondexample/v1/testtype.go @@ -14,37 +14,42 @@ 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" - "k8s.io/apimachinery/pkg/api/errors" + kcplisters "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/listers" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" - secondexamplev1listers "acme.corp/pkg/generated/listers/secondexample/v1" + listerssecondexamplev1 "acme.corp/pkg/generated/listers/secondexample/v1" ) -// 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 { + kcplisters.ResourceClusterIndexer[*secondexamplev1.TestType] indexer cache.Indexer } +var _ TestTypeClusterLister = new(testTypeClusterLister) + // NewTestTypeClusterLister returns a new TestTypeClusterLister. // We assume that the indexer: // - is fed by a cross-workspace LIST+WATCH @@ -52,65 +57,71 @@ type testTypeClusterLister struct { // - 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 + return &testTypeClusterLister{ + kcplisters.NewCluster[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), + indexer, + } } // 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{ + kcplisters.New[*secondexamplev1.TestType](l.indexer, clusterName, secondexamplev1.Resource("testtype")), + l.indexer, + 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 { + kcplisters.ResourceIndexer[*secondexamplev1.TestType] indexer cache.Indexer clusterName logicalcluster.Name } -// 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 newTestTypeNamespaceLister(l.ResourceIndexer, 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 +// newTestTypeNamespaceLister returns a new listerssecondexamplev1.TestTypeNamespaceLister. +func newTestTypeNamespaceLister(indexer kcplisters.ResourceIndexer[*secondexamplev1.TestType], namespace string) listerssecondexamplev1.TestTypeNamespaceLister { + return &testTypeNamespaceLister{ + kcplisters.NewNamespaced(indexer, namespace), } - if !exists { - return nil, errors.NewNotFound(secondexamplev1.Resource("testtypes"), name) +} + +// NewTestTypeLister returns a new listerssecondexamplev1.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) listerssecondexamplev1.TestTypeLister { + return &testTypeScopedLister{ + listers.New[*secondexamplev1.TestType](indexer, secondexamplev1.Resource("testtype")), + indexer, } - return obj.(*secondexamplev1.TestType), nil +} + +// testTypeScopedLister can list all TestTypes inside a workspace +// or scope down to a listerssecondexamplev1.TestTypeNamespaceLister for one namespace. +type testTypeScopedLister struct { + listers.ResourceIndexer[*secondexamplev1.TestType] + indexer cache.Indexer +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (l *testTypeScopedLister) TestTypes(namespace string) listerssecondexamplev1.TestTypeNamespaceLister { + return listers.NewNamespaced(l.ResourceIndexer, namespace) } 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/go.mod b/go.mod index f8d426ebf..348a65790 100644 --- a/go.mod +++ b/go.mod @@ -1,38 +1,21 @@ -module github.com/kcp-dev/code-generator/v2 +module github.com/kcp-dev/code-generator/v3 go 1.23.0 +toolchain go1.23.7 + require ( - github.com/onsi/ginkgo v1.16.5 - github.com/onsi/gomega v1.36.2 - github.com/spf13/cobra v1.9.1 github.com/spf13/pflag v1.0.6 golang.org/x/text v0.24.0 - golang.org/x/tools v0.32.0 - k8s.io/apimachinery v0.32.3 k8s.io/code-generator v0.32.3 k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 k8s.io/klog/v2 v2.130.1 - sigs.k8s.io/controller-tools v0.17.3 ) require ( - github.com/fatih/color v1.18.0 // indirect - github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/google/go-cmp v0.7.0 // indirect - github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/kr/pretty v0.3.1 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/nxadm/tail v1.4.8 // indirect - github.com/rogpeppe/go-internal v1.12.0 // indirect golang.org/x/mod v0.24.0 // indirect - golang.org/x/net v0.39.0 // indirect golang.org/x/sync v0.13.0 // indirect - golang.org/x/sys v0.32.0 // indirect - gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // 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 + golang.org/x/tools v0.32.0 // indirect ) diff --git a/go.sum b/go.sum index fab425244..294eceeb7 100644 --- a/go.sum +++ b/go.sum @@ -1,146 +1,20 @@ -github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= -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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= -github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= -github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= 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-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -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/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/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.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg= -github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= -github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -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/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -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.22.1 h1:QW7tbJAUDyVDVOM5dFa7qaybo+CRfR7bemlQUN6Z8aM= -github.com/onsi/ginkgo/v2 v2.22.1/go.mod h1:S6aTpoRsSq2cZOd+pssHAlKW/Q/jZt6cPrPlnj4a1xM= -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.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8= -github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= -github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= 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/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -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.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 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/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-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.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= -golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= -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-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= -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-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.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= -golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -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.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= -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-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.32.0 h1:Q7N1vhpkQv7ybVzLFtTjvQya2ewbwNDZzUgfXGqtMWU= golang.org/x/tools v0.32.0/go.mod h1:ZxrU41P/wAbZD8EDa6dDCa6XfpkhJ7HFMjHJXfBDu8s= -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.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk= -google.golang.org/protobuf v1.36.1/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-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -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.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.32.3 h1:JmDuDarhDmA/Li7j3aPrwhpNBA94Nvk5zLeOge9HH1U= -k8s.io/apimachinery v0.32.3/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE= k8s.io/code-generator v0.32.3 h1:31p2TVzC9+hVdSkAFruAk3JY+iSfzrJ83Qij1yZutyw= k8s.io/code-generator v0.32.3/go.mod h1:+mbiYID5NLsBuqxjQTygKM/DAdKpAjvBzrJd64NU1G8= k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 h1:si3PfKm8dDYxgfbeA6orqrtLkvvIeH8UqffFJDl0bz4= k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9/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= -sigs.k8s.io/controller-tools v0.17.3 h1:lwFPLicpBKLgIepah+c8ikRBubFW5kOQyT88r3EwfNw= -sigs.k8s.io/controller-tools v0.17.3/go.mod h1:1ii+oXcYZkxcBXzwv3YZBlzjt1fvkrCGjVF73blosJI= 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 index 016171564..d09641e02 100755 --- a/hack/go-install.sh +++ b/hack/go-install.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright 2021 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. diff --git a/pkg/internal/listergen/parser.go b/hack/tools.go similarity index 66% rename from pkg/internal/listergen/parser.go rename to hack/tools.go index bb9ce20bc..f49388ba7 100644 --- a/pkg/internal/listergen/parser.go +++ b/hack/tools.go @@ -1,5 +1,9 @@ +//go:build tools +// +build tools + /* -Copyright 2022 The KCP Authors. +Copyright 2025 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. @@ -14,19 +18,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -package listergen +package tools +// This package imports things required by this repository, to force `go mod` to see them as dependencies 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, - } + _ "k8s.io/code-generator/cmd/client-gen" ) diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index f38bda0ae..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,65 +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 exampledashed/v1 \ - --input secondexample/v1 \ - --input existinginterfaces/v1 \ - --output-dir ./pkg/generated/clientset \ - --output-pkg acme.corp/pkg/generated/clientset +pushd ./examples -${KUBE_APPLYCONFIGURATION_GEN} \ - --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ - --output-dir ./pkg/generated/applyconfigurations \ - --output-pkg acme.corp/pkg/generated/applyconfigurations \ - 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/exampledashed/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 +# 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 \ - --output-dir ./pkg/generated/listers \ - --output-pkg acme.corp/pkg/generated/listers \ - 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/exampledashed/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 +# 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 \ - --output-dir ./pkg/generated/informers \ - --output-pkg acme.corp/pkg/generated/informers \ - 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/exampledashed/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 +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 diff --git a/main.go b/main.go deleted file mode 100644 index b6f4acaf2..000000000 --- a/main.go +++ /dev/null @@ -1,265 +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. - def, err := markers.MakeDefinition(genName, markers.DescribesPackage, gen) - def.Strict = false - defn := markers.Must(def, err) - 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 { - def, err := markers.MakeDefinition(fmt.Sprintf("output:%s:%s", genName, ruleName), markers.DescribesPackage, rule) - def.Strict = false - ruleMarker := markers.Must(def, err) - 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 { - def, err := markers.MakeDefinition("output:"+ruleName, markers.DescribesPackage, rule) - def.Strict = false - - ruleMarker := markers.Must(def, err) - 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 552f016be..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 are options accepted by the 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 78131800a..000000000 --- a/pkg/flag/flags_test.go +++ /dev/null @@ -1,66 +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. -*/ - -//nolint:revive -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 bae3cb579..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/v2/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) []parser.Group { - var info []parser.Group - 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) parser.Group { - return parser.Group{ - Group: group.Group, - Version: parser.Version(namer.IC(version.Version.String())), - PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GoName: 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 c24514b5c..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/v2/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() - - onlyGroups := make([]parser.Group, 0, len(groupVersionKinds)) - 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[parser.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[parser.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 []parser.Version - for version := range versions { - onlyVersions = append(onlyVersions, parser.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) []parser.Group { - var info []parser.Group - 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) parser.Group { - return parser.Group{ - Group: group.Group, - PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - Version: parser.Version(namer.IC(version.Version.String())), - GoName: 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 cde9d6b7b..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/v2/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) parser.Group { - return parser.Group{ - Group: group.Group, - Version: parser.Version(namer.IC(version.Version.String())), - PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GoName: 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..ea46989ac --- /dev/null +++ b/pkg/imports/kcptracker.go @@ -0,0 +1,88 @@ +/* +Copyright 2025 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. +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 668b730ea..000000000 --- a/pkg/internal/clientgen/clientset.go +++ /dev/null @@ -1,173 +0,0 @@ -package clientgen - -import ( - "io" - "strings" - "text/template" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" - "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 []parser.Group - - // 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, - "packageName": strings.ReplaceAll(c.Name, "-", ""), - "packagePath": c.PackagePath, - "groups": c.Groups, - "singleClusterClientPackagePath": c.SingleClusterClientPackagePath, - } - return templ.Execute(w, m) -} - -var clientset = ` -// Code generated by kcp code-generator. DO NOT EDIT. - -package {{.packageName}} - -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}} {{.GoPackageAlias}} "{{$.packagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}" -{{end -}} -) - -type ClusterInterface interface { - Cluster(logicalcluster.Path) client.Interface - Discovery() discovery.DiscoveryInterface -{{range .groups}} {{.GroupGoName}}{{.Version}}() {{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface -{{end -}} -} - -// ClusterClientset contains the clients for groups. -type ClusterClientset struct { - *discovery.DiscoveryClient - clientCache kcpclient.Cache[*client.Clientset] -{{range .groups}} {{.GroupGoNameLower}}{{.Version}} *{{.GoPackageAlias}}.{{.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}}() {{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { - return c.{{.GroupGoNameLower}}{{.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.{{.GroupGoNameLower}}{{.Version}}, err = {{.GoPackageAlias}}.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 179e8fee7..000000000 --- a/pkg/internal/clientgen/fake_clientset.go +++ /dev/null @@ -1,151 +0,0 @@ -package clientgen - -import ( - "io" - "strings" - "text/template" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" - "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 []parser.Group - - // 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 = ` -// 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}} {{.GoPackageAlias}} "{{$.singleClusterClientPackagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}" -{{end -}} -{{range .groups}} kcp{{.GoPackageAlias}} "{{$.packagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}" -{{end -}} -{{range .groups}} fake{{.GoPackageAlias}} "{{$.packagePath}}/typed/{{.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{{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { - return &fake{{.GoPackageAlias}}.{{.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}}() {{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}Interface { - return &fake{{.GoPackageAlias}}.{{.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 ea151b158..000000000 --- a/pkg/internal/clientgen/fake_group.go +++ /dev/null @@ -1,97 +0,0 @@ -package clientgen - -import ( - "io" - "strings" - "text/template" - - "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 parser.Group - - // 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 = ` -// 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.GoPackageAlias}} "{{.packagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" - {{.group.GoPackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" -) - -var _ kcp{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.String}}ClusterInterface { - return &{{.Plural | lowerFirst}}ClusterClient{Fake: c.Fake} -} -{{end -}} - -var _ {{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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 545abd381..000000000 --- a/pkg/internal/clientgen/fake_type.go +++ /dev/null @@ -1,459 +0,0 @@ -package clientgen - -import ( - "fmt" - "io" - "path/filepath" - "strings" - "text/template" - - "k8s.io/apimachinery/pkg/util/sets" - - "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 parser.Group - - // 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 = ` -// 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.GoPackageAlias}} "{{.apiPackagePath}}/{{.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.GoPackageAlias}} "{{.singleClusterApplyConfigurationsPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" -{{end}} - -{{- if .kind.IsNamespaced}} - kcp{{.group.GoPackageAlias}} "{{.packagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" -{{end}} - {{.group.GoPackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.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.GoPackageAlias}}.{{.kind.Plural}}Namespacer{{else}}{{.group.GoPackageAlias}}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.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.kind.String}}List{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &{{.group.GoPackageAlias}}.{{.kind.String}}List{ListMeta: obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}List).ListMeta} - for _, item := range obj.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}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.GoPackageAlias}}.{{.kind.String}}, opts metav1.CreateOptions) (*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err -} -{{end -}} - -{{if "update" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Update(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.GoPackageAlias}}.{{.kind.String}}, opts metav1.UpdateOptions) (*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err -} -{{end -}} - -{{if "updateStatus" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) UpdateStatus(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.GoPackageAlias}}.{{.kind.String}}, opts metav1.UpdateOptions) (*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.kind.String}}List{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &{{.group.GoPackageAlias}}.{{.kind.String}}List{ListMeta: obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}List).ListMeta} - for _, item := range obj.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err -} -{{end -}} - -{{if and .generateApplyVerbs ("apply" | .kind.SupportedVerbs.Has) }} -func (c *{{.kind.Plural | lowerFirst}}Client) Apply(ctx context.Context, applyConfiguration *applyconfigurations{{.group.GoPackageAlias}}.{{.kind.String}}ApplyConfiguration, opts metav1.ApplyOptions) (*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err -} -{{end -}} - -{{if and .generateApplyVerbs ("applyStatus" | .kind.SupportedVerbs.Has) }} -func (c *{{.kind.Plural | lowerFirst}}Client) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurations{{.group.GoPackageAlias}}.{{.kind.String}}ApplyConfiguration, opts metav1.ApplyOptions) (*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.kind.String}}{}) - if obj == nil { - return nil, err - } - return obj.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{$.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.GoPackageAlias}}.{{$.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 c28035ba1..000000000 --- a/pkg/internal/clientgen/group.go +++ /dev/null @@ -1,117 +0,0 @@ -package clientgen - -import ( - "io" - "strings" - "text/template" - - "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 parser.Group - - // 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 = ` -// 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.GoPackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.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.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface -} - -type {{.group.GroupGoName}}{{.group.Version}}ClusterClient struct { - clientCache kcpclient.Cache[*{{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Client] -} - -func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Client]{ - NewForConfigAndClient: {{.group.GoPackageAlias}}.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 a8cf60450..000000000 --- a/pkg/internal/clientgen/scheme.go +++ /dev/null @@ -1,82 +0,0 @@ -package clientgen - -import ( - "io" - "strings" - "text/template" - - "github.com/kcp-dev/code-generator/v2/pkg/parser" - "github.com/kcp-dev/code-generator/v2/pkg/util" -) - -type Scheme struct { - // Groups are the groups in this client-set. - Groups []parser.Group - - // 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 = ` -// 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}} {{.GoPackageAlias}} "{{$.apiPackagePath}}/{{.PackageName}}/{{.Version.PackageName}}" -{{end -}} -) - -var Scheme = runtime.NewScheme() -var Codecs = serializer.NewCodecFactory(Scheme) -var ParameterCodec = runtime.NewParameterCodec(Scheme) -var localSchemeBuilder = runtime.SchemeBuilder{ -{{range .groups}} {{.GoPackageAlias}}.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 d1ad7536a..000000000 --- a/pkg/internal/clientgen/type.go +++ /dev/null @@ -1,129 +0,0 @@ -package clientgen - -import ( - "io" - "strings" - "text/template" - - "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 parser.Group - - // 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 = ` -// 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.GoPackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" -{{end}} - - {{.group.GoPackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.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.GoPackageAlias}}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.GoPackageAlias}}client.{{.kind.String}}Interface{{end}}. -{{ end -}} -type {{.kind.String}}ClusterInterface interface { - Cluster(logicalcluster.Path) {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.GoPackageAlias}}client.{{.kind.String}}Interface{{end}} -{{- if .kind.SupportsListWatch }} - List(ctx context.Context, opts metav1.ListOptions) (*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}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.GoPackageAlias}}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.GoPackageAlias}}.{{.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.GoPackageAlias}}client.{{.kind.String}}Interface. -type {{.kind.Plural}}Namespacer interface { - Namespace(string) {{.group.GoPackageAlias}}client.{{.kind.String}}Interface -} - -type {{.kind.Plural | lowerFirst}}Namespacer struct { - clientCache kcpclient.Cache[*{{.group.GoPackageAlias}}client.{{.group.GroupGoName}}{{.group.Version}}Client] - clusterPath logicalcluster.Path -} - -func (n *{{.kind.Plural | lowerFirst}}Namespacer) Namespace(namespace string) {{.group.GoPackageAlias}}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 1764a4ca3..000000000 --- a/pkg/internal/informergen/factory.go +++ /dev/null @@ -1,496 +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 = ` -// 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}} {{.PackageName}}informers "{{$.packagePath}}/{{.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 - transform cache.TransformFunc - {{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 - transform cache.TransformFunc - - 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 - } -} - -// 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 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 - 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() - - 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}} {{.GroupGoName}}() {{.PackageName}}informers.ClusterInterface -{{end -}} -} - -{{range .groups}} -func (f *sharedInformerFactory) {{.GroupGoName}}() {{.PackageName}}informers.ClusterInterface { - return {{.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 - transform cache.TransformFunc - - 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) - 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 { - internalinterfaces.SharedScopedInformerFactory - ForResource(resource schema.GroupVersionResource) (GenericInformer, error) - WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool - -{{range .groups}} {{.GroupGoName}}() {{.PackageName}}informers.Interface -{{end -}} -} - - -{{range .groups}} -func (f *sharedScopedInformerFactory) {{.GroupGoName}}() {{.PackageName}}informers.Interface { - return {{.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 d4e648790..000000000 --- a/pkg/internal/informergen/factoryinterface.go +++ /dev/null @@ -1,95 +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 = ` -// 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 af46d14b1..000000000 --- a/pkg/internal/informergen/generic.go +++ /dev/null @@ -1,163 +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 []parser.Group - - // GroupVersionKinds are all the kinds we need to support,indexed by group and version. - GroupVersionKinds map[types.Group]map[parser.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 = ` -// 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}} {{.GoPackageAlias}} "{{$.apiPackagePath}}/{{.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.GoPackageAlias}}.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.GoPackageAlias}}.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 280f68d33..000000000 --- a/pkg/internal/informergen/groupinterface.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" - "strings" - "text/template" - - "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 []parser.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, - "packageName": strings.ReplaceAll(g.Group.PackageName(), "-", ""), - "packagePath": g.PackagePath, - "versions": g.Versions, - "useUpstreamInterfaces": g.UseUpstreamInterfaces, - } - return templ.Execute(w, m) -} - -var groupInterface = ` -// Code generated by kcp code-generator. DO NOT EDIT. - -package {{.packageName}} - -import ( -{{range .versions}} "{{$.packagePath}}/{{$.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 796040425..000000000 --- a/pkg/internal/informergen/informer.go +++ /dev/null @@ -1,262 +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 Informer struct { - // Group is the group in this informer. - Group parser.Group - - // 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 = ` -// 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.GoPackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" - {{.group.GoPackageAlias}}listers "{{.listerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" - {{if .useUpstreamInterfaces -}} - upstream{{.group.GoPackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" - upstream{{.group.GoPackageAlias}}informers "{{.singleClusterInformerPackagePath}}/{{.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.GoPackageAlias}}informers.{{end}}{{.kind}}Informer - Informer() kcpcache.ScopeableSharedIndexInformer - Lister() {{.group.GoPackageAlias}}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.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.kind}}{}, f.defaultInformer) -} - -func (f *{{.kind.String|lowerFirst}}ClusterInformer) Lister() {{.group.GoPackageAlias}}listers.{{.kind.String}}ClusterLister { - return {{.group.GoPackageAlias}}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.GoPackageAlias}}listers.{{.kind}}Lister -} -{{end -}} - -func (f *{{.kind.String|lowerFirst}}ClusterInformer) Cluster(clusterName logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.GoPackageAlias}}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.GoPackageAlias}}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.GoPackageAlias}}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.GoPackageAlias}}.{{.kind}}{}, f.defaultInformer) -} - -func (f *{{.kind.String|lowerFirst}}ScopedInformer) Lister() {{.group.GoPackageAlias}}listers.{{.kind.String}}Lister { - return {{.group.GoPackageAlias}}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.GoPackageAlias}}.{{.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 93a5c038b..000000000 --- a/pkg/internal/informergen/versioninterface.go +++ /dev/null @@ -1,116 +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" - "strings" - "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, - "packageName": strings.ReplaceAll(v.Version.PackageName(), "-", ""), - "useUpstreamInterfaces": v.UseUpstreamInterfaces, - } - return templ.Execute(w, m) -} - -var versionInterfaceTemplate = ` -// Code generated by kcp code-generator. DO NOT EDIT. - -package {{.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 3186b5740..000000000 --- a/pkg/internal/listergen/expansions.go +++ /dev/null @@ -1,52 +0,0 @@ -package listergen - -import ( - "io" - "text/template" - - "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 parser.Group - // 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 = ` -// 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 864d5bad1..000000000 --- a/pkg/internal/listergen/lister.go +++ /dev/null @@ -1,295 +0,0 @@ -package listergen - -import ( - "io" - "text/template" - - "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 parser.Group - // 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 = ` -// 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.GoPackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" - {{if .useUpstreamInterfaces -}} - {{.group.GoPackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}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.GoPackageAlias}}.{{.kind.String}}, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}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.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}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.GoPackageAlias}}.{{.kind.String}}, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) - } - return obj.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}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.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}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.GoPackageAlias}}.{{.kind.String}}, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) - } - return obj.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.kind.String}}, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) - } - return obj.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.kind.String}}, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.GoPackageAlias}}.{{.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.GoPackageAlias}}.{{.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.GoPackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) - } - return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), nil -} -{{ end -}} -{{end -}} -` diff --git a/pkg/parser/extract.go b/pkg/parser/extract.go deleted file mode 100644 index 3c4882fa4..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/v2/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 e4ca6c8d3..000000000 --- a/pkg/parser/markers.go +++ /dev/null @@ -1,238 +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{}{})) -) - -func GenclientMarker() *markers.Definition { - def := genclientMarker - def.Strict = false - return def -} - -func NonNamespacedMarker() *markers.Definition { - def := nonNamespacedMarker - def.Strict = false - return def -} - -func SkipVerbsMarker() *markers.Definition { - def := skipVerbsMarker - def.Strict = false - return def -} - -func OnlyVerbsMarker() *markers.Definition { - def := onlyVerbsMarker - def.Strict = false - return def -} - -func GroupNameMarker() *markers.Definition { - def := groupNameMarker - def.Strict = false - return def -} - -func GroupGoNameMarker() *markers.Definition { - def := groupGoNameMarker - def.Strict = false - return def -} - -func NoStatusMarker() *markers.Definition { - def := noStatusMarker - def.Strict = false - return def -} - -func NoVerbsMarker() *markers.Definition { - def := noVerbsMarker - def.Strict = false - return def -} - -func ReadOnlyMarker() *markers.Definition { - def := readOnlyMarker - def.Strict = false - return def -} - -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 - } - extensions := make([]Extension, 0, len(values)) - 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 845e78fcf..000000000 --- a/pkg/parser/types.go +++ /dev/null @@ -1,133 +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 ( - "strings" - - "golang.org/x/text/cases" - "golang.org/x/text/language" - - "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 `marker:",+groupGoName"` - Version Version - PackageAlias string - LowerCaseGroupGoName string -} - -func (g Group) GoPackageAlias() string { - if g.PackageAlias == "" { - panic("PackageAlias is empty. Programmer error.") - } - return strings.ReplaceAll(g.PackageAlias, "-", "") -} - -func (g Group) GroupGoName() string { - if g.GoName == "" { - panic("GroupGoName is empty. Programmer error.") - } - caser := cases.Title(language.English) - parts := strings.Split(g.GoName, "-") - for i, part := range parts { - parts[i] = caser.String(part) - } - return strings.Join(parts, "") -} - -func (g Group) GroupGoNameLower() string { - if g.LowerCaseGroupGoName == "" { - panic("LowerCaseGroupGoName is empty. Programmer error.") - } - result := strings.ToLower(g.LowerCaseGroupGoName) - return strings.ReplaceAll(result, "-", "") -} - -func (g Group) PackageName() string { - return strings.ToLower(strings.ReplaceAll(g.Group.PackageName(), "-", "")) -} - -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") -} - -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 { - _v := strings.ReplaceAll(v.NonEmpty(), "-", "") - return strings.ToLower(_v) -} - -// 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", - "ResourceClaimParameters": "ResourceClaimParameters", - "ResourceClassParameters": "ResourceClassParameters", - }, - }, - } -} diff --git a/pkg/util/plural_exceptions.go b/pkg/util/plural_exceptions.go new file mode 100644 index 000000000..0b28f2d9a --- /dev/null +++ b/pkg/util/plural_exceptions.go @@ -0,0 +1,38 @@ +/* +Copyright 2025 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. +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 d5f5bd998..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 2f39b6ae8..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 public/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) - } - } -}