From dacf11b0482db8f37793bc4e65d9df4bd89543d4 Mon Sep 17 00:00:00 2001 From: Todd Treece <360020+toddtreece@users.noreply.github.com> Date: Wed, 14 Aug 2024 01:17:05 -0400 Subject: [PATCH] K8s: Fix hack/update-codegen (#91867) --- go.mod | 5 +- go.sum | 9 +- hack/externalTools.go | 2 +- hack/openapi-codegen.sh | 139 +++++++------ hack/update-codegen.sh | 28 +-- .../v0alpha1/zz_generated.openapi.go | 2 - .../aggregation/v0alpha1/dataplaneservice.go | 10 +- .../v0alpha1/dataplaneservicecondition.go | 4 +- .../v0alpha1/dataplaneservicespec.go | 4 +- .../v0alpha1/dataplaneservicestatus.go | 4 +- .../aggregation/v0alpha1/service.go | 4 +- .../generated/applyconfiguration/utils.go | 7 + .../versioned/fake/clientset_generated.go | 39 +++- .../aggregation/v0alpha1/dataplaneservice.go | 192 +----------------- .../v0alpha1/fake/fake_dataplaneservice.go | 46 +++-- .../informers/externalversions/factory.go | 1 + .../aggregation/v0alpha1/dataplaneservice.go | 26 +-- .../v0alpha1/zz_generated.openapi.go | 127 ------------ ...enerated.openapi_violation_exceptions.list | 1 - .../v0alpha1/zz_generated.openapi.go | 2 - .../v0alpha1/zz_generated.openapi.go | 2 - .../v0alpha1/zz_generated.openapi.go | 9 +- .../folder/v0alpha1/zz_generated.openapi.go | 2 - .../peakq/v0alpha1/zz_generated.openapi.go | 2 - .../playlist/v0alpha1/zz_generated.openapi.go | 2 - .../query/v0alpha1/zz_generated.openapi.go | 2 - .../scope/v0alpha1/zz_generated.openapi.go | 2 - .../service/v0alpha1/zz_generated.openapi.go | 2 - .../service/v0alpha1/externalname.go | 10 +- .../service/v0alpha1/externalnamespec.go | 4 +- pkg/generated/applyconfiguration/utils.go | 7 + .../versioned/fake/clientset_generated.go | 39 +++- .../typed/service/v0alpha1/externalname.go | 157 +------------- .../v0alpha1/fake/fake_externalname.go | 34 ++-- .../informers/externalversions/factory.go | 1 + .../listers/service/v0alpha1/externalname.go | 39 +--- 36 files changed, 296 insertions(+), 670 deletions(-) delete mode 100644 pkg/apis/dashboard/v0alpha1/zz_generated.openapi_violation_exceptions.list diff --git a/go.mod b/go.mod index 8354bfab659..e25a771cb46 100644 --- a/go.mod +++ b/go.mod @@ -90,7 +90,8 @@ require ( github.com/grafana/grafana-google-sdk-go v0.1.0 // @grafana/partner-datasources github.com/grafana/grafana-openapi-client-go v0.0.0-20231213163343-bd475d63fb79 // @grafana/grafana-backend-group github.com/grafana/grafana-plugin-sdk-go v0.241.0 // @grafana/plugins-platform-backend - github.com/grafana/grafana/pkg/apimachinery v0.0.0-20240730185644-783ff7156079 // @grafana/grafana-app-platform-squad + github.com/grafana/grafana/pkg/aggregator v0.0.0-20240813192817-1b0e6b5c09b2 // @grafana/grafana-app-platform-squad + github.com/grafana/grafana/pkg/apimachinery v0.0.0-20240808213237-f4d2e064f435 // @grafana/grafana-app-platform-squad github.com/grafana/grafana/pkg/apiserver v0.0.0-20240708134731-e9876749d440 // @grafana/grafana-app-platform-squad // This needs to be here for other projects that import grafana/grafana // For local development grafana/grafana will always use the local files @@ -481,8 +482,10 @@ require ( ) require ( + github.com/grafana/grafana/pkg/semconv v0.0.0-20240808213237-f4d2e064f435 // indirect github.com/hairyhenderson/go-which v0.2.0 // indirect github.com/iancoleman/orderedmap v0.3.0 // indirect + k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 // indirect ) // Use fork of crewjam/saml with fixes for some issues until changes get merged into upstream diff --git a/go.sum b/go.sum index 5b06cb81a86..d96c51fc82e 100644 --- a/go.sum +++ b/go.sum @@ -2343,12 +2343,16 @@ github.com/grafana/grafana-openapi-client-go v0.0.0-20231213163343-bd475d63fb79/ github.com/grafana/grafana-plugin-sdk-go v0.114.0/go.mod h1:D7x3ah+1d4phNXpbnOaxa/osSaZlwh9/ZUnGGzegRbk= github.com/grafana/grafana-plugin-sdk-go v0.241.0 h1:zBcSW9xV9gA9hD8UN+HjJtD7tESMZcaQhA1BI76MTxM= github.com/grafana/grafana-plugin-sdk-go v0.241.0/go.mod h1:2HjNwzGCfaFAyR2HGoECTwAmq8vSIn2L1/1yOt4XRS4= -github.com/grafana/grafana/pkg/apimachinery v0.0.0-20240730185644-783ff7156079 h1:JnIzjNpW56Z9Tdmkzfs+kn3h2vtqavdr/CJTdAG1GIM= -github.com/grafana/grafana/pkg/apimachinery v0.0.0-20240730185644-783ff7156079/go.mod h1:m/Tqd1ow+lmYtCj6/UZpejLdP2sxtN/4r6THdzS48r4= +github.com/grafana/grafana/pkg/aggregator v0.0.0-20240813192817-1b0e6b5c09b2 h1:2H9x4q53pkfUGtSNYD1qSBpNnxrFgylof/TYADb5xMI= +github.com/grafana/grafana/pkg/aggregator v0.0.0-20240813192817-1b0e6b5c09b2/go.mod h1:gBLBniiSUQvyt4LRrpIeysj8Many0DV+hdUKifRE0Ec= +github.com/grafana/grafana/pkg/apimachinery v0.0.0-20240808213237-f4d2e064f435 h1:lmw60EW7JWlAEvgggktOyVkH4hF1m/+LSF/Ap0NCyi8= +github.com/grafana/grafana/pkg/apimachinery v0.0.0-20240808213237-f4d2e064f435/go.mod h1:ORVFiW/KNRY52lNjkGwnFWCxNVfE97bJG2jr2fetq0I= github.com/grafana/grafana/pkg/apiserver v0.0.0-20240708134731-e9876749d440 h1:833vWSgndCcOXycwCq2Y98W8+W2ouuuhTL+Gf3BNKg8= github.com/grafana/grafana/pkg/apiserver v0.0.0-20240708134731-e9876749d440/go.mod h1:qfZc7FEYBdKcxHUTtWtEAH+ArbMIkEQnbVPzr8giY3k= github.com/grafana/grafana/pkg/promlib v0.0.6 h1:FuRyHMIgVVXkLuJnCflNfk3gqJflmyiI+/ZuJ9MoAfY= github.com/grafana/grafana/pkg/promlib v0.0.6/go.mod h1:shFkrG1fQ/PPNRGhxAPNMLp0SAeG/jhqaLoG6n2191M= +github.com/grafana/grafana/pkg/semconv v0.0.0-20240808213237-f4d2e064f435 h1:SNEeqY22DrGr5E9kGF1mKSqlOom14W9+b1u4XEGJowA= +github.com/grafana/grafana/pkg/semconv v0.0.0-20240808213237-f4d2e064f435/go.mod h1:8cz+z0i57IjN6MYmu/zZQdCg9CQcsnEHbaJBBEf3KQo= github.com/grafana/grafana/pkg/storage/unified/resource v0.0.0-20240624122844-a89deaeb7365 h1:XRHqYGxjN2+/4QHPoOtr7kYTL9p2P5UxTXfnbiaO/NI= github.com/grafana/grafana/pkg/storage/unified/resource v0.0.0-20240624122844-a89deaeb7365/go.mod h1:X4dwV2eQI8z8G2aHXvhZZXu/y/rb3psQXuaZa66WZfA= github.com/grafana/grafana/pkg/util/xorm v0.0.1 h1:72QZjxWIWpSeOF8ob4aMV058kfgZyeetkAB8dmeti2o= @@ -4707,6 +4711,7 @@ k8s.io/code-generator v0.31.0/go.mod h1:84y4w3es8rOJOUUP1rLsIiGlO1JuEaPFXQPA9e/K k8s.io/component-base v0.31.0 h1:/KIzGM5EvPNQcYgwq5NwoQBaOlVFrghoVGr8lG6vNRs= k8s.io/component-base v0.31.0/go.mod h1:TYVuzI1QmN4L5ItVdMSXKvH7/DtvIuas5/mm8YT3rTo= k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 h1:NGrVE502P0s0/1hudf8zjgwki1X/TByhmAoILTarmzo= k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70/go.mod h1:VH3AT8AaQOqiGjMF9p0/IM1Dj+82ZwjfxUP1IxaHE+8= k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= diff --git a/hack/externalTools.go b/hack/externalTools.go index 5ccc03e363b..f6bf18b1ff1 100644 --- a/hack/externalTools.go +++ b/hack/externalTools.go @@ -3,5 +3,5 @@ package hack // this ensures that code-generator is available in the go.mod file, // which is a dependency of the ./update-codegen.sh script. import ( - _ "k8s.io/code-generator/pkg/util" + _ "k8s.io/code-generator/cmd/client-gen/generators" ) diff --git a/hack/openapi-codegen.sh b/hack/openapi-codegen.sh index 070966375dc..5b7c65a8cf9 100644 --- a/hack/openapi-codegen.sh +++ b/hack/openapi-codegen.sh @@ -45,38 +45,38 @@ function grafana::codegen::gen_openapi() { while [ "$#" -gt 0 ]; do case "$1" in - "--input-pkg-single") - in_pkg_single="$2" - shift 2 - ;; - "--include-common-input-dirs") - if [ "$2" == "true" ]; then - COMMON_INPUT_DIRS='--input-dirs "k8s.io/apimachinery/pkg/apis/meta/v1" --input-dirs "k8s.io/apimachinery/pkg/runtime" --input-dirs "k8s.io/apimachinery/pkg/version"' - else - COMMON_INPUT_DIRS="" - fi - shift 2 - ;; - "--output-base") - out_base="$2" - shift 2 - ;; - "--report-filename") - report="$2" - shift 2 - ;; - "--update-report") - update_report="true" - shift - ;; - "--boilerplate") - boilerplate="$2" - shift 2 - ;; - *) - echo "unknown argument: $1" >&2 - return 1 - ;; + "--input-pkg-single") + in_pkg_single="$2" + shift 2 + ;; + "--include-common-input-dirs") + if [ "$2" == "true" ]; then + COMMON_INPUT_DIRS='"k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/version"' + else + COMMON_INPUT_DIRS="" + fi + shift 2 + ;; + "--output-base") + out_base="$2" + shift 2 + ;; + "--report-filename") + report="$2" + shift 2 + ;; + "--update-report") + update_report="true" + shift + ;; + "--boilerplate") + boilerplate="$2" + shift 2 + ;; + *) + echo "unknown argument: $1" >&2 + return 1 + ;; esac done @@ -103,58 +103,57 @@ function grafana::codegen::gen_openapi() { openapi-gen ) # shellcheck disable=2046 # printf word-splitting is intentional - GO111MODULE=on go install $(printf "k8s.io/code-generator/cmd/%s " "${BINS[@]}") + GO111MODULE=on go install $(printf "k8s.io/kube-openapi/cmd/%s " "${BINS[@]}") ) # Go installs in $GOBIN if defined, and $GOPATH/bin otherwise gobin="${GOBIN:-$(go env GOPATH)/bin}" # These tools all assume out-dir == in-dir. - root="${out_base}/${in_pkg_single}" + root="${in_pkg_single}" mkdir -p "${root}" - root="$(cd "${root}" && pwd -P)" local input_pkgs=() while read -r dir; do pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)" input_pkgs+=("${pkg}") done < <( - ( kube::codegen::internal::git_grep -l --null \ - -e '+k8s:openapi-gen=' \ - ":(glob)${root}"/'**/*.go' \ - || true \ - ) | while read -r -d $'\0' F; do dirname "${F}"; done \ - | LC_ALL=C sort -u + ( + kube::codegen::internal::grep -l --null \ + -e '+k8s:openapi-gen=' \ + -r "${root}" \ + --include '*.go' || + true + ) | while read -r -d $'\0' F; do dirname "${F}"; done | + LC_ALL=C sort -u ) - - local new_report="" - if [ "${#input_pkgs[@]}" != 0 ]; then - echo "Generating openapi code for ${#input_pkgs[@]} targets" - - kube::codegen::internal::git_find -z \ - ":(glob)${root}"/'**/zz_generated.openapi.go' \ - | xargs -0 rm -f - - local inputs=() - for arg in "${input_pkgs[@]}"; do - inputs+=("--input-dirs" "$arg") - done - - new_report="${root}/${report}.tmp" - if [ -n "${update_report}" ]; then - new_report="${root}/${report}" - fi - - "${gobin}/openapi-gen" \ - -v "${v}" \ - -O zz_generated.openapi \ - --go-header-file "${boilerplate}" \ - --output-base "${out_base}" \ - --output-package "${in_pkg_single}" \ - --report-filename "${new_report}" \ - ${COMMON_INPUT_DIRS} \ - "${inputs[@]}" + local new_report="" + if [ "${#input_pkgs[@]}" == 0 ]; then + return 0 fi + echo "Generating openapi code for ${#input_pkgs[@]} targets" + + kube::codegen::internal::findz \ + "${root}" \ + -type f \ + -name zz_generated.openapi.go \ + | xargs -0 rm -f + + local new_report + new_report="$(mktemp -t "$(basename "$0").api_violations.XXXXXX")" + if [ -n "${update_report}" ]; then + new_report="${root}/${report}" + fi + + "${gobin}/openapi-gen" \ + -v "${v}" \ + --output-file zz_generated.openapi.go \ + --go-header-file "${boilerplate}" \ + --output-dir "${root}" \ + --output-pkg "${in_pkg_single}" \ + --report-filename "${new_report}" \ + ${COMMON_INPUT_DIRS} \ + "${input_pkgs[@]}" touch "${root}/${report}" # in case it doesn't exist yet if [[ -z "${new_report}" ]]; then @@ -169,6 +168,6 @@ function grafana::codegen::gen_openapi() { # if all goes well, remove the temporary reports if [ -z "${update_report}" ]; then - rm -f "${new_report}" + rm -f "${new_report}" fi } diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 9a982333f79..55dcaa5d05e 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -33,26 +33,27 @@ grafana::codegen:run() { include_common_input_dirs=$([[ ${api_pkg} == "common" ]] && echo "true" || echo "false") kube::codegen::gen_helpers \ - --input-pkg-root github.com/grafana/grafana/${generate_root}/apis/${api_pkg} \ - --output-base "${OUTDIR}" \ - --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" + --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \ + ${generate_root}/apis/${api_pkg} - for pkg_version in $(grafana:codegen:lsdirs ./${generate_root}/apis/${api_pkg}); do + for pkg_version in $(grafana:codegen:lsdirs ./${generate_root}/apis/${api_pkg}); do grafana::codegen::gen_openapi \ - --input-pkg-single github.com/grafana/grafana/${generate_root}/apis/${api_pkg}/${pkg_version} \ + --input-pkg-single ${generate_root}/apis/${api_pkg}/${pkg_version} \ --output-base "${OUTDIR}" \ --report-filename "${OPENAPI_VIOLATION_EXCEPTIONS_FILENAME}" \ --update-report \ --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \ --include-common-input-dirs ${include_common_input_dirs} - violations_file="${OUTDIR}/github.com/grafana/grafana/${generate_root}/apis/${api_pkg}/${pkg_version}/${OPENAPI_VIOLATION_EXCEPTIONS_FILENAME}" + violations_file="${generate_root}/apis/${api_pkg}/${pkg_version}/${OPENAPI_VIOLATION_EXCEPTIONS_FILENAME}" + if [ ! -f "${violations_file}" ]; then + continue + fi # delete violation exceptions file, if empty if ! grep -q . "${violations_file}"; then echo "Deleting ${violations_file} since it is empty" rm ${violations_file} fi - echo "" done done @@ -67,12 +68,12 @@ grafana::codegen:run() { echo "-------------------------" kube::codegen::gen_client \ - --with-watch \ - --with-applyconfig \ - --input-pkg-root github.com/grafana/grafana/${generate_root}/apis \ - --output-pkg-root github.com/grafana/grafana/${generate_root}/generated \ - --output-base "${OUTDIR}" \ - --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" + --with-watch \ + --with-applyconfig \ + --output-dir ${generate_root}/generated \ + --output-pkg github.com/grafana/grafana/${generate_root}/generated \ + --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \ + ${generate_root}/apis echo "" } @@ -83,5 +84,6 @@ grafana:codegen:lsdirs() { grafana::codegen:run pkg grafana::codegen:run pkg/apimachinery +grafana::codegen:run pkg/aggregator echo "done." diff --git a/pkg/aggregator/apis/aggregation/v0alpha1/zz_generated.openapi.go b/pkg/aggregator/apis/aggregation/v0alpha1/zz_generated.openapi.go index cd864d8edd5..da85a4c88d9 100644 --- a/pkg/aggregator/apis/aggregation/v0alpha1/zz_generated.openapi.go +++ b/pkg/aggregator/apis/aggregation/v0alpha1/zz_generated.openapi.go @@ -5,8 +5,6 @@ // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v0alpha1 import ( diff --git a/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservice.go b/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservice.go index b62f426821a..2145c74a719 100644 --- a/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservice.go +++ b/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservice.go @@ -10,7 +10,7 @@ import ( v1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// DataPlaneServiceApplyConfiguration represents an declarative configuration of the DataPlaneService type for use +// DataPlaneServiceApplyConfiguration represents a declarative configuration of the DataPlaneService type for use // with apply. type DataPlaneServiceApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` @@ -19,7 +19,7 @@ type DataPlaneServiceApplyConfiguration struct { Status *DataPlaneServiceStatusApplyConfiguration `json:"status,omitempty"` } -// DataPlaneService constructs an declarative configuration of the DataPlaneService type for use with +// DataPlaneService constructs a declarative configuration of the DataPlaneService type for use with // apply. func DataPlaneService(name string) *DataPlaneServiceApplyConfiguration { b := &DataPlaneServiceApplyConfiguration{} @@ -202,3 +202,9 @@ func (b *DataPlaneServiceApplyConfiguration) WithStatus(value *DataPlaneServiceS b.Status = value return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *DataPlaneServiceApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.Name +} diff --git a/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservicecondition.go b/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservicecondition.go index feaf7e123e5..e57d7d2f32a 100644 --- a/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservicecondition.go +++ b/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservicecondition.go @@ -9,7 +9,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// DataPlaneServiceConditionApplyConfiguration represents an declarative configuration of the DataPlaneServiceCondition type for use +// DataPlaneServiceConditionApplyConfiguration represents a declarative configuration of the DataPlaneServiceCondition type for use // with apply. type DataPlaneServiceConditionApplyConfiguration struct { Type *v0alpha1.DataPlaneServiceConditionType `json:"type,omitempty"` @@ -19,7 +19,7 @@ type DataPlaneServiceConditionApplyConfiguration struct { Message *string `json:"message,omitempty"` } -// DataPlaneServiceConditionApplyConfiguration constructs an declarative configuration of the DataPlaneServiceCondition type for use with +// DataPlaneServiceConditionApplyConfiguration constructs a declarative configuration of the DataPlaneServiceCondition type for use with // apply. func DataPlaneServiceCondition() *DataPlaneServiceConditionApplyConfiguration { return &DataPlaneServiceConditionApplyConfiguration{} diff --git a/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservicespec.go b/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservicespec.go index fdac3efd8c0..2323cfad365 100644 --- a/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservicespec.go +++ b/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservicespec.go @@ -8,7 +8,7 @@ import ( v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1" ) -// DataPlaneServiceSpecApplyConfiguration represents an declarative configuration of the DataPlaneServiceSpec type for use +// DataPlaneServiceSpecApplyConfiguration represents a declarative configuration of the DataPlaneServiceSpec type for use // with apply. type DataPlaneServiceSpecApplyConfiguration struct { PluginID *string `json:"pluginID,omitempty"` @@ -18,7 +18,7 @@ type DataPlaneServiceSpecApplyConfiguration struct { Services []ServiceApplyConfiguration `json:"services,omitempty"` } -// DataPlaneServiceSpecApplyConfiguration constructs an declarative configuration of the DataPlaneServiceSpec type for use with +// DataPlaneServiceSpecApplyConfiguration constructs a declarative configuration of the DataPlaneServiceSpec type for use with // apply. func DataPlaneServiceSpec() *DataPlaneServiceSpecApplyConfiguration { return &DataPlaneServiceSpecApplyConfiguration{} diff --git a/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservicestatus.go b/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservicestatus.go index ca6a99c259c..f8f21a662c1 100644 --- a/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservicestatus.go +++ b/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/dataplaneservicestatus.go @@ -4,13 +4,13 @@ package v0alpha1 -// DataPlaneServiceStatusApplyConfiguration represents an declarative configuration of the DataPlaneServiceStatus type for use +// DataPlaneServiceStatusApplyConfiguration represents a declarative configuration of the DataPlaneServiceStatus type for use // with apply. type DataPlaneServiceStatusApplyConfiguration struct { Conditions []DataPlaneServiceConditionApplyConfiguration `json:"conditions,omitempty"` } -// DataPlaneServiceStatusApplyConfiguration constructs an declarative configuration of the DataPlaneServiceStatus type for use with +// DataPlaneServiceStatusApplyConfiguration constructs a declarative configuration of the DataPlaneServiceStatus type for use with // apply. func DataPlaneServiceStatus() *DataPlaneServiceStatusApplyConfiguration { return &DataPlaneServiceStatusApplyConfiguration{} diff --git a/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/service.go b/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/service.go index a585f271dd6..d3461a50ee4 100644 --- a/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/service.go +++ b/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1/service.go @@ -8,7 +8,7 @@ import ( v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1" ) -// ServiceApplyConfiguration represents an declarative configuration of the Service type for use +// ServiceApplyConfiguration represents a declarative configuration of the Service type for use // with apply. type ServiceApplyConfiguration struct { Type *v0alpha1.ServiceType `json:"type,omitempty"` @@ -16,7 +16,7 @@ type ServiceApplyConfiguration struct { Path *string `json:"path,omitempty"` } -// ServiceApplyConfiguration constructs an declarative configuration of the Service type for use with +// ServiceApplyConfiguration constructs a declarative configuration of the Service type for use with // apply. func Service() *ServiceApplyConfiguration { return &ServiceApplyConfiguration{} diff --git a/pkg/aggregator/generated/applyconfiguration/utils.go b/pkg/aggregator/generated/applyconfiguration/utils.go index dd9c27d23ca..977a8848e75 100644 --- a/pkg/aggregator/generated/applyconfiguration/utils.go +++ b/pkg/aggregator/generated/applyconfiguration/utils.go @@ -7,7 +7,10 @@ package applyconfiguration import ( v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1" aggregationv0alpha1 "github.com/grafana/grafana/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1" + internal "github.com/grafana/grafana/pkg/aggregator/generated/applyconfiguration/internal" + runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" + testing "k8s.io/client-go/testing" ) // ForKind returns an apply configuration type for the given GroupVersionKind, or nil if no @@ -29,3 +32,7 @@ func ForKind(kind schema.GroupVersionKind) interface{} { } return nil } + +func NewTypeConverter(scheme *runtime.Scheme) *testing.TypeConverter { + return &testing.TypeConverter{Scheme: scheme, TypeResolver: internal.Parser()} +} diff --git a/pkg/aggregator/generated/clientset/versioned/fake/clientset_generated.go b/pkg/aggregator/generated/clientset/versioned/fake/clientset_generated.go index b0cc69a076e..afcfa74af25 100644 --- a/pkg/aggregator/generated/clientset/versioned/fake/clientset_generated.go +++ b/pkg/aggregator/generated/clientset/versioned/fake/clientset_generated.go @@ -5,6 +5,7 @@ package fake import ( + applyconfiguration "github.com/grafana/grafana/pkg/aggregator/generated/applyconfiguration" clientset "github.com/grafana/grafana/pkg/aggregator/generated/clientset/versioned" aggregationv0alpha1 "github.com/grafana/grafana/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1" fakeaggregationv0alpha1 "github.com/grafana/grafana/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1/fake" @@ -17,8 +18,12 @@ import ( // NewSimpleClientset returns a clientset that will respond with the provided objects. // It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement +// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement // for a real clientset and is mostly useful in simple unit tests. +// +// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves +// server side apply testing. NewClientset is only available when apply configurations are generated (e.g. +// via --with-applyconfig). func NewSimpleClientset(objects ...runtime.Object) *Clientset { o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) for _, obj := range objects { @@ -60,6 +65,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(), + applyconfiguration.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/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1/dataplaneservice.go b/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1/dataplaneservice.go index 311f6a77285..9c8ad21cf04 100644 --- a/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1/dataplaneservice.go +++ b/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1/dataplaneservice.go @@ -6,9 +6,6 @@ package v0alpha1 import ( "context" - json "encoding/json" - "fmt" - "time" v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1" aggregationv0alpha1 "github.com/grafana/grafana/pkg/aggregator/generated/applyconfiguration/aggregation/v0alpha1" @@ -16,7 +13,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // DataPlaneServicesGetter has a method to return a DataPlaneServiceInterface. @@ -29,6 +26,7 @@ type DataPlaneServicesGetter interface { type DataPlaneServiceInterface interface { Create(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.CreateOptions) (*v0alpha1.DataPlaneService, error) Update(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (*v0alpha1.DataPlaneService, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (*v0alpha1.DataPlaneService, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error @@ -37,193 +35,25 @@ type DataPlaneServiceInterface interface { 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 *v0alpha1.DataPlaneService, err error) Apply(ctx context.Context, dataPlaneService *aggregationv0alpha1.DataPlaneServiceApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.DataPlaneService, err error) + // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). ApplyStatus(ctx context.Context, dataPlaneService *aggregationv0alpha1.DataPlaneServiceApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.DataPlaneService, err error) DataPlaneServiceExpansion } // dataPlaneServices implements DataPlaneServiceInterface type dataPlaneServices struct { - client rest.Interface + *gentype.ClientWithListAndApply[*v0alpha1.DataPlaneService, *v0alpha1.DataPlaneServiceList, *aggregationv0alpha1.DataPlaneServiceApplyConfiguration] } // newDataPlaneServices returns a DataPlaneServices func newDataPlaneServices(c *AggregationV0alpha1Client) *dataPlaneServices { return &dataPlaneServices{ - client: c.RESTClient(), + gentype.NewClientWithListAndApply[*v0alpha1.DataPlaneService, *v0alpha1.DataPlaneServiceList, *aggregationv0alpha1.DataPlaneServiceApplyConfiguration]( + "dataplaneservices", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *v0alpha1.DataPlaneService { return &v0alpha1.DataPlaneService{} }, + func() *v0alpha1.DataPlaneServiceList { return &v0alpha1.DataPlaneServiceList{} }), } } - -// Get takes name of the dataPlaneService, and returns the corresponding dataPlaneService object, and an error if there is any. -func (c *dataPlaneServices) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.DataPlaneService, err error) { - result = &v0alpha1.DataPlaneService{} - err = c.client.Get(). - Resource("dataplaneservices"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of DataPlaneServices that match those selectors. -func (c *dataPlaneServices) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.DataPlaneServiceList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v0alpha1.DataPlaneServiceList{} - err = c.client.Get(). - Resource("dataplaneservices"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested dataPlaneServices. -func (c *dataPlaneServices) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Resource("dataplaneservices"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a dataPlaneService and creates it. Returns the server's representation of the dataPlaneService, and an error, if there is any. -func (c *dataPlaneServices) Create(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.CreateOptions) (result *v0alpha1.DataPlaneService, err error) { - result = &v0alpha1.DataPlaneService{} - err = c.client.Post(). - Resource("dataplaneservices"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(dataPlaneService). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a dataPlaneService and updates it. Returns the server's representation of the dataPlaneService, and an error, if there is any. -func (c *dataPlaneServices) Update(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (result *v0alpha1.DataPlaneService, err error) { - result = &v0alpha1.DataPlaneService{} - err = c.client.Put(). - Resource("dataplaneservices"). - Name(dataPlaneService.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(dataPlaneService). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *dataPlaneServices) UpdateStatus(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (result *v0alpha1.DataPlaneService, err error) { - result = &v0alpha1.DataPlaneService{} - err = c.client.Put(). - Resource("dataplaneservices"). - Name(dataPlaneService.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(dataPlaneService). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the dataPlaneService and deletes it. Returns an error if one occurs. -func (c *dataPlaneServices) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Resource("dataplaneservices"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *dataPlaneServices) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Resource("dataplaneservices"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched dataPlaneService. -func (c *dataPlaneServices) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.DataPlaneService, err error) { - result = &v0alpha1.DataPlaneService{} - err = c.client.Patch(pt). - Resource("dataplaneservices"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied dataPlaneService. -func (c *dataPlaneServices) Apply(ctx context.Context, dataPlaneService *aggregationv0alpha1.DataPlaneServiceApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.DataPlaneService, err error) { - if dataPlaneService == nil { - return nil, fmt.Errorf("dataPlaneService provided to Apply must not be nil") - } - patchOpts := opts.ToPatchOptions() - data, err := json.Marshal(dataPlaneService) - if err != nil { - return nil, err - } - name := dataPlaneService.Name - if name == nil { - return nil, fmt.Errorf("dataPlaneService.Name must be provided to Apply") - } - result = &v0alpha1.DataPlaneService{} - err = c.client.Patch(types.ApplyPatchType). - Resource("dataplaneservices"). - Name(*name). - VersionedParams(&patchOpts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *dataPlaneServices) ApplyStatus(ctx context.Context, dataPlaneService *aggregationv0alpha1.DataPlaneServiceApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.DataPlaneService, err error) { - if dataPlaneService == nil { - return nil, fmt.Errorf("dataPlaneService provided to Apply must not be nil") - } - patchOpts := opts.ToPatchOptions() - data, err := json.Marshal(dataPlaneService) - if err != nil { - return nil, err - } - - name := dataPlaneService.Name - if name == nil { - return nil, fmt.Errorf("dataPlaneService.Name must be provided to Apply") - } - - result = &v0alpha1.DataPlaneService{} - err = c.client.Patch(types.ApplyPatchType). - Resource("dataplaneservices"). - Name(*name). - SubResource("status"). - VersionedParams(&patchOpts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1/fake/fake_dataplaneservice.go b/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1/fake/fake_dataplaneservice.go index 0c323038118..779b0aaa13b 100644 --- a/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1/fake/fake_dataplaneservice.go +++ b/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1/fake/fake_dataplaneservice.go @@ -29,20 +29,22 @@ var dataplaneservicesKind = v0alpha1.SchemeGroupVersion.WithKind("DataPlaneServi // Get takes name of the dataPlaneService, and returns the corresponding dataPlaneService object, and an error if there is any. func (c *FakeDataPlaneServices) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.DataPlaneService, err error) { + emptyResult := &v0alpha1.DataPlaneService{} obj, err := c.Fake. - Invokes(testing.NewRootGetAction(dataplaneservicesResource, name), &v0alpha1.DataPlaneService{}) + Invokes(testing.NewRootGetActionWithOptions(dataplaneservicesResource, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v0alpha1.DataPlaneService), err } // List takes label and field selectors, and returns the list of DataPlaneServices that match those selectors. func (c *FakeDataPlaneServices) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.DataPlaneServiceList, err error) { + emptyResult := &v0alpha1.DataPlaneServiceList{} obj, err := c.Fake. - Invokes(testing.NewRootListAction(dataplaneservicesResource, dataplaneservicesKind, opts), &v0alpha1.DataPlaneServiceList{}) + Invokes(testing.NewRootListActionWithOptions(dataplaneservicesResource, dataplaneservicesKind, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -61,36 +63,39 @@ func (c *FakeDataPlaneServices) List(ctx context.Context, opts v1.ListOptions) ( // Watch returns a watch.Interface that watches the requested dataPlaneServices. func (c *FakeDataPlaneServices) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewRootWatchAction(dataplaneservicesResource, opts)) + InvokesWatch(testing.NewRootWatchActionWithOptions(dataplaneservicesResource, opts)) } // Create takes the representation of a dataPlaneService and creates it. Returns the server's representation of the dataPlaneService, and an error, if there is any. func (c *FakeDataPlaneServices) Create(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.CreateOptions) (result *v0alpha1.DataPlaneService, err error) { + emptyResult := &v0alpha1.DataPlaneService{} obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(dataplaneservicesResource, dataPlaneService), &v0alpha1.DataPlaneService{}) + Invokes(testing.NewRootCreateActionWithOptions(dataplaneservicesResource, dataPlaneService, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v0alpha1.DataPlaneService), err } // Update takes the representation of a dataPlaneService and updates it. Returns the server's representation of the dataPlaneService, and an error, if there is any. func (c *FakeDataPlaneServices) Update(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (result *v0alpha1.DataPlaneService, err error) { + emptyResult := &v0alpha1.DataPlaneService{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(dataplaneservicesResource, dataPlaneService), &v0alpha1.DataPlaneService{}) + Invokes(testing.NewRootUpdateActionWithOptions(dataplaneservicesResource, dataPlaneService, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v0alpha1.DataPlaneService), err } // UpdateStatus was generated because the type contains a Status member. // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeDataPlaneServices) UpdateStatus(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (*v0alpha1.DataPlaneService, error) { +func (c *FakeDataPlaneServices) UpdateStatus(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (result *v0alpha1.DataPlaneService, err error) { + emptyResult := &v0alpha1.DataPlaneService{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(dataplaneservicesResource, "status", dataPlaneService), &v0alpha1.DataPlaneService{}) + Invokes(testing.NewRootUpdateSubresourceActionWithOptions(dataplaneservicesResource, "status", dataPlaneService, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v0alpha1.DataPlaneService), err } @@ -104,7 +109,7 @@ func (c *FakeDataPlaneServices) Delete(ctx context.Context, name string, opts v1 // DeleteCollection deletes a collection of objects. func (c *FakeDataPlaneServices) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(dataplaneservicesResource, listOpts) + action := testing.NewRootDeleteCollectionActionWithOptions(dataplaneservicesResource, opts, listOpts) _, err := c.Fake.Invokes(action, &v0alpha1.DataPlaneServiceList{}) return err @@ -112,10 +117,11 @@ func (c *FakeDataPlaneServices) DeleteCollection(ctx context.Context, opts v1.De // Patch applies the patch and returns the patched dataPlaneService. func (c *FakeDataPlaneServices) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.DataPlaneService, err error) { + emptyResult := &v0alpha1.DataPlaneService{} obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(dataplaneservicesResource, name, pt, data, subresources...), &v0alpha1.DataPlaneService{}) + Invokes(testing.NewRootPatchSubresourceActionWithOptions(dataplaneservicesResource, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v0alpha1.DataPlaneService), err } @@ -133,10 +139,11 @@ func (c *FakeDataPlaneServices) Apply(ctx context.Context, dataPlaneService *agg if name == nil { return nil, fmt.Errorf("dataPlaneService.Name must be provided to Apply") } + emptyResult := &v0alpha1.DataPlaneService{} obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(dataplaneservicesResource, *name, types.ApplyPatchType, data), &v0alpha1.DataPlaneService{}) + Invokes(testing.NewRootPatchSubresourceActionWithOptions(dataplaneservicesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v0alpha1.DataPlaneService), err } @@ -155,10 +162,11 @@ func (c *FakeDataPlaneServices) ApplyStatus(ctx context.Context, dataPlaneServic if name == nil { return nil, fmt.Errorf("dataPlaneService.Name must be provided to Apply") } + emptyResult := &v0alpha1.DataPlaneService{} obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(dataplaneservicesResource, *name, types.ApplyPatchType, data, "status"), &v0alpha1.DataPlaneService{}) + Invokes(testing.NewRootPatchSubresourceActionWithOptions(dataplaneservicesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v0alpha1.DataPlaneService), err } diff --git a/pkg/aggregator/generated/informers/externalversions/factory.go b/pkg/aggregator/generated/informers/externalversions/factory.go index 300863eaae0..ccb035b90e2 100644 --- a/pkg/aggregator/generated/informers/externalversions/factory.go +++ b/pkg/aggregator/generated/informers/externalversions/factory.go @@ -214,6 +214,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 diff --git a/pkg/aggregator/generated/listers/aggregation/v0alpha1/dataplaneservice.go b/pkg/aggregator/generated/listers/aggregation/v0alpha1/dataplaneservice.go index c54c7ba6fc1..98f56d09222 100644 --- a/pkg/aggregator/generated/listers/aggregation/v0alpha1/dataplaneservice.go +++ b/pkg/aggregator/generated/listers/aggregation/v0alpha1/dataplaneservice.go @@ -6,8 +6,8 @@ package v0alpha1 import ( v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -25,30 +25,10 @@ type DataPlaneServiceLister interface { // dataPlaneServiceLister implements the DataPlaneServiceLister interface. type dataPlaneServiceLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v0alpha1.DataPlaneService] } // NewDataPlaneServiceLister returns a new DataPlaneServiceLister. func NewDataPlaneServiceLister(indexer cache.Indexer) DataPlaneServiceLister { - return &dataPlaneServiceLister{indexer: indexer} -} - -// List lists all DataPlaneServices in the indexer. -func (s *dataPlaneServiceLister) List(selector labels.Selector) (ret []*v0alpha1.DataPlaneService, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v0alpha1.DataPlaneService)) - }) - return ret, err -} - -// Get retrieves the DataPlaneService from the index for a given name. -func (s *dataPlaneServiceLister) Get(name string) (*v0alpha1.DataPlaneService, error) { - obj, exists, err := s.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v0alpha1.Resource("dataplaneservice"), name) - } - return obj.(*v0alpha1.DataPlaneService), nil + return &dataPlaneServiceLister{listers.New[*v0alpha1.DataPlaneService](indexer, v0alpha1.Resource("dataplaneservice"))} } diff --git a/pkg/apis/dashboard/v0alpha1/zz_generated.openapi.go b/pkg/apis/dashboard/v0alpha1/zz_generated.openapi.go index 330f7dd1255..5b43ab61377 100644 --- a/pkg/apis/dashboard/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/dashboard/v0alpha1/zz_generated.openapi.go @@ -5,8 +5,6 @@ // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v0alpha1 import ( @@ -21,9 +19,6 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.Dashboard": schema_pkg_apis_dashboard_v0alpha1_Dashboard(ref), "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardAccess": schema_pkg_apis_dashboard_v0alpha1_DashboardAccess(ref), "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardList": schema_pkg_apis_dashboard_v0alpha1_DashboardList(ref), - "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummary": schema_pkg_apis_dashboard_v0alpha1_DashboardSummary(ref), - "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummaryList": schema_pkg_apis_dashboard_v0alpha1_DashboardSummaryList(ref), - "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummarySpec": schema_pkg_apis_dashboard_v0alpha1_DashboardSummarySpec(ref), "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardVersionInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardVersionInfo(ref), "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardVersionList": schema_pkg_apis_dashboard_v0alpha1_DashboardVersionList(ref), "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardWithAccessInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardWithAccessInfo(ref), @@ -251,128 +246,6 @@ func schema_pkg_apis_dashboard_v0alpha1_DashboardList(ref common.ReferenceCallba } } -func schema_pkg_apis_dashboard_v0alpha1_DashboardSummary(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), - }, - }, - "spec": { - SchemaProps: spec.SchemaProps{ - Description: "The dashboard body", - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummarySpec"), - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummarySpec", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, - } -} - -func schema_pkg_apis_dashboard_v0alpha1_DashboardSummaryList(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), - }, - }, - "items": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, - Ref: ref("github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummary"), - }, - }, - }, - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardSummary", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, - } -} - -func schema_pkg_apis_dashboard_v0alpha1_DashboardSummarySpec(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "title": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - "tags": { - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - }, - Required: []string{"title"}, - }, - }, - } -} - func schema_pkg_apis_dashboard_v0alpha1_DashboardVersionInfo(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/pkg/apis/dashboard/v0alpha1/zz_generated.openapi_violation_exceptions.list b/pkg/apis/dashboard/v0alpha1/zz_generated.openapi_violation_exceptions.list deleted file mode 100644 index 1428ccea7ae..00000000000 --- a/pkg/apis/dashboard/v0alpha1/zz_generated.openapi_violation_exceptions.list +++ /dev/null @@ -1 +0,0 @@ -API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1,DashboardSummarySpec,Tags diff --git a/pkg/apis/dashboardsnapshot/v0alpha1/zz_generated.openapi.go b/pkg/apis/dashboardsnapshot/v0alpha1/zz_generated.openapi.go index 7566695cfaa..cd739258ef8 100644 --- a/pkg/apis/dashboardsnapshot/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/dashboardsnapshot/v0alpha1/zz_generated.openapi.go @@ -5,8 +5,6 @@ // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v0alpha1 import ( diff --git a/pkg/apis/datasource/v0alpha1/zz_generated.openapi.go b/pkg/apis/datasource/v0alpha1/zz_generated.openapi.go index 5a0f971e3d6..a590af21d4f 100644 --- a/pkg/apis/datasource/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/datasource/v0alpha1/zz_generated.openapi.go @@ -5,8 +5,6 @@ // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v0alpha1 import ( diff --git a/pkg/apis/featuretoggle/v0alpha1/zz_generated.openapi.go b/pkg/apis/featuretoggle/v0alpha1/zz_generated.openapi.go index a7817ad4248..0e84f57d84b 100644 --- a/pkg/apis/featuretoggle/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/featuretoggle/v0alpha1/zz_generated.openapi.go @@ -5,8 +5,6 @@ // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v0alpha1 import ( @@ -192,6 +190,13 @@ func schema_pkg_apis_featuretoggle_v0alpha1_FeatureSpec(ref common.ReferenceCall Format: "", }, }, + "expression": { + SchemaProps: spec.SchemaProps{ + Description: "Expression to determine if the flag is enabled by default", + Type: []string{"string"}, + Format: "", + }, + }, }, Required: []string{"description", "stage"}, }, diff --git a/pkg/apis/folder/v0alpha1/zz_generated.openapi.go b/pkg/apis/folder/v0alpha1/zz_generated.openapi.go index 71d03fb914d..9d8466e178c 100644 --- a/pkg/apis/folder/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/folder/v0alpha1/zz_generated.openapi.go @@ -5,8 +5,6 @@ // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v0alpha1 import ( diff --git a/pkg/apis/peakq/v0alpha1/zz_generated.openapi.go b/pkg/apis/peakq/v0alpha1/zz_generated.openapi.go index 42bdb435e50..adb1e72521e 100644 --- a/pkg/apis/peakq/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/peakq/v0alpha1/zz_generated.openapi.go @@ -5,8 +5,6 @@ // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v0alpha1 import ( diff --git a/pkg/apis/playlist/v0alpha1/zz_generated.openapi.go b/pkg/apis/playlist/v0alpha1/zz_generated.openapi.go index 534cc7312dd..6c66706772f 100644 --- a/pkg/apis/playlist/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/playlist/v0alpha1/zz_generated.openapi.go @@ -5,8 +5,6 @@ // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v0alpha1 import ( diff --git a/pkg/apis/query/v0alpha1/zz_generated.openapi.go b/pkg/apis/query/v0alpha1/zz_generated.openapi.go index 94065764f1e..fafe2ffc26e 100644 --- a/pkg/apis/query/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/query/v0alpha1/zz_generated.openapi.go @@ -5,8 +5,6 @@ // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v0alpha1 import ( diff --git a/pkg/apis/scope/v0alpha1/zz_generated.openapi.go b/pkg/apis/scope/v0alpha1/zz_generated.openapi.go index 4f081df925e..1bcc51f93a4 100644 --- a/pkg/apis/scope/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/scope/v0alpha1/zz_generated.openapi.go @@ -5,8 +5,6 @@ // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v0alpha1 import ( diff --git a/pkg/apis/service/v0alpha1/zz_generated.openapi.go b/pkg/apis/service/v0alpha1/zz_generated.openapi.go index bf951cc52c2..0ff30a12b36 100644 --- a/pkg/apis/service/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/service/v0alpha1/zz_generated.openapi.go @@ -5,8 +5,6 @@ // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v0alpha1 import ( diff --git a/pkg/generated/applyconfiguration/service/v0alpha1/externalname.go b/pkg/generated/applyconfiguration/service/v0alpha1/externalname.go index 7bf2af7bcea..81f48884fdf 100644 --- a/pkg/generated/applyconfiguration/service/v0alpha1/externalname.go +++ b/pkg/generated/applyconfiguration/service/v0alpha1/externalname.go @@ -10,7 +10,7 @@ import ( v1 "k8s.io/client-go/applyconfigurations/meta/v1" ) -// ExternalNameApplyConfiguration represents an declarative configuration of the ExternalName type for use +// ExternalNameApplyConfiguration represents a declarative configuration of the ExternalName type for use // with apply. type ExternalNameApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` @@ -18,7 +18,7 @@ type ExternalNameApplyConfiguration struct { Spec *ExternalNameSpecApplyConfiguration `json:"spec,omitempty"` } -// ExternalName constructs an declarative configuration of the ExternalName type for use with +// ExternalName constructs a declarative configuration of the ExternalName type for use with // apply. func ExternalName(name, namespace string) *ExternalNameApplyConfiguration { b := &ExternalNameApplyConfiguration{} @@ -194,3 +194,9 @@ func (b *ExternalNameApplyConfiguration) WithSpec(value *ExternalNameSpecApplyCo b.Spec = value return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *ExternalNameApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.Name +} diff --git a/pkg/generated/applyconfiguration/service/v0alpha1/externalnamespec.go b/pkg/generated/applyconfiguration/service/v0alpha1/externalnamespec.go index d172862ddb1..4791d8d45bf 100644 --- a/pkg/generated/applyconfiguration/service/v0alpha1/externalnamespec.go +++ b/pkg/generated/applyconfiguration/service/v0alpha1/externalnamespec.go @@ -4,13 +4,13 @@ package v0alpha1 -// ExternalNameSpecApplyConfiguration represents an declarative configuration of the ExternalNameSpec type for use +// ExternalNameSpecApplyConfiguration represents a declarative configuration of the ExternalNameSpec type for use // with apply. type ExternalNameSpecApplyConfiguration struct { Host *string `json:"host,omitempty"` } -// ExternalNameSpecApplyConfiguration constructs an declarative configuration of the ExternalNameSpec type for use with +// ExternalNameSpecApplyConfiguration constructs a declarative configuration of the ExternalNameSpec type for use with // apply. func ExternalNameSpec() *ExternalNameSpecApplyConfiguration { return &ExternalNameSpecApplyConfiguration{} diff --git a/pkg/generated/applyconfiguration/utils.go b/pkg/generated/applyconfiguration/utils.go index 19f42b751e2..55ac136e4fc 100644 --- a/pkg/generated/applyconfiguration/utils.go +++ b/pkg/generated/applyconfiguration/utils.go @@ -8,8 +8,11 @@ import ( v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" servicev0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1" alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1" + internal "github.com/grafana/grafana/pkg/generated/applyconfiguration/internal" applyconfigurationservicev0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/service/v0alpha1" + runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" + testing "k8s.io/client-go/testing" ) // ForKind returns an apply configuration type for the given GroupVersionKind, or nil if no @@ -41,3 +44,7 @@ func ForKind(kind schema.GroupVersionKind) interface{} { } return nil } + +func NewTypeConverter(scheme *runtime.Scheme) *testing.TypeConverter { + return &testing.TypeConverter{Scheme: scheme, TypeResolver: internal.Parser()} +} diff --git a/pkg/generated/clientset/versioned/fake/clientset_generated.go b/pkg/generated/clientset/versioned/fake/clientset_generated.go index 5b7771eb90a..8fb5f797700 100644 --- a/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -5,6 +5,7 @@ package fake import ( + applyconfiguration "github.com/grafana/grafana/pkg/generated/applyconfiguration" clientset "github.com/grafana/grafana/pkg/generated/clientset/versioned" notificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1" fakenotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1/fake" @@ -19,8 +20,12 @@ import ( // NewSimpleClientset returns a clientset that will respond with the provided objects. // It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement +// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement // for a real clientset and is mostly useful in simple unit tests. +// +// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves +// server side apply testing. NewClientset is only available when apply configurations are generated (e.g. +// via --with-applyconfig). func NewSimpleClientset(objects ...runtime.Object) *Clientset { o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) for _, obj := range objects { @@ -62,6 +67,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(), + applyconfiguration.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/pkg/generated/clientset/versioned/typed/service/v0alpha1/externalname.go b/pkg/generated/clientset/versioned/typed/service/v0alpha1/externalname.go index 04c348e53c1..bdaeec2dd81 100644 --- a/pkg/generated/clientset/versioned/typed/service/v0alpha1/externalname.go +++ b/pkg/generated/clientset/versioned/typed/service/v0alpha1/externalname.go @@ -6,9 +6,6 @@ package v0alpha1 import ( "context" - json "encoding/json" - "fmt" - "time" v0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1" servicev0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/service/v0alpha1" @@ -16,7 +13,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // ExternalNamesGetter has a method to return a ExternalNameInterface. @@ -41,154 +38,18 @@ type ExternalNameInterface interface { // externalNames implements ExternalNameInterface type externalNames struct { - client rest.Interface - ns string + *gentype.ClientWithListAndApply[*v0alpha1.ExternalName, *v0alpha1.ExternalNameList, *servicev0alpha1.ExternalNameApplyConfiguration] } // newExternalNames returns a ExternalNames func newExternalNames(c *ServiceV0alpha1Client, namespace string) *externalNames { return &externalNames{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithListAndApply[*v0alpha1.ExternalName, *v0alpha1.ExternalNameList, *servicev0alpha1.ExternalNameApplyConfiguration]( + "externalnames", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v0alpha1.ExternalName { return &v0alpha1.ExternalName{} }, + func() *v0alpha1.ExternalNameList { return &v0alpha1.ExternalNameList{} }), } } - -// Get takes name of the externalName, and returns the corresponding externalName object, and an error if there is any. -func (c *externalNames) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.ExternalName, err error) { - result = &v0alpha1.ExternalName{} - err = c.client.Get(). - Namespace(c.ns). - Resource("externalnames"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ExternalNames that match those selectors. -func (c *externalNames) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.ExternalNameList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v0alpha1.ExternalNameList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("externalnames"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested externalNames. -func (c *externalNames) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("externalnames"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a externalName and creates it. Returns the server's representation of the externalName, and an error, if there is any. -func (c *externalNames) Create(ctx context.Context, externalName *v0alpha1.ExternalName, opts v1.CreateOptions) (result *v0alpha1.ExternalName, err error) { - result = &v0alpha1.ExternalName{} - err = c.client.Post(). - Namespace(c.ns). - Resource("externalnames"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(externalName). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a externalName and updates it. Returns the server's representation of the externalName, and an error, if there is any. -func (c *externalNames) Update(ctx context.Context, externalName *v0alpha1.ExternalName, opts v1.UpdateOptions) (result *v0alpha1.ExternalName, err error) { - result = &v0alpha1.ExternalName{} - err = c.client.Put(). - Namespace(c.ns). - Resource("externalnames"). - Name(externalName.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(externalName). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the externalName and deletes it. Returns an error if one occurs. -func (c *externalNames) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("externalnames"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *externalNames) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("externalnames"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched externalName. -func (c *externalNames) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.ExternalName, err error) { - result = &v0alpha1.ExternalName{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("externalnames"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied externalName. -func (c *externalNames) Apply(ctx context.Context, externalName *servicev0alpha1.ExternalNameApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.ExternalName, err error) { - if externalName == nil { - return nil, fmt.Errorf("externalName provided to Apply must not be nil") - } - patchOpts := opts.ToPatchOptions() - data, err := json.Marshal(externalName) - if err != nil { - return nil, err - } - name := externalName.Name - if name == nil { - return nil, fmt.Errorf("externalName.Name must be provided to Apply") - } - result = &v0alpha1.ExternalName{} - err = c.client.Patch(types.ApplyPatchType). - Namespace(c.ns). - Resource("externalnames"). - Name(*name). - VersionedParams(&patchOpts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/generated/clientset/versioned/typed/service/v0alpha1/fake/fake_externalname.go b/pkg/generated/clientset/versioned/typed/service/v0alpha1/fake/fake_externalname.go index b3f0bacb493..4191fe506ef 100644 --- a/pkg/generated/clientset/versioned/typed/service/v0alpha1/fake/fake_externalname.go +++ b/pkg/generated/clientset/versioned/typed/service/v0alpha1/fake/fake_externalname.go @@ -30,22 +30,24 @@ var externalnamesKind = v0alpha1.SchemeGroupVersion.WithKind("ExternalName") // Get takes name of the externalName, and returns the corresponding externalName object, and an error if there is any. func (c *FakeExternalNames) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.ExternalName, err error) { + emptyResult := &v0alpha1.ExternalName{} obj, err := c.Fake. - Invokes(testing.NewGetAction(externalnamesResource, c.ns, name), &v0alpha1.ExternalName{}) + Invokes(testing.NewGetActionWithOptions(externalnamesResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v0alpha1.ExternalName), err } // List takes label and field selectors, and returns the list of ExternalNames that match those selectors. func (c *FakeExternalNames) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.ExternalNameList, err error) { + emptyResult := &v0alpha1.ExternalNameList{} obj, err := c.Fake. - Invokes(testing.NewListAction(externalnamesResource, externalnamesKind, c.ns, opts), &v0alpha1.ExternalNameList{}) + Invokes(testing.NewListActionWithOptions(externalnamesResource, externalnamesKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -64,28 +66,30 @@ func (c *FakeExternalNames) List(ctx context.Context, opts v1.ListOptions) (resu // Watch returns a watch.Interface that watches the requested externalNames. func (c *FakeExternalNames) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(externalnamesResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(externalnamesResource, c.ns, opts)) } // Create takes the representation of a externalName and creates it. Returns the server's representation of the externalName, and an error, if there is any. func (c *FakeExternalNames) Create(ctx context.Context, externalName *v0alpha1.ExternalName, opts v1.CreateOptions) (result *v0alpha1.ExternalName, err error) { + emptyResult := &v0alpha1.ExternalName{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(externalnamesResource, c.ns, externalName), &v0alpha1.ExternalName{}) + Invokes(testing.NewCreateActionWithOptions(externalnamesResource, c.ns, externalName, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v0alpha1.ExternalName), err } // Update takes the representation of a externalName and updates it. Returns the server's representation of the externalName, and an error, if there is any. func (c *FakeExternalNames) Update(ctx context.Context, externalName *v0alpha1.ExternalName, opts v1.UpdateOptions) (result *v0alpha1.ExternalName, err error) { + emptyResult := &v0alpha1.ExternalName{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(externalnamesResource, c.ns, externalName), &v0alpha1.ExternalName{}) + Invokes(testing.NewUpdateActionWithOptions(externalnamesResource, c.ns, externalName, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v0alpha1.ExternalName), err } @@ -100,7 +104,7 @@ func (c *FakeExternalNames) Delete(ctx context.Context, name string, opts v1.Del // DeleteCollection deletes a collection of objects. func (c *FakeExternalNames) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(externalnamesResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(externalnamesResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v0alpha1.ExternalNameList{}) return err @@ -108,11 +112,12 @@ func (c *FakeExternalNames) DeleteCollection(ctx context.Context, opts v1.Delete // Patch applies the patch and returns the patched externalName. func (c *FakeExternalNames) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.ExternalName, err error) { + emptyResult := &v0alpha1.ExternalName{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(externalnamesResource, c.ns, name, pt, data, subresources...), &v0alpha1.ExternalName{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(externalnamesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v0alpha1.ExternalName), err } @@ -130,11 +135,12 @@ func (c *FakeExternalNames) Apply(ctx context.Context, externalName *servicev0al if name == nil { return nil, fmt.Errorf("externalName.Name must be provided to Apply") } + emptyResult := &v0alpha1.ExternalName{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(externalnamesResource, c.ns, *name, types.ApplyPatchType, data), &v0alpha1.ExternalName{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(externalnamesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v0alpha1.ExternalName), err } diff --git a/pkg/generated/informers/externalversions/factory.go b/pkg/generated/informers/externalversions/factory.go index 1c28112c022..cc5cf674386 100644 --- a/pkg/generated/informers/externalversions/factory.go +++ b/pkg/generated/informers/externalversions/factory.go @@ -215,6 +215,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 diff --git a/pkg/generated/listers/service/v0alpha1/externalname.go b/pkg/generated/listers/service/v0alpha1/externalname.go index 89cc8e425f4..43a296498eb 100644 --- a/pkg/generated/listers/service/v0alpha1/externalname.go +++ b/pkg/generated/listers/service/v0alpha1/externalname.go @@ -6,8 +6,8 @@ package v0alpha1 import ( v0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -24,25 +24,17 @@ type ExternalNameLister interface { // externalNameLister implements the ExternalNameLister interface. type externalNameLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v0alpha1.ExternalName] } // NewExternalNameLister returns a new ExternalNameLister. func NewExternalNameLister(indexer cache.Indexer) ExternalNameLister { - return &externalNameLister{indexer: indexer} -} - -// List lists all ExternalNames in the indexer. -func (s *externalNameLister) List(selector labels.Selector) (ret []*v0alpha1.ExternalName, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v0alpha1.ExternalName)) - }) - return ret, err + return &externalNameLister{listers.New[*v0alpha1.ExternalName](indexer, v0alpha1.Resource("externalname"))} } // ExternalNames returns an object that can list and get ExternalNames. func (s *externalNameLister) ExternalNames(namespace string) ExternalNameNamespaceLister { - return externalNameNamespaceLister{indexer: s.indexer, namespace: namespace} + return externalNameNamespaceLister{listers.NewNamespaced[*v0alpha1.ExternalName](s.ResourceIndexer, namespace)} } // ExternalNameNamespaceLister helps list and get ExternalNames. @@ -60,26 +52,5 @@ type ExternalNameNamespaceLister interface { // externalNameNamespaceLister implements the ExternalNameNamespaceLister // interface. type externalNameNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all ExternalNames in the indexer for a given namespace. -func (s externalNameNamespaceLister) List(selector labels.Selector) (ret []*v0alpha1.ExternalName, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v0alpha1.ExternalName)) - }) - return ret, err -} - -// Get retrieves the ExternalName from the indexer for a given namespace and name. -func (s externalNameNamespaceLister) Get(name string) (*v0alpha1.ExternalName, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v0alpha1.Resource("externalname"), name) - } - return obj.(*v0alpha1.ExternalName), nil + listers.ResourceIndexer[*v0alpha1.ExternalName] }