1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-26 13:29:11 +01:00

update k8s to v1.33

Signed-off-by: dongjiang <dongjiang1989@126.com>
This commit is contained in:
dongjiang
2025-04-28 10:12:24 +08:00
parent 6e9622bf41
commit a249c9baf0
1273 changed files with 79284 additions and 28462 deletions

View File

@@ -85,7 +85,7 @@ func (args *Args) AddFlags(fs *pflag.FlagSet, inputBase string) {
fs.StringVar(&args.GoHeaderFile, "go-header-file", "",
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
fs.Var(NewGVPackagesValue(gvsBuilder, nil), "input",
"group/versions that client-gen will generate clients for. At most one version per group is allowed. Specified in the format \"group1/version1,group2/version2...\".")
`group/versions that client-gen will generate clients for. At most one version per group is allowed. Specified in the format "group1/version1,group2/version2...".`)
fs.Var(NewGVTypesValue(&args.IncludedTypesOverrides, []string{}), "included-types-overrides",
"list of group/version/type for which client should be generated. By default, client is generated for all types which have genclient in types.go. This overrides that. For each groupVersion in this list, only the types mentioned here will be included. The default check of genclient will be used for other group versions.")
fs.Var(NewInputBasePathValue(gvsBuilder, inputBase), "input-base",

View File

@@ -77,6 +77,7 @@ func (g *genClientset) Imports(c *generator.Context) (imports []string) {
"fakediscovery \"k8s.io/client-go/discovery/fake\"",
"k8s.io/apimachinery/pkg/runtime",
"k8s.io/apimachinery/pkg/watch",
"metav1 \"k8s.io/apimachinery/pkg/apis/meta/v1\"",
)
return
@@ -139,9 +140,13 @@ func NewClientset(objects ...runtime.Object) *Clientset {
cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake}
cs.AddReactor("*", "*", testing.ObjectReaction(o))
cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
var opts metav1.ListOptions
if watchActcion, ok := action.(testing.WatchActionImpl); ok {
opts = watchActcion.ListOptions
}
gvr := action.GetResource()
ns := action.GetNamespace()
watch, err := o.Watch(gvr, ns)
watch, err := o.Watch(gvr, ns, opts)
if err != nil {
return false, nil, err
}
@@ -173,9 +178,13 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset {
cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake}
cs.AddReactor("*", "*", testing.ObjectReaction(o))
cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
var opts metav1.ListOptions
if watchActcion, ok := action.(testing.WatchActionImpl); ok {
opts = watchActcion.ListOptions
}
gvr := action.GetResource()
ns := action.GetNamespace()
watch, err := o.Watch(gvr, ns)
watch, err := o.Watch(gvr, ns, opts)
if err != nil {
return false, nil, err
}

View File

@@ -169,9 +169,7 @@ var newClientForConfigTemplate = `
// where httpClient was generated with rest.HTTPClientFor(c).
func NewForConfig(c *$.restConfig|raw$) (*$.GroupGoName$$.Version$Client, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
}
setConfigDefaults(&config)
httpClient, err := $.RESTHTTPClientFor|raw$(&config)
if err != nil {
return nil, err
@@ -185,9 +183,7 @@ var newClientForConfigAndClientTemplate = `
// Note the http client provided takes precedence over the configured transport values.
func NewForConfigAndClient(c *$.restConfig|raw$, h *$.httpClient|raw$) (*$.GroupGoName$$.Version$Client, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
}
setConfigDefaults(&config)
client, err := $.restRESTClientForConfigAndClient|raw$(&config, h)
if err != nil {
return nil, err
@@ -227,7 +223,7 @@ func New(c $.restRESTClientInterface|raw$) *$.GroupGoName$$.Version$Client {
`
var setInternalVersionClientDefaultsTemplate = `
func setConfigDefaults(config *$.restConfig|raw$) error {
func setConfigDefaults(config *$.restConfig|raw$) {
config.APIPath = $.apiPath$
if config.UserAgent == "" {
config.UserAgent = $.restDefaultKubernetesUserAgent|raw$()
@@ -244,13 +240,11 @@ func setConfigDefaults(config *$.restConfig|raw$) error {
if config.Burst == 0 {
config.Burst = 10
}
return nil
}
`
var setClientDefaultsTemplate = `
func setConfigDefaults(config *$.restConfig|raw$) error {
func setConfigDefaults(config *$.restConfig|raw$) {
gv := $.SchemeGroupVersion|raw$
config.GroupVersion = &gv
config.APIPath = $.apiPath$
@@ -259,7 +253,5 @@ func setConfigDefaults(config *$.restConfig|raw$) error {
if config.UserAgent == "" {
config.UserAgent = $.restDefaultKubernetesUserAgent|raw$()
}
return nil
}
`

View File

@@ -19,6 +19,7 @@ package main
import (
"flag"
"slices"
"github.com/spf13/pflag"
"k8s.io/klog/v2"
@@ -46,6 +47,8 @@ func main() {
inputPkgs = append(inputPkgs, v.Package)
}
}
// ensure stable code generation output
slices.Sort(inputPkgs)
if err := args.Validate(); err != nil {
klog.Fatalf("Error: %v", err)

View File

@@ -86,7 +86,8 @@ func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w
"cacheNewSharedIndexInformer": c.Universe.Function(cacheNewSharedIndexInformer),
"cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer),
"clientSetInterface": clientSetInterface,
"contextTODO": c.Universe.Type(contextTODOFunc),
"contextContext": c.Universe.Type(contextContext),
"contextBackground": c.Universe.Function(contextBackgroundFunc),
"group": namer.IC(g.groupGoName),
"informerFor": informerFor,
"interfacesTweakListOptionsFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "TweakListOptionsFunc"}),
@@ -152,13 +153,25 @@ func NewFiltered$.type|public$Informer(client $.clientSetInterface|raw$$if .name
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).List($.contextTODO|raw$(), options)
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).List($.contextBackground|raw$(), options)
},
WatchFunc: func(options $.v1ListOptions|raw$) ($.watchInterface|raw$, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).Watch($.contextTODO|raw$(), options)
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).Watch($.contextBackground|raw$(), options)
},
ListWithContextFunc: func(ctx $.contextContext|raw$, options $.v1ListOptions|raw$) ($.runtimeObject|raw$, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).List(ctx, options)
},
WatchFuncWithContext: func(ctx $.contextContext|raw$, options $.v1ListOptions|raw$) ($.watchInterface|raw$, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).Watch(ctx, options)
},
},
&$.type|raw${},

View File

@@ -29,7 +29,8 @@ var (
cacheNewSharedIndexInformer = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "NewSharedIndexInformer"}
cacheSharedIndexInformer = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "SharedIndexInformer"}
cacheTransformFunc = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "TransformFunc"}
contextTODOFunc = types.Name{Package: "context", Name: "TODO"}
contextBackgroundFunc = types.Name{Package: "context", Name: "Background"}
contextContext = types.Name{Package: "context", Name: "Context"}
fmtErrorfFunc = types.Name{Package: "fmt", Name: "Errorf"}
listOptions = types.Name{Package: "k8s.io/kubernetes/pkg/apis/core", Name: "ListOptions"}
reflectType = types.Name{Package: "reflect", Name: "Type"}

View File

@@ -1,5 +1,5 @@
/*
Copyright 2018 The Kubernetes Authors.
Copyright 2025 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -61,11 +61,15 @@ func (g *registerExternalGenerator) Finalize(context *generator.Context, w io.Wr
sw := generator.NewSnippetWriter(w, context, "$", "$")
m := map[string]interface{}{
"groupName": g.gv.Group,
"version": g.gv.Version,
"types": typesToGenerateOnlyNames,
"addToGroupVersion": context.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "AddToGroupVersion"}),
"groupVersion": context.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GroupVersion"}),
"groupName": g.gv.Group,
"version": g.gv.Version,
"types": typesToGenerateOnlyNames,
"addToGroupVersion": context.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "AddToGroupVersion"}),
"groupVersion": context.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GroupVersion"}),
"schemaGroupVersion": context.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersion"}),
"schemaGroupResource": context.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupResource"}),
"scheme": context.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "Scheme"}),
"schemeBuilder": context.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "SchemeBuilder"}),
}
sw.Do(registerExternalTypesTemplate, m)
return sw.Error()
@@ -80,16 +84,16 @@ var GroupVersion = $.groupVersion|raw${Group: GroupName, Version: "$.version$"}
// SchemeGroupVersion is group version used to register these objects
// Deprecated: use GroupVersion instead.
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "$.version$"}
var SchemeGroupVersion = $.schemaGroupVersion|raw${Group: GroupName, Version: "$.version$"}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
func Resource(resource string) $.schemaGroupResource|raw$ {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
var (
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
SchemeBuilder runtime.SchemeBuilder
SchemeBuilder $.schemeBuilder|raw$
localSchemeBuilder = &SchemeBuilder
// Deprecated: use Install instead
AddToScheme = localSchemeBuilder.AddToScheme
@@ -104,7 +108,7 @@ func init() {
}
// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
func addKnownTypes(scheme *$.scheme|raw$) error {
scheme.AddKnownTypes(SchemeGroupVersion,
$range .types -$
&$.${},

View File

@@ -14,4 +14,4 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package codegenerator // import "k8s.io/code-generator"
package codegenerator

View File

@@ -27,6 +27,11 @@ set -o pipefail
KUBE_CODEGEN_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
# Callers which want a specific tag of the k8s.io/code-generator repo should
# set the KUBE_CODEGEN_TAG to the tag name, e.g. KUBE_CODEGEN_TAG="release-1.32"
# before sourcing this file.
CODEGEN_VERSION_SPEC="${KUBE_CODEGEN_TAG:+"@${KUBE_CODEGEN_TAG}"}"
function kube::codegen::internal::findz() {
# We use `find` rather than `git ls-files` because sometimes external
# projects use this across repos. This is an imperfect wrapper of find,
@@ -43,7 +48,7 @@ function kube::codegen::internal::grep() {
--exclude-dir vendor
}
# Generate tagged helper code: conversions, deepcopy, and defaults
# Generate tagged helper code: conversions, deepcopy, defaults and validations
#
# USAGE: kube::codegen::gen_helpers [FLAGS] <input-dir>
#
@@ -103,9 +108,10 @@ function kube::codegen::gen_helpers() {
# and then install with forced module mode on and fully qualified name.
cd "${KUBE_CODEGEN_ROOT}"
BINS=(
conversion-gen
deepcopy-gen
defaulter-gen
conversion-gen"${CODEGEN_VERSION_SPEC}"
deepcopy-gen"${CODEGEN_VERSION_SPEC}"
defaulter-gen"${CODEGEN_VERSION_SPEC}"
validation-gen"${CODEGEN_VERSION_SPEC}"
)
# shellcheck disable=2046 # printf word-splitting is intentional
GO111MODULE=on go install $(printf "k8s.io/code-generator/cmd/%s " "${BINS[@]}")
@@ -145,6 +151,38 @@ function kube::codegen::gen_helpers() {
"${input_pkgs[@]}"
fi
# Validations
#
local input_pkgs=()
while read -r dir; do
pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)"
input_pkgs+=("${pkg}")
done < <(
( kube::codegen::internal::grep -l --null \
-e '^\s*//\s*+k8s:validation-gen=' \
-r "${in_dir}" \
--include '*.go' \
|| true \
) | while read -r -d $'\0' F; do dirname "${F}"; done \
| LC_ALL=C sort -u
)
if [ "${#input_pkgs[@]}" != 0 ]; then
echo "Generating validation code for ${#input_pkgs[@]} targets"
kube::codegen::internal::findz \
"${in_dir}" \
-type f \
-name zz_generated.validations.go \
| xargs -0 rm -f
"${gobin}/validation-gen" \
-v "${v}" \
--output-file zz_generated.validations.go \
--go-header-file "${boilerplate}" \
"${input_pkgs[@]}"
fi
# Defaults
#
local input_pkgs=()
@@ -324,7 +362,7 @@ function kube::codegen::gen_openapi() {
# and then install with forced module mode on and fully qualified name.
cd "${KUBE_CODEGEN_ROOT}"
BINS=(
openapi-gen
openapi-gen"${CODEGEN_VERSION_SPEC}"
)
# shellcheck disable=2046 # printf word-splitting is intentional
GO111MODULE=on go install $(printf "k8s.io/kube-openapi/cmd/%s " "${BINS[@]}")
@@ -368,7 +406,10 @@ function kube::codegen::gen_openapi() {
"${input_pkgs[@]}"
fi
touch "${report}" # in case it doesn't exist yet
if [ ! -e "${report}" ]; then
touch "${report}" # in case it doesn't exist yet
fi
if ! diff -u "${report}" "${new_report}"; then
echo -e "ERROR:"
echo -e "\tAPI rule check failed for ${report}: new reported violations"
@@ -551,10 +592,10 @@ function kube::codegen::gen_client() {
# and then install with forced module mode on and fully qualified name.
cd "${KUBE_CODEGEN_ROOT}"
BINS=(
applyconfiguration-gen
client-gen
informer-gen
lister-gen
applyconfiguration-gen"${CODEGEN_VERSION_SPEC}"
client-gen"${CODEGEN_VERSION_SPEC}"
informer-gen"${CODEGEN_VERSION_SPEC}"
lister-gen"${CODEGEN_VERSION_SPEC}"
)
# shellcheck disable=2046 # printf word-splitting is intentional
GO111MODULE=on go install $(printf "k8s.io/code-generator/cmd/%s " "${BINS[@]}")
@@ -726,7 +767,7 @@ function kube::codegen::gen_register() {
# and then install with forced module mode on and fully qualified name.
cd "${KUBE_CODEGEN_ROOT}"
BINS=(
register-gen
register-gen"${CODEGEN_VERSION_SPEC}"
)
# shellcheck disable=2046 # printf word-splitting is intentional
GO111MODULE=on go install $(printf "k8s.io/code-generator/cmd/%s " "${BINS[@]}")