K8s: Fix hack/update-codegen (#91867)

This commit is contained in:
Todd Treece 2024-08-14 01:17:05 -04:00 committed by GitHub
parent e90b272299
commit dacf11b048
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
36 changed files with 296 additions and 670 deletions

5
go.mod
View File

@ -90,7 +90,8 @@ require (
github.com/grafana/grafana-google-sdk-go v0.1.0 // @grafana/partner-datasources 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-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-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 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 // This needs to be here for other projects that import grafana/grafana
// For local development grafana/grafana will always use the local files // For local development grafana/grafana will always use the local files
@ -481,8 +482,10 @@ require (
) )
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/hairyhenderson/go-which v0.2.0 // indirect
github.com/iancoleman/orderedmap v0.3.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 // Use fork of crewjam/saml with fixes for some issues until changes get merged into upstream

9
go.sum
View File

@ -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.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 h1:zBcSW9xV9gA9hD8UN+HjJtD7tESMZcaQhA1BI76MTxM=
github.com/grafana/grafana-plugin-sdk-go v0.241.0/go.mod h1:2HjNwzGCfaFAyR2HGoECTwAmq8vSIn2L1/1yOt4XRS4= 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/aggregator v0.0.0-20240813192817-1b0e6b5c09b2 h1:2H9x4q53pkfUGtSNYD1qSBpNnxrFgylof/TYADb5xMI=
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/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 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/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 h1:FuRyHMIgVVXkLuJnCflNfk3gqJflmyiI+/ZuJ9MoAfY=
github.com/grafana/grafana/pkg/promlib v0.0.6/go.mod h1:shFkrG1fQ/PPNRGhxAPNMLp0SAeG/jhqaLoG6n2191M= 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 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/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= 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 h1:/KIzGM5EvPNQcYgwq5NwoQBaOlVFrghoVGr8lG6vNRs=
k8s.io/component-base v0.31.0/go.mod h1:TYVuzI1QmN4L5ItVdMSXKvH7/DtvIuas5/mm8YT3rTo= 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 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/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 v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=

View File

@ -3,5 +3,5 @@ package hack
// this ensures that code-generator is available in the go.mod file, // this ensures that code-generator is available in the go.mod file,
// which is a dependency of the ./update-codegen.sh script. // which is a dependency of the ./update-codegen.sh script.
import ( import (
_ "k8s.io/code-generator/pkg/util" _ "k8s.io/code-generator/cmd/client-gen/generators"
) )

View File

@ -51,7 +51,7 @@ function grafana::codegen::gen_openapi() {
;; ;;
"--include-common-input-dirs") "--include-common-input-dirs")
if [ "$2" == "true" ]; then 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"' COMMON_INPUT_DIRS='"k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/version"'
else else
COMMON_INPUT_DIRS="" COMMON_INPUT_DIRS=""
fi fi
@ -103,58 +103,57 @@ function grafana::codegen::gen_openapi() {
openapi-gen openapi-gen
) )
# shellcheck disable=2046 # printf word-splitting is intentional # 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 # Go installs in $GOBIN if defined, and $GOPATH/bin otherwise
gobin="${GOBIN:-$(go env GOPATH)/bin}" gobin="${GOBIN:-$(go env GOPATH)/bin}"
# These tools all assume out-dir == in-dir. # These tools all assume out-dir == in-dir.
root="${out_base}/${in_pkg_single}" root="${in_pkg_single}"
mkdir -p "${root}" mkdir -p "${root}"
root="$(cd "${root}" && pwd -P)"
local input_pkgs=() local input_pkgs=()
while read -r dir; do while read -r dir; do
pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)" pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)"
input_pkgs+=("${pkg}") input_pkgs+=("${pkg}")
done < <( done < <(
( kube::codegen::internal::git_grep -l --null \ (
kube::codegen::internal::grep -l --null \
-e '+k8s:openapi-gen=' \ -e '+k8s:openapi-gen=' \
":(glob)${root}"/'**/*.go' \ -r "${root}" \
|| true \ --include '*.go' ||
) | while read -r -d $'\0' F; do dirname "${F}"; done \ true
| LC_ALL=C sort -u ) | while read -r -d $'\0' F; do dirname "${F}"; done |
LC_ALL=C sort -u
) )
local new_report="" local new_report=""
if [ "${#input_pkgs[@]}" != 0 ]; then if [ "${#input_pkgs[@]}" == 0 ]; then
return 0
fi
echo "Generating openapi code for ${#input_pkgs[@]} targets" echo "Generating openapi code for ${#input_pkgs[@]} targets"
kube::codegen::internal::git_find -z \ kube::codegen::internal::findz \
":(glob)${root}"/'**/zz_generated.openapi.go' \ "${root}" \
-type f \
-name zz_generated.openapi.go \
| xargs -0 rm -f | xargs -0 rm -f
local inputs=() local new_report
for arg in "${input_pkgs[@]}"; do new_report="$(mktemp -t "$(basename "$0").api_violations.XXXXXX")"
inputs+=("--input-dirs" "$arg")
done
new_report="${root}/${report}.tmp"
if [ -n "${update_report}" ]; then if [ -n "${update_report}" ]; then
new_report="${root}/${report}" new_report="${root}/${report}"
fi fi
"${gobin}/openapi-gen" \ "${gobin}/openapi-gen" \
-v "${v}" \ -v "${v}" \
-O zz_generated.openapi \ --output-file zz_generated.openapi.go \
--go-header-file "${boilerplate}" \ --go-header-file "${boilerplate}" \
--output-base "${out_base}" \ --output-dir "${root}" \
--output-package "${in_pkg_single}" \ --output-pkg "${in_pkg_single}" \
--report-filename "${new_report}" \ --report-filename "${new_report}" \
${COMMON_INPUT_DIRS} \ ${COMMON_INPUT_DIRS} \
"${inputs[@]}" "${input_pkgs[@]}"
fi
touch "${root}/${report}" # in case it doesn't exist yet touch "${root}/${report}" # in case it doesn't exist yet
if [[ -z "${new_report}" ]]; then if [[ -z "${new_report}" ]]; then

View File

@ -33,26 +33,27 @@ grafana::codegen:run() {
include_common_input_dirs=$([[ ${api_pkg} == "common" ]] && echo "true" || echo "false") include_common_input_dirs=$([[ ${api_pkg} == "common" ]] && echo "true" || echo "false")
kube::codegen::gen_helpers \ kube::codegen::gen_helpers \
--input-pkg-root github.com/grafana/grafana/${generate_root}/apis/${api_pkg} \ --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
--output-base "${OUTDIR}" \ ${generate_root}/apis/${api_pkg}
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt"
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 \ 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}" \ --output-base "${OUTDIR}" \
--report-filename "${OPENAPI_VIOLATION_EXCEPTIONS_FILENAME}" \ --report-filename "${OPENAPI_VIOLATION_EXCEPTIONS_FILENAME}" \
--update-report \ --update-report \
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \ --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
--include-common-input-dirs ${include_common_input_dirs} --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 # delete violation exceptions file, if empty
if ! grep -q . "${violations_file}"; then if ! grep -q . "${violations_file}"; then
echo "Deleting ${violations_file} since it is empty" echo "Deleting ${violations_file} since it is empty"
rm ${violations_file} rm ${violations_file}
fi fi
echo "" echo ""
done done
done done
@ -69,10 +70,10 @@ grafana::codegen:run() {
kube::codegen::gen_client \ kube::codegen::gen_client \
--with-watch \ --with-watch \
--with-applyconfig \ --with-applyconfig \
--input-pkg-root github.com/grafana/grafana/${generate_root}/apis \ --output-dir ${generate_root}/generated \
--output-pkg-root github.com/grafana/grafana/${generate_root}/generated \ --output-pkg github.com/grafana/grafana/${generate_root}/generated \
--output-base "${OUTDIR}" \ --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" ${generate_root}/apis
echo "" echo ""
} }
@ -83,5 +84,6 @@ grafana:codegen:lsdirs() {
grafana::codegen:run pkg grafana::codegen:run pkg
grafana::codegen:run pkg/apimachinery grafana::codegen:run pkg/apimachinery
grafana::codegen:run pkg/aggregator
echo "done." echo "done."

View File

@ -5,8 +5,6 @@
// Code generated by openapi-gen. DO NOT EDIT. // Code generated by openapi-gen. DO NOT EDIT.
// This file was autogenerated by openapi-gen. Do not edit it manually!
package v0alpha1 package v0alpha1
import ( import (

View File

@ -10,7 +10,7 @@ import (
v1 "k8s.io/client-go/applyconfigurations/meta/v1" 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. // with apply.
type DataPlaneServiceApplyConfiguration struct { type DataPlaneServiceApplyConfiguration struct {
v1.TypeMetaApplyConfiguration `json:",inline"` v1.TypeMetaApplyConfiguration `json:",inline"`
@ -19,7 +19,7 @@ type DataPlaneServiceApplyConfiguration struct {
Status *DataPlaneServiceStatusApplyConfiguration `json:"status,omitempty"` 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. // apply.
func DataPlaneService(name string) *DataPlaneServiceApplyConfiguration { func DataPlaneService(name string) *DataPlaneServiceApplyConfiguration {
b := &DataPlaneServiceApplyConfiguration{} b := &DataPlaneServiceApplyConfiguration{}
@ -202,3 +202,9 @@ func (b *DataPlaneServiceApplyConfiguration) WithStatus(value *DataPlaneServiceS
b.Status = value b.Status = value
return b return b
} }
// GetName retrieves the value of the Name field in the declarative configuration.
func (b *DataPlaneServiceApplyConfiguration) GetName() *string {
b.ensureObjectMetaApplyConfigurationExists()
return b.Name
}

View File

@ -9,7 +9,7 @@ import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 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. // with apply.
type DataPlaneServiceConditionApplyConfiguration struct { type DataPlaneServiceConditionApplyConfiguration struct {
Type *v0alpha1.DataPlaneServiceConditionType `json:"type,omitempty"` Type *v0alpha1.DataPlaneServiceConditionType `json:"type,omitempty"`
@ -19,7 +19,7 @@ type DataPlaneServiceConditionApplyConfiguration struct {
Message *string `json:"message,omitempty"` 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. // apply.
func DataPlaneServiceCondition() *DataPlaneServiceConditionApplyConfiguration { func DataPlaneServiceCondition() *DataPlaneServiceConditionApplyConfiguration {
return &DataPlaneServiceConditionApplyConfiguration{} return &DataPlaneServiceConditionApplyConfiguration{}

View File

@ -8,7 +8,7 @@ import (
v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1" 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. // with apply.
type DataPlaneServiceSpecApplyConfiguration struct { type DataPlaneServiceSpecApplyConfiguration struct {
PluginID *string `json:"pluginID,omitempty"` PluginID *string `json:"pluginID,omitempty"`
@ -18,7 +18,7 @@ type DataPlaneServiceSpecApplyConfiguration struct {
Services []ServiceApplyConfiguration `json:"services,omitempty"` 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. // apply.
func DataPlaneServiceSpec() *DataPlaneServiceSpecApplyConfiguration { func DataPlaneServiceSpec() *DataPlaneServiceSpecApplyConfiguration {
return &DataPlaneServiceSpecApplyConfiguration{} return &DataPlaneServiceSpecApplyConfiguration{}

View File

@ -4,13 +4,13 @@
package v0alpha1 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. // with apply.
type DataPlaneServiceStatusApplyConfiguration struct { type DataPlaneServiceStatusApplyConfiguration struct {
Conditions []DataPlaneServiceConditionApplyConfiguration `json:"conditions,omitempty"` 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. // apply.
func DataPlaneServiceStatus() *DataPlaneServiceStatusApplyConfiguration { func DataPlaneServiceStatus() *DataPlaneServiceStatusApplyConfiguration {
return &DataPlaneServiceStatusApplyConfiguration{} return &DataPlaneServiceStatusApplyConfiguration{}

View File

@ -8,7 +8,7 @@ import (
v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1" 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. // with apply.
type ServiceApplyConfiguration struct { type ServiceApplyConfiguration struct {
Type *v0alpha1.ServiceType `json:"type,omitempty"` Type *v0alpha1.ServiceType `json:"type,omitempty"`
@ -16,7 +16,7 @@ type ServiceApplyConfiguration struct {
Path *string `json:"path,omitempty"` 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. // apply.
func Service() *ServiceApplyConfiguration { func Service() *ServiceApplyConfiguration {
return &ServiceApplyConfiguration{} return &ServiceApplyConfiguration{}

View File

@ -7,7 +7,10 @@ package applyconfiguration
import ( import (
v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1" v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1"
aggregationv0alpha1 "github.com/grafana/grafana/pkg/aggregator/generated/applyconfiguration/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" 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 // 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 return nil
} }
func NewTypeConverter(scheme *runtime.Scheme) *testing.TypeConverter {
return &testing.TypeConverter{Scheme: scheme, TypeResolver: internal.Parser()}
}

View File

@ -5,6 +5,7 @@
package fake package fake
import ( import (
applyconfiguration "github.com/grafana/grafana/pkg/aggregator/generated/applyconfiguration"
clientset "github.com/grafana/grafana/pkg/aggregator/generated/clientset/versioned" clientset "github.com/grafana/grafana/pkg/aggregator/generated/clientset/versioned"
aggregationv0alpha1 "github.com/grafana/grafana/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1" 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" 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. // 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, // 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. // 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 { func NewSimpleClientset(objects ...runtime.Object) *Clientset {
o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder())
for _, obj := range objects { for _, obj := range objects {
@ -60,6 +65,38 @@ func (c *Clientset) Tracker() testing.ObjectTracker {
return c.tracker 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 ( var (
_ clientset.Interface = &Clientset{} _ clientset.Interface = &Clientset{}
_ testing.FakeClient = &Clientset{} _ testing.FakeClient = &Clientset{}

View File

@ -6,9 +6,6 @@ package v0alpha1
import ( import (
"context" "context"
json "encoding/json"
"fmt"
"time"
v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1" v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1"
aggregationv0alpha1 "github.com/grafana/grafana/pkg/aggregator/generated/applyconfiguration/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" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types" types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch" 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. // DataPlaneServicesGetter has a method to return a DataPlaneServiceInterface.
@ -29,6 +26,7 @@ type DataPlaneServicesGetter interface {
type DataPlaneServiceInterface interface { type DataPlaneServiceInterface interface {
Create(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.CreateOptions) (*v0alpha1.DataPlaneService, error) 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) 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) UpdateStatus(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (*v0alpha1.DataPlaneService, error)
Delete(ctx context.Context, name string, opts v1.DeleteOptions) error Delete(ctx context.Context, name string, opts v1.DeleteOptions) error
DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) 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) 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) 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) 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) ApplyStatus(ctx context.Context, dataPlaneService *aggregationv0alpha1.DataPlaneServiceApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.DataPlaneService, err error)
DataPlaneServiceExpansion DataPlaneServiceExpansion
} }
// dataPlaneServices implements DataPlaneServiceInterface // dataPlaneServices implements DataPlaneServiceInterface
type dataPlaneServices struct { type dataPlaneServices struct {
client rest.Interface *gentype.ClientWithListAndApply[*v0alpha1.DataPlaneService, *v0alpha1.DataPlaneServiceList, *aggregationv0alpha1.DataPlaneServiceApplyConfiguration]
} }
// newDataPlaneServices returns a DataPlaneServices // newDataPlaneServices returns a DataPlaneServices
func newDataPlaneServices(c *AggregationV0alpha1Client) *dataPlaneServices { func newDataPlaneServices(c *AggregationV0alpha1Client) *dataPlaneServices {
return &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
}

View File

@ -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. // 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) { func (c *FakeDataPlaneServices) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.DataPlaneService, err error) {
emptyResult := &v0alpha1.DataPlaneService{}
obj, err := c.Fake. obj, err := c.Fake.
Invokes(testing.NewRootGetAction(dataplaneservicesResource, name), &v0alpha1.DataPlaneService{}) Invokes(testing.NewRootGetActionWithOptions(dataplaneservicesResource, name, options), emptyResult)
if obj == nil { if obj == nil {
return nil, err return emptyResult, err
} }
return obj.(*v0alpha1.DataPlaneService), err return obj.(*v0alpha1.DataPlaneService), err
} }
// List takes label and field selectors, and returns the list of DataPlaneServices that match those selectors. // 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) { func (c *FakeDataPlaneServices) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.DataPlaneServiceList, err error) {
emptyResult := &v0alpha1.DataPlaneServiceList{}
obj, err := c.Fake. obj, err := c.Fake.
Invokes(testing.NewRootListAction(dataplaneservicesResource, dataplaneservicesKind, opts), &v0alpha1.DataPlaneServiceList{}) Invokes(testing.NewRootListActionWithOptions(dataplaneservicesResource, dataplaneservicesKind, opts), emptyResult)
if obj == nil { if obj == nil {
return nil, err return emptyResult, err
} }
label, _, _ := testing.ExtractFromListOptions(opts) 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. // Watch returns a watch.Interface that watches the requested dataPlaneServices.
func (c *FakeDataPlaneServices) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { func (c *FakeDataPlaneServices) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
return c.Fake. 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. // 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) { 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. obj, err := c.Fake.
Invokes(testing.NewRootCreateAction(dataplaneservicesResource, dataPlaneService), &v0alpha1.DataPlaneService{}) Invokes(testing.NewRootCreateActionWithOptions(dataplaneservicesResource, dataPlaneService, opts), emptyResult)
if obj == nil { if obj == nil {
return nil, err return emptyResult, err
} }
return obj.(*v0alpha1.DataPlaneService), 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. // 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) { 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. obj, err := c.Fake.
Invokes(testing.NewRootUpdateAction(dataplaneservicesResource, dataPlaneService), &v0alpha1.DataPlaneService{}) Invokes(testing.NewRootUpdateActionWithOptions(dataplaneservicesResource, dataPlaneService, opts), emptyResult)
if obj == nil { if obj == nil {
return nil, err return emptyResult, err
} }
return obj.(*v0alpha1.DataPlaneService), err return obj.(*v0alpha1.DataPlaneService), err
} }
// UpdateStatus was generated because the type contains a Status member. // UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). // 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. obj, err := c.Fake.
Invokes(testing.NewRootUpdateSubresourceAction(dataplaneservicesResource, "status", dataPlaneService), &v0alpha1.DataPlaneService{}) Invokes(testing.NewRootUpdateSubresourceActionWithOptions(dataplaneservicesResource, "status", dataPlaneService, opts), emptyResult)
if obj == nil { if obj == nil {
return nil, err return emptyResult, err
} }
return obj.(*v0alpha1.DataPlaneService), 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. // DeleteCollection deletes a collection of objects.
func (c *FakeDataPlaneServices) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { 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{}) _, err := c.Fake.Invokes(action, &v0alpha1.DataPlaneServiceList{})
return err 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. // 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) { 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. 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 { if obj == nil {
return nil, err return emptyResult, err
} }
return obj.(*v0alpha1.DataPlaneService), err return obj.(*v0alpha1.DataPlaneService), err
} }
@ -133,10 +139,11 @@ func (c *FakeDataPlaneServices) Apply(ctx context.Context, dataPlaneService *agg
if name == nil { if name == nil {
return nil, fmt.Errorf("dataPlaneService.Name must be provided to Apply") return nil, fmt.Errorf("dataPlaneService.Name must be provided to Apply")
} }
emptyResult := &v0alpha1.DataPlaneService{}
obj, err := c.Fake. 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 { if obj == nil {
return nil, err return emptyResult, err
} }
return obj.(*v0alpha1.DataPlaneService), err return obj.(*v0alpha1.DataPlaneService), err
} }
@ -155,10 +162,11 @@ func (c *FakeDataPlaneServices) ApplyStatus(ctx context.Context, dataPlaneServic
if name == nil { if name == nil {
return nil, fmt.Errorf("dataPlaneService.Name must be provided to Apply") return nil, fmt.Errorf("dataPlaneService.Name must be provided to Apply")
} }
emptyResult := &v0alpha1.DataPlaneService{}
obj, err := c.Fake. 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 { if obj == nil {
return nil, err return emptyResult, err
} }
return obj.(*v0alpha1.DataPlaneService), err return obj.(*v0alpha1.DataPlaneService), err
} }

View File

@ -214,6 +214,7 @@ type SharedInformerFactory interface {
// Start initializes all requested informers. They are handled in goroutines // Start initializes all requested informers. They are handled in goroutines
// which run until the stop channel gets closed. // 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{}) Start(stopCh <-chan struct{})
// Shutdown marks a factory as shutting down. At that point no new // Shutdown marks a factory as shutting down. At that point no new

View File

@ -6,8 +6,8 @@ package v0alpha1
import ( import (
v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1" v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/listers"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
) )
@ -25,30 +25,10 @@ type DataPlaneServiceLister interface {
// dataPlaneServiceLister implements the DataPlaneServiceLister interface. // dataPlaneServiceLister implements the DataPlaneServiceLister interface.
type dataPlaneServiceLister struct { type dataPlaneServiceLister struct {
indexer cache.Indexer listers.ResourceIndexer[*v0alpha1.DataPlaneService]
} }
// NewDataPlaneServiceLister returns a new DataPlaneServiceLister. // NewDataPlaneServiceLister returns a new DataPlaneServiceLister.
func NewDataPlaneServiceLister(indexer cache.Indexer) DataPlaneServiceLister { func NewDataPlaneServiceLister(indexer cache.Indexer) DataPlaneServiceLister {
return &dataPlaneServiceLister{indexer: indexer} return &dataPlaneServiceLister{listers.New[*v0alpha1.DataPlaneService](indexer, v0alpha1.Resource("dataplaneservice"))}
}
// 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
} }

View File

@ -5,8 +5,6 @@
// Code generated by openapi-gen. DO NOT EDIT. // Code generated by openapi-gen. DO NOT EDIT.
// This file was autogenerated by openapi-gen. Do not edit it manually!
package v0alpha1 package v0alpha1
import ( 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.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.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.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.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.DashboardVersionList": schema_pkg_apis_dashboard_v0alpha1_DashboardVersionList(ref),
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1.DashboardWithAccessInfo": schema_pkg_apis_dashboard_v0alpha1_DashboardWithAccessInfo(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 { func schema_pkg_apis_dashboard_v0alpha1_DashboardVersionInfo(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{ return common.OpenAPIDefinition{
Schema: spec.Schema{ Schema: spec.Schema{

View File

@ -1 +0,0 @@
API rule violation: list_type_missing,github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1,DashboardSummarySpec,Tags

View File

@ -5,8 +5,6 @@
// Code generated by openapi-gen. DO NOT EDIT. // Code generated by openapi-gen. DO NOT EDIT.
// This file was autogenerated by openapi-gen. Do not edit it manually!
package v0alpha1 package v0alpha1
import ( import (

View File

@ -5,8 +5,6 @@
// Code generated by openapi-gen. DO NOT EDIT. // Code generated by openapi-gen. DO NOT EDIT.
// This file was autogenerated by openapi-gen. Do not edit it manually!
package v0alpha1 package v0alpha1
import ( import (

View File

@ -5,8 +5,6 @@
// Code generated by openapi-gen. DO NOT EDIT. // Code generated by openapi-gen. DO NOT EDIT.
// This file was autogenerated by openapi-gen. Do not edit it manually!
package v0alpha1 package v0alpha1
import ( import (
@ -192,6 +190,13 @@ func schema_pkg_apis_featuretoggle_v0alpha1_FeatureSpec(ref common.ReferenceCall
Format: "", Format: "",
}, },
}, },
"expression": {
SchemaProps: spec.SchemaProps{
Description: "Expression to determine if the flag is enabled by default",
Type: []string{"string"},
Format: "",
},
},
}, },
Required: []string{"description", "stage"}, Required: []string{"description", "stage"},
}, },

View File

@ -5,8 +5,6 @@
// Code generated by openapi-gen. DO NOT EDIT. // Code generated by openapi-gen. DO NOT EDIT.
// This file was autogenerated by openapi-gen. Do not edit it manually!
package v0alpha1 package v0alpha1
import ( import (

View File

@ -5,8 +5,6 @@
// Code generated by openapi-gen. DO NOT EDIT. // Code generated by openapi-gen. DO NOT EDIT.
// This file was autogenerated by openapi-gen. Do not edit it manually!
package v0alpha1 package v0alpha1
import ( import (

View File

@ -5,8 +5,6 @@
// Code generated by openapi-gen. DO NOT EDIT. // Code generated by openapi-gen. DO NOT EDIT.
// This file was autogenerated by openapi-gen. Do not edit it manually!
package v0alpha1 package v0alpha1
import ( import (

View File

@ -5,8 +5,6 @@
// Code generated by openapi-gen. DO NOT EDIT. // Code generated by openapi-gen. DO NOT EDIT.
// This file was autogenerated by openapi-gen. Do not edit it manually!
package v0alpha1 package v0alpha1
import ( import (

View File

@ -5,8 +5,6 @@
// Code generated by openapi-gen. DO NOT EDIT. // Code generated by openapi-gen. DO NOT EDIT.
// This file was autogenerated by openapi-gen. Do not edit it manually!
package v0alpha1 package v0alpha1
import ( import (

View File

@ -5,8 +5,6 @@
// Code generated by openapi-gen. DO NOT EDIT. // Code generated by openapi-gen. DO NOT EDIT.
// This file was autogenerated by openapi-gen. Do not edit it manually!
package v0alpha1 package v0alpha1
import ( import (

View File

@ -10,7 +10,7 @@ import (
v1 "k8s.io/client-go/applyconfigurations/meta/v1" 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. // with apply.
type ExternalNameApplyConfiguration struct { type ExternalNameApplyConfiguration struct {
v1.TypeMetaApplyConfiguration `json:",inline"` v1.TypeMetaApplyConfiguration `json:",inline"`
@ -18,7 +18,7 @@ type ExternalNameApplyConfiguration struct {
Spec *ExternalNameSpecApplyConfiguration `json:"spec,omitempty"` 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. // apply.
func ExternalName(name, namespace string) *ExternalNameApplyConfiguration { func ExternalName(name, namespace string) *ExternalNameApplyConfiguration {
b := &ExternalNameApplyConfiguration{} b := &ExternalNameApplyConfiguration{}
@ -194,3 +194,9 @@ func (b *ExternalNameApplyConfiguration) WithSpec(value *ExternalNameSpecApplyCo
b.Spec = value b.Spec = value
return b return b
} }
// GetName retrieves the value of the Name field in the declarative configuration.
func (b *ExternalNameApplyConfiguration) GetName() *string {
b.ensureObjectMetaApplyConfigurationExists()
return b.Name
}

View File

@ -4,13 +4,13 @@
package v0alpha1 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. // with apply.
type ExternalNameSpecApplyConfiguration struct { type ExternalNameSpecApplyConfiguration struct {
Host *string `json:"host,omitempty"` 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. // apply.
func ExternalNameSpec() *ExternalNameSpecApplyConfiguration { func ExternalNameSpec() *ExternalNameSpecApplyConfiguration {
return &ExternalNameSpecApplyConfiguration{} return &ExternalNameSpecApplyConfiguration{}

View File

@ -8,8 +8,11 @@ import (
v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1" v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1"
servicev0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1" servicev0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1"
alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/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" applyconfigurationservicev0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/service/v0alpha1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema" 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 // 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 return nil
} }
func NewTypeConverter(scheme *runtime.Scheme) *testing.TypeConverter {
return &testing.TypeConverter{Scheme: scheme, TypeResolver: internal.Parser()}
}

View File

@ -5,6 +5,7 @@
package fake package fake
import ( import (
applyconfiguration "github.com/grafana/grafana/pkg/generated/applyconfiguration"
clientset "github.com/grafana/grafana/pkg/generated/clientset/versioned" clientset "github.com/grafana/grafana/pkg/generated/clientset/versioned"
notificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/alerting_notifications/v0alpha1" 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" 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. // 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, // 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. // 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 { func NewSimpleClientset(objects ...runtime.Object) *Clientset {
o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder())
for _, obj := range objects { for _, obj := range objects {
@ -62,6 +67,38 @@ func (c *Clientset) Tracker() testing.ObjectTracker {
return c.tracker 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 ( var (
_ clientset.Interface = &Clientset{} _ clientset.Interface = &Clientset{}
_ testing.FakeClient = &Clientset{} _ testing.FakeClient = &Clientset{}

View File

@ -6,9 +6,6 @@ package v0alpha1
import ( import (
"context" "context"
json "encoding/json"
"fmt"
"time"
v0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1" v0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1"
servicev0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/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" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types" types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch" 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. // ExternalNamesGetter has a method to return a ExternalNameInterface.
@ -41,154 +38,18 @@ type ExternalNameInterface interface {
// externalNames implements ExternalNameInterface // externalNames implements ExternalNameInterface
type externalNames struct { type externalNames struct {
client rest.Interface *gentype.ClientWithListAndApply[*v0alpha1.ExternalName, *v0alpha1.ExternalNameList, *servicev0alpha1.ExternalNameApplyConfiguration]
ns string
} }
// newExternalNames returns a ExternalNames // newExternalNames returns a ExternalNames
func newExternalNames(c *ServiceV0alpha1Client, namespace string) *externalNames { func newExternalNames(c *ServiceV0alpha1Client, namespace string) *externalNames {
return &externalNames{ return &externalNames{
client: c.RESTClient(), gentype.NewClientWithListAndApply[*v0alpha1.ExternalName, *v0alpha1.ExternalNameList, *servicev0alpha1.ExternalNameApplyConfiguration](
ns: namespace, "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
}

View File

@ -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. // 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) { func (c *FakeExternalNames) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.ExternalName, err error) {
emptyResult := &v0alpha1.ExternalName{}
obj, err := c.Fake. 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 { if obj == nil {
return nil, err return emptyResult, err
} }
return obj.(*v0alpha1.ExternalName), err return obj.(*v0alpha1.ExternalName), err
} }
// List takes label and field selectors, and returns the list of ExternalNames that match those selectors. // 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) { func (c *FakeExternalNames) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.ExternalNameList, err error) {
emptyResult := &v0alpha1.ExternalNameList{}
obj, err := c.Fake. 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 { if obj == nil {
return nil, err return emptyResult, err
} }
label, _, _ := testing.ExtractFromListOptions(opts) 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. // Watch returns a watch.Interface that watches the requested externalNames.
func (c *FakeExternalNames) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { func (c *FakeExternalNames) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
return c.Fake. 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. // 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) { 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. 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 { if obj == nil {
return nil, err return emptyResult, err
} }
return obj.(*v0alpha1.ExternalName), 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. // 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) { 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. 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 { if obj == nil {
return nil, err return emptyResult, err
} }
return obj.(*v0alpha1.ExternalName), 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. // DeleteCollection deletes a collection of objects.
func (c *FakeExternalNames) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { 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{}) _, err := c.Fake.Invokes(action, &v0alpha1.ExternalNameList{})
return err 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. // 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) { 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. 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 { if obj == nil {
return nil, err return emptyResult, err
} }
return obj.(*v0alpha1.ExternalName), err return obj.(*v0alpha1.ExternalName), err
} }
@ -130,11 +135,12 @@ func (c *FakeExternalNames) Apply(ctx context.Context, externalName *servicev0al
if name == nil { if name == nil {
return nil, fmt.Errorf("externalName.Name must be provided to Apply") return nil, fmt.Errorf("externalName.Name must be provided to Apply")
} }
emptyResult := &v0alpha1.ExternalName{}
obj, err := c.Fake. 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 { if obj == nil {
return nil, err return emptyResult, err
} }
return obj.(*v0alpha1.ExternalName), err return obj.(*v0alpha1.ExternalName), err
} }

View File

@ -215,6 +215,7 @@ type SharedInformerFactory interface {
// Start initializes all requested informers. They are handled in goroutines // Start initializes all requested informers. They are handled in goroutines
// which run until the stop channel gets closed. // 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{}) Start(stopCh <-chan struct{})
// Shutdown marks a factory as shutting down. At that point no new // Shutdown marks a factory as shutting down. At that point no new

View File

@ -6,8 +6,8 @@ package v0alpha1
import ( import (
v0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1" v0alpha1 "github.com/grafana/grafana/pkg/apis/service/v0alpha1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/listers"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
) )
@ -24,25 +24,17 @@ type ExternalNameLister interface {
// externalNameLister implements the ExternalNameLister interface. // externalNameLister implements the ExternalNameLister interface.
type externalNameLister struct { type externalNameLister struct {
indexer cache.Indexer listers.ResourceIndexer[*v0alpha1.ExternalName]
} }
// NewExternalNameLister returns a new ExternalNameLister. // NewExternalNameLister returns a new ExternalNameLister.
func NewExternalNameLister(indexer cache.Indexer) ExternalNameLister { func NewExternalNameLister(indexer cache.Indexer) ExternalNameLister {
return &externalNameLister{indexer: indexer} return &externalNameLister{listers.New[*v0alpha1.ExternalName](indexer, v0alpha1.Resource("externalname"))}
}
// 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
} }
// ExternalNames returns an object that can list and get ExternalNames. // ExternalNames returns an object that can list and get ExternalNames.
func (s *externalNameLister) ExternalNames(namespace string) ExternalNameNamespaceLister { 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. // ExternalNameNamespaceLister helps list and get ExternalNames.
@ -60,26 +52,5 @@ type ExternalNameNamespaceLister interface {
// externalNameNamespaceLister implements the ExternalNameNamespaceLister // externalNameNamespaceLister implements the ExternalNameNamespaceLister
// interface. // interface.
type externalNameNamespaceLister struct { type externalNameNamespaceLister struct {
indexer cache.Indexer listers.ResourceIndexer[*v0alpha1.ExternalName]
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
} }