From c11f8cdc6ec0d5144a2c53adc06807d513acdf47 Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Wed, 3 Jan 2024 18:34:19 -0800 Subject: [PATCH] Implement SingularNameProvider for REST Signed-off-by: Tamal Saha --- Makefile | 4 +-- admission/v1/generic/generic.go | 4 +-- admission/v1/workload/workload.go | 4 +-- admission/v1beta1/generic/generic.go | 4 +-- admission/v1beta1/workload/workload.go | 4 +-- builder/builder.go | 22 ++++++---------- go.mod | 4 +-- go.sum | 20 +++++++-------- .../admissionreview/v1/admission_review.go | 6 +++++ .../v1beta1/admission_review.go | 6 +++++ vendor/kmodules.xyz/client-go/Makefile | 2 +- .../client-go/meta/preconditions.go | 6 ++--- vendor/modules.txt | 6 ++--- .../pkg/client/apiutil/apimachinery.go | 21 ++++++++++++++++ .../controller-runtime/pkg/client/options.go | 5 ++-- .../pkg/webhook/admission/http.go | 25 ++++++++++++------- 16 files changed, 87 insertions(+), 56 deletions(-) diff --git a/Makefile b/Makefile index 43ae3400..13a2e6c3 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ REPO := $(notdir $(shell pwd)) BIN := webhook-runtime # https://github.com/appscodelabs/gengo-builder -CODE_GENERATOR_IMAGE ?= ghcr.io/appscode/gengo:release-1.25 +CODE_GENERATOR_IMAGE ?= ghcr.io/appscode/gengo:release-1.29 # This version-strategy uses git tags to set the version string git_branch := $(shell git rev-parse --abbrev-ref HEAD) @@ -191,7 +191,7 @@ unit-tests: $(BUILD_DIRS) ./hack/test.sh $(SRC_DIRS) \ " -ADDTL_LINTERS := goconst,gofmt,goimports,unparam +ADDTL_LINTERS := gofmt,goimports,unparam .PHONY: lint lint: $(BUILD_DIRS) diff --git a/admission/v1/generic/generic.go b/admission/v1/generic/generic.go index 9b86987f..97695849 100644 --- a/admission/v1/generic/generic.go +++ b/admission/v1/generic/generic.go @@ -42,7 +42,7 @@ type GenericWebhook struct { plural schema.GroupVersionResource singular string - srcGroups sets.String + srcGroups sets.Set[string] target schema.GroupVersionKind factory api.GetterFactory get api.GetFunc @@ -65,7 +65,7 @@ func NewGenericWebhook( return &GenericWebhook{ plural: plural, singular: singular, - srcGroups: sets.NewString(srcGroups...), + srcGroups: sets.New[string](srcGroups...), target: target, factory: factory, handler: handler, diff --git a/admission/v1/workload/workload.go b/admission/v1/workload/workload.go index 6b7a5383..c466ecae 100644 --- a/admission/v1/workload/workload.go +++ b/admission/v1/workload/workload.go @@ -49,7 +49,7 @@ type WorkloadWebhook struct { singular string kind string - srcGroups sets.String + srcGroups sets.Set[string] factory api.GetterFactory get api.GetFunc handler lib.ResourceHandler @@ -71,7 +71,7 @@ func NewWorkloadWebhook( plural: plural, singular: singular, kind: kind, - srcGroups: sets.NewString(core.GroupName, appsv1.GroupName, extensions.GroupName, batchv1.GroupName), + srcGroups: sets.New[string](core.GroupName, appsv1.GroupName, extensions.GroupName, batchv1.GroupName), factory: factory, handler: handler, } diff --git a/admission/v1beta1/generic/generic.go b/admission/v1beta1/generic/generic.go index aafbe313..6ec89359 100644 --- a/admission/v1beta1/generic/generic.go +++ b/admission/v1beta1/generic/generic.go @@ -42,7 +42,7 @@ type GenericWebhook struct { plural schema.GroupVersionResource singular string - srcGroups sets.String + srcGroups sets.Set[string] target schema.GroupVersionKind factory api.GetterFactory get api.GetFunc @@ -65,7 +65,7 @@ func NewGenericWebhook( return &GenericWebhook{ plural: plural, singular: singular, - srcGroups: sets.NewString(srcGroups...), + srcGroups: sets.New[string](srcGroups...), target: target, factory: factory, handler: handler, diff --git a/admission/v1beta1/workload/workload.go b/admission/v1beta1/workload/workload.go index e795e760..742c39eb 100644 --- a/admission/v1beta1/workload/workload.go +++ b/admission/v1beta1/workload/workload.go @@ -49,7 +49,7 @@ type WorkloadWebhook struct { singular string kind string - srcGroups sets.String + srcGroups sets.Set[string] factory api.GetterFactory get api.GetFunc handler admission.ResourceHandler @@ -71,7 +71,7 @@ func NewWorkloadWebhook( plural: plural, singular: singular, kind: kind, - srcGroups: sets.NewString(core.GroupName, appsv1.GroupName, extensions.GroupName, batchv1.GroupName), + srcGroups: sets.New[string](core.GroupName, appsv1.GroupName, extensions.GroupName, batchv1.GroupName), factory: factory, handler: handler, } diff --git a/builder/builder.go b/builder/builder.go index 792fe695..63b264e9 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -59,23 +59,15 @@ func (blder *WebhookBuilder) Complete() (hooks.AdmissionHook, hooks.AdmissionHoo } blder.gk = gvk.GroupKind() - mutator, err := blder.registerDefaultingWebhook() - if err != nil { - return nil, nil, err - } - validator, err := blder.registerValidatingWebhook() - if err != nil { - return nil, nil, err - } - return mutator, validator, nil + return blder.registerDefaultingWebhook(), blder.registerValidatingWebhook(), nil } // registerDefaultingWebhook registers a defaulting webhook if th. -func (blder *WebhookBuilder) registerDefaultingWebhook() (hooks.AdmissionHook, error) { +func (blder *WebhookBuilder) registerDefaultingWebhook() hooks.AdmissionHook { defaulter, isDefaulter := blder.apiType.(admission.Defaulter) if !isDefaulter { log.Info("skip registering a mutating webhook, admission.Defaulter interface is not implemented", "GK", blder.gk) - return nil, nil + return nil } mwh := admission.DefaultingWebhookFor(blder.scheme, defaulter) @@ -83,14 +75,14 @@ func (blder *WebhookBuilder) registerDefaultingWebhook() (hooks.AdmissionHook, e prefix: MutatorGroupPrefix, gk: blder.gk, w: mwh, - }, nil + } } -func (blder *WebhookBuilder) registerValidatingWebhook() (hooks.AdmissionHook, error) { +func (blder *WebhookBuilder) registerValidatingWebhook() hooks.AdmissionHook { checker, isValidator := blder.apiType.(admission.Validator) if !isValidator { log.Info("skip registering a validating webhook, admission.Validator interface is not implemented", "GK", blder.gk) - return nil, nil + return nil } vwh := admission.ValidatingWebhookFor(blder.scheme, checker) @@ -98,5 +90,5 @@ func (blder *WebhookBuilder) registerValidatingWebhook() (hooks.AdmissionHook, e prefix: ValidatorGroupPrefix, gk: blder.gk, w: vwh, - }, nil + } } diff --git a/go.mod b/go.mod index 116839c0..2c8e62c6 100644 --- a/go.mod +++ b/go.mod @@ -12,9 +12,9 @@ require ( k8s.io/client-go v0.29.0 k8s.io/klog/v2 v2.110.1 k8s.io/kubernetes v0.0.0-00010101000000-000000000000 - kmodules.xyz/client-go v0.29.1 + kmodules.xyz/client-go v0.29.5 kmodules.xyz/openshift v0.29.0 - sigs.k8s.io/controller-runtime v0.16.1-0.20231215020716-1b80b9629af8 + sigs.k8s.io/controller-runtime v0.16.3 ) require ( diff --git a/go.sum b/go.sum index d4fec931..907e5935 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= -github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg= +github.com/go-logr/zapr v1.2.4 h1:QHVo+6stLbfJmYGkQ7uGHUCu5hnAFAj6mDe6Ea0SeOo= +github.com/go-logr/zapr v1.2.4/go.mod h1:FyHWQIzQORZ0QVE1BtVHv3cKtNLuXsbNLtpuhNapBOA= github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= @@ -95,8 +95,8 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs= -github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= +github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= +github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= @@ -180,8 +180,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= -golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= +golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss= +golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -233,12 +233,12 @@ k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSn k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk= kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80= -kmodules.xyz/client-go v0.29.1 h1:XC7/LybFnyKnPmjur/F+1wRk9c9QNu7yICiehnKNzf4= -kmodules.xyz/client-go v0.29.1/go.mod h1:xWlS/1zWkx1sIKCAkzULy9570mHZYi2exDECEoP1ek4= +kmodules.xyz/client-go v0.29.5 h1:iRl4MoV+96TM1csInOCWjn5xSOXzuYlil6CO40vXLHU= +kmodules.xyz/client-go v0.29.5/go.mod h1:pHuzpwzEcDUIGjVVvwz9N8lY+6A7HXwvs2d7NtK7Hho= kmodules.xyz/openshift v0.29.0 h1:8PXjeQ+usUGkLnYUMSbZrMg+i1OIYBe9UWOeBf2FRzU= kmodules.xyz/openshift v0.29.0/go.mod h1:neEinR+BcvP4vKKCkh9HpRK9e3c+upSst9E7rskZVuQ= -sigs.k8s.io/controller-runtime v0.16.1-0.20231215020716-1b80b9629af8 h1:2uFstfRgF3VNnIepR+DADX2twekWrW4oIF/DJGtq/1I= -sigs.k8s.io/controller-runtime v0.16.1-0.20231215020716-1b80b9629af8/go.mod h1:R//DPbq8lk8vvdJ931v3FxDSXkICZIssoGQ1vOSnaFg= +sigs.k8s.io/controller-runtime v0.16.3 h1:2TuvuokmfXvDUamSx1SuAOO3eTyye+47mJCigwG62c4= +sigs.k8s.io/controller-runtime v0.16.3/go.mod h1:j7bialYoSn142nv9sCOJmQgDXQXxnroFU4VnX/brVJ0= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= diff --git a/registry/admissionreview/v1/admission_review.go b/registry/admissionreview/v1/admission_review.go index 7481ce1f..7e1805b6 100644 --- a/registry/admissionreview/v1/admission_review.go +++ b/registry/admissionreview/v1/admission_review.go @@ -18,6 +18,7 @@ package v1 import ( "context" + "strings" admissionv1 "k8s.io/api/admission/v1" admissionv1beta1 "k8s.io/api/admission/v1beta1" @@ -40,6 +41,7 @@ var ( _ rest.Scoper = &REST{} _ rest.GroupVersionKindProvider = &REST{} _ rest.Storage = &REST{} + _ rest.SingularNameProvider = &REST{} ) func NewREST(hookFn AdmissionHookFunc) *REST { @@ -56,6 +58,10 @@ func (r *REST) GroupVersionKind(_ schema.GroupVersion) schema.GroupVersionKind { return admissionv1beta1.SchemeGroupVersion.WithKind("AdmissionReview") } +func (r *REST) GetSingularName() string { + return strings.ToLower("AdmissionReview") +} + func (r *REST) NamespaceScoped() bool { return false } diff --git a/registry/admissionreview/v1beta1/admission_review.go b/registry/admissionreview/v1beta1/admission_review.go index 4648708d..3e194a6e 100644 --- a/registry/admissionreview/v1beta1/admission_review.go +++ b/registry/admissionreview/v1beta1/admission_review.go @@ -18,6 +18,7 @@ package v1beta1 import ( "context" + "strings" admission "k8s.io/api/admission/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -39,6 +40,7 @@ var ( _ rest.Scoper = &REST{} _ rest.GroupVersionKindProvider = &REST{} _ rest.Storage = &REST{} + _ rest.SingularNameProvider = &REST{} ) func NewREST(hookFn AdmissionHookFunc) *REST { @@ -55,6 +57,10 @@ func (r *REST) GroupVersionKind(_ schema.GroupVersion) schema.GroupVersionKind { return admission.SchemeGroupVersion.WithKind("AdmissionReview") } +func (r *REST) GetSingularName() string { + return strings.ToLower("AdmissionReview") +} + func (r *REST) NamespaceScoped() bool { return false } diff --git a/vendor/kmodules.xyz/client-go/Makefile b/vendor/kmodules.xyz/client-go/Makefile index 7ba38d5d..aea8faa8 100644 --- a/vendor/kmodules.xyz/client-go/Makefile +++ b/vendor/kmodules.xyz/client-go/Makefile @@ -19,7 +19,7 @@ REPO := $(notdir $(shell pwd)) BIN := client-go # https://github.com/appscodelabs/gengo-builder -CODE_GENERATOR_IMAGE ?= ghcr.io/appscode/gengo:release-1.25 +CODE_GENERATOR_IMAGE ?= ghcr.io/appscode/gengo:release-1.29 # This version-strategy uses git tags to set the version string git_branch := $(shell git rev-parse --abbrev-ref HEAD) diff --git a/vendor/kmodules.xyz/client-go/meta/preconditions.go b/vendor/kmodules.xyz/client-go/meta/preconditions.go index 0f7d914b..5a5f597a 100644 --- a/vendor/kmodules.xyz/client-go/meta/preconditions.go +++ b/vendor/kmodules.xyz/client-go/meta/preconditions.go @@ -25,7 +25,7 @@ import ( ) type PreConditionSet struct { - sets.String + sets.Set[string] } func (s PreConditionSet) PreconditionFunc() []mergepatch.PreconditionFunc { @@ -36,7 +36,7 @@ func (s PreConditionSet) PreconditionFunc() []mergepatch.PreconditionFunc { mergepatch.RequireMetadataKeyUnchanged("namespace"), } - for _, field := range s.List() { + for _, field := range sets.List[string](s.Set) { preconditions = append(preconditions, RequireChainKeyUnchanged(field), ) @@ -45,7 +45,7 @@ func (s PreConditionSet) PreconditionFunc() []mergepatch.PreconditionFunc { } func (s PreConditionSet) Error() error { - strList := strings.Join(s.List(), "\n\t") + strList := strings.Join(sets.List[string](s.Set), "\n\t") return fmt.Errorf(strings.Join([]string{`At least one of the following was changed: apiVersion kind diff --git a/vendor/modules.txt b/vendor/modules.txt index 48599b2f..34c5d515 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -562,7 +562,7 @@ k8s.io/utils/strings/slices # kmodules.xyz/apiversion v0.2.0 ## explicit; go 1.14 kmodules.xyz/apiversion -# kmodules.xyz/client-go v0.29.1 +# kmodules.xyz/client-go v0.29.5 ## explicit; go 1.21.5 kmodules.xyz/client-go kmodules.xyz/client-go/api/v1 @@ -579,8 +579,8 @@ kmodules.xyz/openshift/client/clientset/versioned kmodules.xyz/openshift/client/clientset/versioned/scheme kmodules.xyz/openshift/client/clientset/versioned/typed/apps/v1 kmodules.xyz/openshift/client/clientset/versioned/typed/security/v1 -# sigs.k8s.io/controller-runtime v0.16.1-0.20231215020716-1b80b9629af8 -## explicit; go 1.21 +# sigs.k8s.io/controller-runtime v0.16.3 +## explicit; go 1.20 sigs.k8s.io/controller-runtime/pkg/client sigs.k8s.io/controller-runtime/pkg/client/apiutil sigs.k8s.io/controller-runtime/pkg/log diff --git a/vendor/sigs.k8s.io/controller-runtime/pkg/client/apiutil/apimachinery.go b/vendor/sigs.k8s.io/controller-runtime/pkg/client/apiutil/apimachinery.go index 3c0206be..6a1bfb54 100644 --- a/vendor/sigs.k8s.io/controller-runtime/pkg/client/apiutil/apimachinery.go +++ b/vendor/sigs.k8s.io/controller-runtime/pkg/client/apiutil/apimachinery.go @@ -31,9 +31,11 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer" + "k8s.io/client-go/discovery" "k8s.io/client-go/dynamic" clientgoscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + "k8s.io/client-go/restmapper" ) var ( @@ -58,6 +60,25 @@ func AddToProtobufScheme(addToScheme func(*runtime.Scheme) error) error { return addToScheme(protobufScheme) } +// NewDiscoveryRESTMapper constructs a new RESTMapper based on discovery +// information fetched by a new client with the given config. +func NewDiscoveryRESTMapper(c *rest.Config, httpClient *http.Client) (meta.RESTMapper, error) { + if httpClient == nil { + return nil, fmt.Errorf("httpClient must not be nil, consider using rest.HTTPClientFor(c) to create a client") + } + + // Get a mapper + dc, err := discovery.NewDiscoveryClientForConfigAndClient(c, httpClient) + if err != nil { + return nil, err + } + gr, err := restmapper.GetAPIGroupResources(dc) + if err != nil { + return nil, err + } + return restmapper.NewDiscoveryRESTMapper(gr), nil +} + // IsObjectNamespaced returns true if the object is namespace scoped. // For unstructured objects the gvk is found from the object itself. func IsObjectNamespaced(obj runtime.Object, scheme *runtime.Scheme, restmapper meta.RESTMapper) (bool, error) { diff --git a/vendor/sigs.k8s.io/controller-runtime/pkg/client/options.go b/vendor/sigs.k8s.io/controller-runtime/pkg/client/options.go index 798506f4..d81bf25d 100644 --- a/vendor/sigs.k8s.io/controller-runtime/pkg/client/options.go +++ b/vendor/sigs.k8s.io/controller-runtime/pkg/client/options.go @@ -419,7 +419,7 @@ type ListOptions struct { LabelSelector labels.Selector // FieldSelector filters results by a particular field. In order // to use this with cache-based implementations, restrict usage to - // exact match field-value pair that's been added to the indexers. + // a single field-value pair that's been added to the indexers. FieldSelector fields.Selector // Namespace represents the namespace to list for, or empty for @@ -514,8 +514,7 @@ type MatchingLabels map[string]string func (m MatchingLabels) ApplyToList(opts *ListOptions) { // TODO(directxman12): can we avoid reserializing this over and over? if opts.LabelSelector == nil { - opts.LabelSelector = labels.SelectorFromValidatedSet(map[string]string(m)) - return + opts.LabelSelector = labels.NewSelector() } // If there's already a selector, we need to AND the two together. noValidSel := labels.SelectorFromValidatedSet(map[string]string(m)) diff --git a/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/admission/http.go b/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/admission/http.go index 8bcbaf45..57e465ab 100644 --- a/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/admission/http.go +++ b/vendor/sigs.k8s.io/controller-runtime/pkg/webhook/admission/http.go @@ -42,23 +42,27 @@ func init() { var _ http.Handler = &Webhook{} func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) { + var body []byte + var err error ctx := r.Context() if wh.WithContextFunc != nil { ctx = wh.WithContextFunc(ctx, r) } - if r.Body == nil || r.Body == http.NoBody { - err := errors.New("request body is empty") + var reviewResponse Response + if r.Body == nil { + err = errors.New("request body is empty") wh.getLogger(nil).Error(err, "bad request") - wh.writeResponse(w, Errored(http.StatusBadRequest, err)) + reviewResponse = Errored(http.StatusBadRequest, err) + wh.writeResponse(w, reviewResponse) return } defer r.Body.Close() - body, err := io.ReadAll(r.Body) - if err != nil { + if body, err = io.ReadAll(r.Body); err != nil { wh.getLogger(nil).Error(err, "unable to read the body from the incoming request") - wh.writeResponse(w, Errored(http.StatusBadRequest, err)) + reviewResponse = Errored(http.StatusBadRequest, err) + wh.writeResponse(w, reviewResponse) return } @@ -66,7 +70,8 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) { if contentType := r.Header.Get("Content-Type"); contentType != "application/json" { err = fmt.Errorf("contentType=%s, expected application/json", contentType) wh.getLogger(nil).Error(err, "unable to process a request with unknown content type") - wh.writeResponse(w, Errored(http.StatusBadRequest, err)) + reviewResponse = Errored(http.StatusBadRequest, err) + wh.writeResponse(w, reviewResponse) return } @@ -84,12 +89,14 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) { _, actualAdmRevGVK, err := admissionCodecs.UniversalDeserializer().Decode(body, nil, &ar) if err != nil { wh.getLogger(nil).Error(err, "unable to decode the request") - wh.writeResponse(w, Errored(http.StatusBadRequest, err)) + reviewResponse = Errored(http.StatusBadRequest, err) + wh.writeResponse(w, reviewResponse) return } wh.getLogger(&req).V(5).Info("received request") - wh.writeResponseTyped(w, wh.Handle(ctx, req), actualAdmRevGVK) + reviewResponse = wh.Handle(ctx, req) + wh.writeResponseTyped(w, reviewResponse, actualAdmRevGVK) } // writeResponse writes response to w generically, i.e. without encoding GVK information.